Skip to content

Commit

Permalink
Set OMP vars before importing numpy when testing (#1007)
Browse files Browse the repository at this point in the history
**Context:** When testing Kokkos the OMP env vars were not having an
effect because they were set after importing numpy, and were only set
for one test file.

**Description of the Change:** Set the OMP env vars at the conftest.py
file and before importing numpy.

**Benefits:** Faster testing times

**Possible Drawbacks:** The number of threads is fixed to 2. Different
machines might support larger numbers and increase performance.
  • Loading branch information
rauletorresc authored Aug 9, 2024
1 parent 6570f2d commit 3a18a71
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 8 additions & 1 deletion frontend/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@
"""
Pytest configuration file for Catalyst test suite.
"""
# pylint: disable=unused-import

import os

# OMP env vars have to be set before importing numpy in order to have an effect
os.environ["OMP_PROC_BIND"] = "false"
os.environ["OMP_NUM_THREADS"] = "2"

# pylint: disable=unused-import,wrong-import-position
import platform

import numpy as np
Expand Down
3 changes: 0 additions & 3 deletions frontend/test/pytest/test_mid_circuit_measurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# limitations under the License.
"""Tests for mid-circuit measurements in Catalyst"""

import os
from dataclasses import asdict
from functools import reduce
from typing import Iterable, Sequence
Expand All @@ -29,8 +28,6 @@
from catalyst import CompileError, cond, measure, qjit

# TODO: add tests with other measurement processes (e.g. qml.sample, qml.probs, ...)
os.environ["OMP_PROC_BIND"] = "false"
os.environ["OMP_NUM_THREADS"] = "2"

# pylint: disable=too-many-public-methods

Expand Down

0 comments on commit 3a18a71

Please sign in to comment.