Skip to content

Commit 54eec91

Browse files
Liu KeyuLiu Keyu
authored andcommitted
Fix bugs
1 parent f4874e6 commit 54eec91

File tree

6 files changed

+190
-280
lines changed

6 files changed

+190
-280
lines changed

noxfile.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ def _run_tests(
6767
"test",
6868
*install_args,
6969
"pytest",
70+
"-v",
7071
*pytest_run_args,
72+
"--disable-warnings",
7173
*session.posargs,
7274
"--cov-config=pyproject.toml",
7375
env=env,
@@ -137,5 +139,7 @@ def docs(session: nox.Session) -> None:
137139
"--frozen",
138140
"sphinx-autobuild" if serve else "sphinx-build",
139141
*shared_args,
142+
"-v",
143+
"--disable-warnings",
140144
env=env,
141145
)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ dependencies = [
4444
"numpy>=1.24; python_version >= '3.11'",
4545
"numpy>=1.22",
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
47-
"torch>=2.7.1,<2.8.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.
47+
"torch>=2.7.1,<2.8.0",
4848
"typing-extensions>=4.1", # for `assert_never`
4949
"qiskit-ibm-transpiler>=0.11.1",
5050
"qiskit-ibm-ai-local-transpiler>=0.3.2; python_version < '3.13'"

src/mqt/predictor/ml/predictor.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ def compile_training_circuits(
205205
self,
206206
path_uncompiled_circuits: Path | None = None,
207207
path_compiled_circuits: Path | None = None,
208-
timeout: int = 600,
209-
num_workers: int = -1,
208+
timeout: int = 6000,
210209
) -> None:
211210
"""Compiles all circuits in the given directory with the given timeout and saves them in the given directory.
212211
@@ -227,7 +226,7 @@ def compile_training_circuits(
227226
with zipfile.ZipFile(str(path_zip), "r") as zip_ref:
228227
zip_ref.extractall(path_uncompiled_circuits)
229228

230-
Parallel(n_jobs=num_workers, verbose=100)(
229+
Parallel(n_jobs=1, verbose=100)(
231230
delayed(self._compile_all_circuits_devicewise)(
232231
device, timeout, path_uncompiled_circuits, path_compiled_circuits, logger.level
233232
)
@@ -239,7 +238,6 @@ def generate_training_data(
239238
path_uncompiled_circuits: Path | None = None,
240239
path_compiled_circuits: Path | None = None,
241240
path_training_data: Path | None = None,
242-
num_workers: int = -1,
243241
) -> None:
244242
"""Creates and saves training data from all generated training samples.
245243
@@ -267,7 +265,7 @@ def generate_training_data(
267265
names_list = []
268266
scores_list = []
269267

270-
results = Parallel(n_jobs=num_workers, verbose=100)(
268+
results = Parallel(n_jobs=1, verbose=100)(
271269
delayed(self._generate_training_sample)(
272270
filename.name,
273271
path_uncompiled_circuits,

src/mqt/predictor/rl/actions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,7 @@ def get_openqasm_gates() -> list[str]:
495495
PassType.MAPPING,
496496
stochastic=True,
497497
transpile_pass=lambda device: [
498+
### Requires a initial layout, but "optimize" mode overwrites it
498499
TrivialLayout(coupling_map=CouplingMap(device.build_coupling_map())),
499500
FullAncillaAllocation(coupling_map=CouplingMap(device.build_coupling_map())),
500501
EnlargeWithAncilla(),

src/mqt/predictor/rl/predictorenv.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ def _apply_qiskit_action(self, action: Action, action_index: int) -> QuantumCirc
341341
def metric_fn(circ: QuantumCircuit) -> float:
342342
return float(circ.count_ops().get("swap", 0))
343343

344-
# for stochastic actions, pass the layout/routing trials parameter
345344
max_iteration = self.max_iter
346345
if "Sabre" in action.name and "AIRouting" not in action.name:
347346
# Internal trials for Sabre
@@ -359,6 +358,10 @@ def metric_fn(circ: QuantumCircuit) -> float:
359358
max_iteration=max_iteration,
360359
metric_fn=metric_fn,
361360
)
361+
else:
362+
msg = f"Unknown stochastic action: {action.name}"
363+
raise ValueError(msg)
364+
362365
else:
363366
if action.name in ["QiskitO3", "Opt2qBlocks"] and isinstance(action, DeviceDependentAction):
364367
passes = action.transpile_pass(
@@ -378,8 +381,8 @@ def metric_fn(circ: QuantumCircuit) -> float:
378381
pm = PassManager(transpile_pass)
379382
altered_qc = pm.run(self.state)
380383
pm_property_set = dict(pm.property_set) if hasattr(pm, "property_set") else {}
384+
381385
if action_index in (self.actions_mapping_indices + self.actions_final_optimization_indices):
382-
pm_property_set = dict(pm.property_set)
383386
altered_qc = self._handle_qiskit_layout_postprocessing(action, pm_property_set, altered_qc)
384387

385388
return altered_qc

0 commit comments

Comments
 (0)