Skip to content

Commit 927af07

Browse files
denialhaagpre-commit-ci[bot]burgholzer
authored
👷 Fix minimums nox session (#468)
## Description This PR fixes the `minimums` nox session by setting a lower bound for Qiskit. The sessions is currently failing (including in the CI on `main`) because MQT Predictor is not yet compatible with the latest Qiskit version. As a lock-file update was necessary, this PR also makes MQT Predictor compatible with the latest Qiskit version. ## Checklist: - [x] The pull request only contains commits that are focused and relevant to this change. - [x] ~I have added appropriate tests that cover the new/changed functionality.~ - [x] ~I have updated the documentation to reflect these changes.~ - [x] ~I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.~ - [x] ~I have added migration instructions to the upgrade guide (if needed).~ - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: burgholzer <burgholzer@me.com>
1 parent 7995c82 commit 927af07

File tree

5 files changed

+391
-333
lines changed

5 files changed

+391
-333
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ venv.bak/
5151

5252
.ruff_cache/
5353
.mypy_cache/
54+
55+
src/**/_version.py

noxfile.py

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@
1111
from __future__ import annotations
1212

1313
import argparse
14+
import contextlib
1415
import os
1516
import shutil
17+
import tempfile
1618
from typing import TYPE_CHECKING
1719

1820
import nox
1921

2022
if TYPE_CHECKING:
21-
from collections.abc import Sequence
23+
from collections.abc import Generator, Sequence
2224

2325

2426
nox.needs_version = ">=2024.3.2"
@@ -35,6 +37,17 @@
3537
nox.options.error_on_missing_interpreters = True
3638

3739

40+
@contextlib.contextmanager
41+
def preserve_lockfile() -> Generator[None]:
42+
"""Preserve the lockfile by moving it to a temporary directory."""
43+
with tempfile.TemporaryDirectory() as temp_dir_name:
44+
shutil.move("uv.lock", f"{temp_dir_name}/uv.lock")
45+
try:
46+
yield
47+
finally:
48+
shutil.move(f"{temp_dir_name}/uv.lock", "uv.lock")
49+
50+
3851
@nox.session(reuse_venv=True)
3952
def lint(session: nox.Session) -> None:
4053
"""Run the linter."""
@@ -82,25 +95,15 @@ def tests(session: nox.Session) -> None:
8295
@nox.session(reuse_venv=True, venv_backend="uv", python=PYTHON_ALL_VERSIONS)
8396
def minimums(session: nox.Session) -> None:
8497
"""Test the minimum versions of dependencies."""
85-
_run_tests(
86-
session,
87-
install_args=["--resolution=lowest-direct"],
88-
pytest_run_args=["-Wdefault"],
89-
)
90-
env = {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}
91-
session.run("uv", "tree", "--frozen", env=env)
92-
session.run("uv", "lock", "--refresh", env=env)
93-
94-
95-
@nox.session(reuse_venv=True, venv_backend="uv", python=PYTHON_ALL_VERSIONS)
96-
def qiskit(session: nox.Session) -> None:
97-
"""Tests against the latest version of Qiskit."""
98-
_run_tests(
99-
session,
100-
extra_command=["uv", "pip", "install", "qiskit[qasm3-import] @ git+https://github.com/Qiskit/qiskit.git"],
101-
)
102-
env = {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}
103-
session.run("uv", "pip", "show", "qiskit", env=env)
98+
with preserve_lockfile():
99+
_run_tests(
100+
session,
101+
install_args=["--resolution=lowest-direct"],
102+
pytest_run_args=["-Wdefault"],
103+
)
104+
env = {"UV_PROJECT_ENVIRONMENT": session.virtualenv.location}
105+
session.run("uv", "tree", "--frozen", env=env)
106+
session.run("uv", "lock", "--refresh", env=env)
104107

105108

106109
@nox.session(reuse_venv=True)

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ dynamic = ["version"]
3030

3131
dependencies = [
3232
"mqt.bench>=2.0.0",
33-
"qiskit!=1.3.2", # 1.3.2 causes a Qiskit error when using the CommutativeInverseCancellation pass, see https://github.com/Qiskit/qiskit/issues/13742
33+
"qiskit>=1.3.3,<2.2.0",
3434
"pytket>=1.29.0", # lowest version that supports the used pytket AutoRebase pass instead of auto_rebase
35-
"pytket_qiskit>=0.60.0",
35+
"pytket_qiskit>=0.61.0",
3636
"sb3_contrib>=2.0.0",
3737
"tqdm>=4.66.0",
3838
"rich>=12.6.0",

tests/compilation/test_reward.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@
1616
from mqt.bench import BenchmarkLevel, get_benchmark
1717
from mqt.bench.targets import get_device
1818
from qiskit import transpile
19-
20-
if TYPE_CHECKING:
21-
from qiskit import QuantumCircuit
22-
from qiskit.transpiler import Target
23-
24-
2519
from qiskit.circuit.library import CXGate, Measure, XGate
2620
from qiskit.transpiler import InstructionProperties, Target
2721

2822
from mqt.predictor.reward import crit_depth, esp_data_available, estimated_success_probability, expected_fidelity
2923

24+
try:
25+
from qiskit.providers.backend import QubitProperties
26+
27+
QISKIT_PRE_2_0 = False
28+
except ImportError:
29+
QubitProperties = object
30+
31+
QISKIT_PRE_2_0 = True
32+
33+
if TYPE_CHECKING:
34+
from qiskit import QuantumCircuit
35+
3036

3137
@pytest.fixture
3238
def device() -> Target:
@@ -92,10 +98,16 @@ def make_target(
9298
if no_qubit_props:
9399
t.qubit_properties = None
94100
else:
95-
t.qubit_properties = [
96-
type("QubitProps", (), {"t1": t1, "t2": t2}),
97-
type("QubitProps", (), {"t1": t1, "t2": t2}),
98-
]
101+
if QISKIT_PRE_2_0:
102+
t.qubit_properties = [
103+
type("QubitProp", (), {"t1": t1, "t2": t2}),
104+
type("QubitProps", (), {"t1": t1, "t2": t2}),
105+
]
106+
else:
107+
t.qubit_properties = [
108+
QubitProperties(t1=t1, t2=t2),
109+
QubitProperties(t1=t1, t2=t2),
110+
]
99111
return t
100112

101113

0 commit comments

Comments
 (0)