Skip to content

Commit 043be23

Browse files
Liu KeyuLiu Keyu
authored andcommitted
Remove example_test.py
1 parent 43fcabc commit 043be23

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ dependencies = [
4646
"numpy>=1.22,<2; sys_platform == 'darwin' and 'x86_64' in platform_machine and python_version < '3.13'", # Restrict numpy v2 for macOS x86 since it is not supported anymore since torch v2.3.0
4747
"torch>=2.2.2,<2.3.0; sys_platform == 'darwin' and 'x86_64' in platform_machine and python_version < '3.13'", # Restrict torch v2.3.0 for macOS x86 since it is not supported anymore.
4848
"typing-extensions>=4.1", # for `assert_never`
49+
"qiskit-ibm-transpiler>=0.2.0",
4950
]
5051

5152
classifiers = [

src/mqt/predictor/rl/helper.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
import logging
1414
from pathlib import Path
15-
from typing import TYPE_CHECKING, Optional, Callable
15+
from typing import TYPE_CHECKING, Optional, Callable, List, Tuple, Dict, Any
1616

1717
import numpy as np
1818
from qiskit import QuantumCircuit
@@ -34,7 +34,7 @@
3434

3535
logger = logging.getLogger("mqt-predictor")
3636

37-
def extract_cregs_and_measurements(qc: QuantumCircuit) -> tuple[list[ClassicalRegister], list[tuple[Instruction, list, list]]]:
37+
def extract_cregs_and_measurements(qc: QuantumCircuit) -> Tuple[List[ClassicalRegister], List[tuple[Instruction, List, List]]]:
3838
"""
3939
Extracts classical registers and measurement operations from a quantum circuit.
4040
@@ -77,9 +77,9 @@ def remove_cregs(qc: QuantumCircuit) -> QuantumCircuit:
7777

7878
def add_cregs_and_measurements(
7979
qc: QuantumCircuit,
80-
cregs: list[ClassicalRegister],
81-
measurements: list[tuple[Instruction, list, list]],
82-
qubit_map: Optional[dict] = None,
80+
cregs: List[ClassicalRegister],
81+
measurements: List[Tuple[Instruction, List, List]],
82+
qubit_map: Optional[Dict] = None,
8383
) -> QuantumCircuit:
8484
"""
8585
Adds classical registers and measurement operations back to the quantum circuit.
@@ -155,9 +155,9 @@ def best_of_n_passmanager(
155155
action: Action,
156156
device: Target,
157157
qc: QuantumCircuit,
158-
max_iteration: tuple[int, int] = (20, 20),
158+
max_iteration: Tuple[int, int] = (20, 20),
159159
metric_fn: Optional[Callable[[QuantumCircuit], float]] = None,
160-
)-> tuple[QuantumCircuit, dict[str, any]]:
160+
)-> tuple[QuantumCircuit, Dict[str, Any]]:
161161
"""
162162
Runs the given transpile_pass multiple times and keeps the best result.
163163

src/mqt/predictor/rl/predictorenv.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,18 +316,18 @@ def apply_action(self, action_index: int) -> QuantumCircuit | None:
316316
raise ValueError(msg)
317317

318318
def _apply_qiskit_action(self, action: Action, action_index: int) -> QuantumCircuit:
319-
if action.get("stochastic", False):
319+
if getattr(action, "stochastic", False):
320320
def metric_fn(circ: QuantumCircuit) -> float:
321-
return circ.count_ops().get("swap", 0)
321+
return float(circ.count_ops().get("swap", 0))
322322
# for stochastic actions, pass the layout/routing trials parameter
323323
max_iteration = self.max_iter
324-
if "Sabre" in action["name"] and "AIRouting" not in action["name"]:
324+
if "Sabre" in action.name and "AIRouting" not in action.name:
325325
# Internal trials for Sabre
326326
transpile_pass = action.transpile_pass(self.device, max_iteration)
327327
pm = PassManager(transpile_pass)
328328
altered_qc = pm.run(self.state)
329329
pm_property_set = dict(pm.property_set)
330-
elif "AIRouting" in action["name"]:
330+
elif "AIRouting" in action.name:
331331
# Run AIRouting in custom loop
332332
altered_qc, pm_property_set = best_of_n_passmanager(
333333
action,

0 commit comments

Comments
 (0)