Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
129b60f
Update predictor(adding callbacks)
Mar 29, 2025
08889bd
Update
Apr 10, 2025
e2ff3fe
Restore helper.py and predictor.py to match upstream
Jul 29, 2025
1c32d15
Merge remote-tracking branch 'upstream/main'
Jul 29, 2025
78dc1aa
Implement new mapping actions
Jul 29, 2025
a3ba836
Fix: resolve pre-commit issues and add missing annotations
Jul 29, 2025
5935e6f
Fix: resolve pre-commit issues and add missing annotations
Jul 29, 2025
f71fb29
Fix: resolve pre-commit issues and add missing annotations
Jul 30, 2025
3c7592b
Fix: resolve pre-commit issues and add missing annotations
Jul 30, 2025
6db5c27
Fix mypy errors
Aug 1, 2025
47841c5
Fix mypy errors
Aug 1, 2025
b1ac8ce
Fix dependencies issues
Aug 3, 2025
5f8473c
Fix dependency issues
Aug 3, 2025
7491ec0
Add missing zip file
Aug 3, 2025
3346842
Fix issue with Python 3.13
Aug 3, 2025
6f7a73c
Merge branch 'main' into hybrid-mapping
Shaobo-Zhou Aug 3, 2025
6c67349
Remove Python 3.13 from noxfile.py due to compatibility issue
Aug 3, 2025
2692b96
Skip minimums session on Windows due to CI slowness
Aug 4, 2025
f4874e6
Fix bugs
Aug 5, 2025
54eec91
Fix bugs
Aug 5, 2025
845f7de
Use default Qiskit settings for VF2Layout and add assertion for nativ…
Shaobo-Zhou Aug 7, 2025
3418936
Debug
Shaobo-Zhou Aug 7, 2025
ae870cc
Fix missing argument
Shaobo-Zhou Aug 7, 2025
861bc62
Fix warning issues
Shaobo-Zhou Aug 7, 2025
fa989b6
Fix window runtime warning problem
Shaobo-Zhou Aug 7, 2025
405bd39
Fix window runtime warning problem
Shaobo-Zhou Aug 7, 2025
7b2f321
Add time limit for VF2PostLayout
Shaobo-Zhou Aug 7, 2025
b67d0a6
Fix windows runtime warning problem
Shaobo-Zhou Aug 7, 2025
bf7c9ee
Add new actions
Shaobo-Zhou Aug 29, 2025
6d2733f
Add new actions
Shaobo-Zhou Aug 29, 2025
878185a
Add evaluation code for baseline model
Shaobo-Zhou Sep 3, 2025
eae11a2
Set up code for testing new model
Shaobo-Zhou Sep 5, 2025
68306ec
Reset
Shaobo-Zhou Sep 5, 2025
fcba8fa
Add new actions
Shaobo-Zhou Sep 6, 2025
e5b7518
Fix dependencies
Shaobo-Zhou Sep 8, 2025
907ce2b
Fix dependencies
Shaobo-Zhou Sep 8, 2025
70dcd7d
Fix dependencies
Shaobo-Zhou Sep 8, 2025
e0364b1
Merge branch 'main' into new_structure
Shaobo-Zhou Sep 8, 2025
eb27098
🎨 pre-commit fixes
pre-commit-ci[bot] Sep 8, 2025
2688c0e
Fix dependencies
Shaobo-Zhou Sep 8, 2025
840d23d
Fix multiprocessing on Python 3.13
Shaobo-Zhou Sep 9, 2025
ac406ac
Fix timeout watcher
Shaobo-Zhou Sep 9, 2025
97c81bb
Update comments and restructure
Shaobo-Zhou Sep 15, 2025
470365d
Adjust test circuits from ALG to INDEP
Shaobo-Zhou Sep 15, 2025
caaf224
Update max synthesis size for bqskit
Shaobo-Zhou Sep 15, 2025
468da2e
Add tests for more coverage
Shaobo-Zhou Sep 17, 2025
737a9f2
Update tests
Shaobo-Zhou Sep 18, 2025
94c25ab
Update override
Shaobo-Zhou Sep 18, 2025
3ff922e
Update comments
Shaobo-Zhou Sep 18, 2025
782caf8
Update noxfile.py and CHANGELOG.md
Shaobo-Zhou Sep 22, 2025
44e0e40
Clean up venv after each session to free up space
Shaobo-Zhou Sep 23, 2025
350bae5
Clean up venv after each session to free up space
Shaobo-Zhou Sep 23, 2025
91208d1
Clean up venv after each session to free up space
Shaobo-Zhou Sep 23, 2025
622d409
Clean up venv after each session to free up space
Shaobo-Zhou Sep 23, 2025
fa008a6
Update noxfile
Shaobo-Zhou Sep 25, 2025
0c98e56
Update ibm runtime dependency
Shaobo-Zhou Sep 25, 2025
34a1c7c
Update noxfile
Shaobo-Zhou Sep 25, 2025
a8d069a
Update noxfile
Shaobo-Zhou Sep 25, 2025
114b79b
Update noxfile
Shaobo-Zhou Sep 25, 2025
aaf14b1
Fetch update from main
Shaobo-Zhou Sep 26, 2025
e39cd7e
Merge remote-tracking branch 'upstream/main' into new_structure
Shaobo-Zhou Nov 20, 2025
e7b4174
Fix ruff checks
Shaobo-Zhou Nov 20, 2025
fcab4fa
Update action space and add normalized gate counts as RL features
Shaobo-Zhou Nov 20, 2025
cb4d0fb
Fix FOM comparison logic
Shaobo-Zhou Nov 20, 2025
988a8f7
Remove 3-qubit gates from dict
Shaobo-Zhou Nov 21, 2025
9a40b3e
Add reward shaping
Shaobo-Zhou Nov 26, 2025
cee79cd
Add fallback for unsupported reward function
Shaobo-Zhou Nov 27, 2025
756d777
Minor Fixes
Shaobo-Zhou Nov 27, 2025
d60d17e
Minor Fixes
Shaobo-Zhou Nov 27, 2025
a05e37a
Merge branch 'main' into new_RL
Shaobo-Zhou Nov 27, 2025
85d4d57
Minor Fixes
Shaobo-Zhou Nov 27, 2025
a1370de
Fix predictorenv.py
Shaobo-Zhou Nov 27, 2025
e456f43
Update changelog and improve test coverage
Shaobo-Zhou Dec 3, 2025
de7c498
Update cost model
Shaobo-Zhou Dec 3, 2025
9a68c59
Merge branch 'main' into new_RL
Shaobo-Zhou Dec 3, 2025
d0a07a2
Update cost model
Shaobo-Zhou Dec 3, 2025
18cf31f
Fix CI issue
Shaobo-Zhou Dec 3, 2025
0c42b41
Improve coverage
Shaobo-Zhou Dec 3, 2025
a451710
Update src/mqt/predictor/reward.py
Shaobo-Zhou Dec 3, 2025
ac7dc28
Update src/mqt/predictor/rl/cost_model.py
Shaobo-Zhou Dec 3, 2025
67dc402
Update tests/hellinger_distance/test_estimated_hellinger_distance.py
Shaobo-Zhou Dec 3, 2025
8259b4d
Code improvements suggested by CodeRabbit
Shaobo-Zhou Dec 3, 2025
4b5bf6f
Fix warnings
Shaobo-Zhou Dec 3, 2025
14aa3ac
Improve coverage
Shaobo-Zhou Dec 4, 2025
04fde70
Improve coverage
Shaobo-Zhou Dec 4, 2025
1df8071
Update src/mqt/predictor/rl/predictorenv.py
Shaobo-Zhou Dec 4, 2025
6a104b8
Fixes
Shaobo-Zhou Dec 4, 2025
ae43600
Merge branch 'main' into new_RL
Shaobo-Zhou Dec 17, 2025
b91f4f4
Fixes
Shaobo-Zhou Dec 17, 2025
b2197b3
Fix format
Shaobo-Zhou Dec 17, 2025
331972a
Fixes
Shaobo-Zhou Dec 17, 2025
b8a80d2
Fixes
Shaobo-Zhou Dec 17, 2025
7810d4d
Update comments
Shaobo-Zhou Dec 18, 2025
8b3ecaf
Merge branch 'main' into new_RL
burgholzer Dec 25, 2025
bc49c63
✏️ curate changelog
burgholzer Dec 25, 2025
5cd1bf7
✏️ minimize unnecessary whitespace changes
burgholzer Dec 25, 2025
5a895d0
⏪ revert Windows workaround
burgholzer Dec 25, 2025
1ecb3e2
🏷️ Various typing fixes
burgholzer Dec 25, 2025
dde6f89
⏪ avoid CUDA out of memory error
burgholzer Dec 25, 2025
2e3d1c7
Update cost_model.py to QCEC style
Shaobo-Zhou Feb 4, 2026
c8b7201
Merge branch 'main' into new_RL
Shaobo-Zhou Feb 4, 2026
da3c95f
🎨 pre-commit fixes
pre-commit-ci[bot] Feb 4, 2026
56573a9
Adjusted implementation of reward approximation
Shaobo-Zhou Feb 8, 2026
e0cec3c
Coderabbit suggestions
Shaobo-Zhou Feb 8, 2026
a41b323
Resolve problem with estimated Hellinger distance
Shaobo-Zhou Feb 8, 2026
37c55a8
Merge branch 'main' into new_RL
Shaobo-Zhou Feb 8, 2026
734df4e
Add test coverage
Shaobo-Zhou Feb 8, 2026
d376268
Apply coderabbit suggestions
Shaobo-Zhou Feb 8, 2026
adaefa9
Apply coderabbit suggestions
Shaobo-Zhou Feb 8, 2026
7a0c40b
Apply coderabbit suggestions
Shaobo-Zhou Feb 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ repos:
- id: ty-check
name: ty check
entry: uv run ty check
language: unsupported
language: system
require_serial: true
types_or: [python, pyi, jupyter]
exclude: ^(docs/)
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@ This project adheres to [Semantic Versioning], with the exception that minor rel

### Changed

- ✨ Improve RL reward design by adding intermediate rewards ([#526]) ([**@Shaobo-Zhou**])
- 🔧 Replace `mypy` with `ty` ([#572]) ([**@denialhaag**])
- 🐛 Fix instruction duration unit in estimated success probability calculation ([#445]) ([**@Shaobo-Zhou**])

### Removed

- ✨ Remove support for custom names of trained models ([#489]) ([**@bachase**])
- 🔥 Drop support for x86 macOS systems ([#421]) ([**@denialhaag**])

Expand Down Expand Up @@ -47,6 +51,7 @@ _📚 Refer to the [GitHub Release Notes](https://github.com/munich-quantum-tool
<!-- PR links -->

[#572]: https://github.com/munich-quantum-toolkit/predictor/pull/572
[#526]: https://github.com/munich-quantum-toolkit/predictor/pull/526
[#489]: https://github.com/munich-quantum-toolkit/predictor/pull/489
[#445]: https://github.com/munich-quantum-toolkit/predictor/pull/445
[#421]: https://github.com/munich-quantum-toolkit/predictor/pull/421
Expand Down
1 change: 0 additions & 1 deletion src/mqt/predictor/ml/predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ def train_random_forest_model(
training_data = self._get_prepared_training_data()
num_cv = min(len(training_data.y_train), 5)
mdl = GridSearchCV(mdl, tree_param, cv=num_cv, n_jobs=8).fit(training_data.X_train, training_data.y_train)

joblib_dump(mdl, save_mdl_path)
logger.info("Random Forest model is trained and saved.")

Expand Down
2 changes: 1 addition & 1 deletion src/mqt/predictor/reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def estimated_success_probability(qc: QuantumCircuit, device: Target, precision:
if first_qubit_idx not in active_qubits:
continue

dt = device.dt # instruction durations are stored in unit dt
dt = device.dt or 1.0 # discrete time unit; fallback to 1.0 if unavailable
res *= np.exp(
-instruction.duration
* dt
Expand Down
3 changes: 2 additions & 1 deletion src/mqt/predictor/rl/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

from bqskit import Circuit
from pytket._tket.passes import BasePass as tket_BasePass
from qiskit.passmanager import PropertySet
from qiskit.transpiler.basepasses import BasePass as qiskit_BasePass


Expand Down Expand Up @@ -143,7 +144,7 @@ class DeviceDependentAction(Action):
Callable[..., tuple[Any, ...] | Circuit],
]
)
do_while: Callable[[dict[str, Circuit]], bool] | None = None
do_while: Callable[[PropertySet], bool] | None = None


# Registry of actions
Expand Down
116 changes: 116 additions & 0 deletions src/mqt/predictor/rl/approx_reward.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Copyright (c) 2023 - 2026 Chair for Design Automation, TUM
# Copyright (c) 2025 - 2026 Munich Quantum Software Company GmbH
# All rights reserved.
#
# SPDX-License-Identifier: MIT
#
# Licensed under the MIT License

"""This module provides helper functions to approximate expected fidelity and estimated success probability (ESP) by transpiling a circuit to a device's basis gate set and combining resulting gate counts with calibration-derived per-gate error rates and durations."""

from __future__ import annotations

from typing import TYPE_CHECKING

import numpy as np
from qiskit import transpile

if TYPE_CHECKING:
from qiskit import QuantumCircuit
from qiskit.transpiler import Target

BLACKLIST: set[str] = {"measure", "reset", "delay", "barrier"} # These gates do not directly contribute to the error


def get_basis_gates_from_target(device: Target) -> list[str]:
"""Return the basis gate names from a Qiskit Target."""
return sorted([g for g in device.operation_names if g not in BLACKLIST])


def estimate_basis_gate_counts(qc: QuantumCircuit, *, basis_gates: list[str]) -> dict[str, int]:
"""Transpile ``qc`` to ``basis_gates`` and count occurrences of each basis gate."""
qc_t = transpile(qc, basis_gates=basis_gates, optimization_level=1, seed_transpiler=42)
counts = dict.fromkeys(basis_gates, 0)
for ci in qc_t.data:
name = ci.operation.name
if name in BLACKLIST:
continue
if name in counts:
counts[name] += 1
return counts


def approx_expected_fidelity(
qc: QuantumCircuit,
*,
device: Target,
error_rates: dict[str, float],
) -> float:
"""Approximate expected fidelity using per-basis-gate error rates.

The circuit is first transpiled to the device basis. Then a simple product
model is applied: Π_g (1 - p_g)^{count_g}.

Args:
qc: Circuit to evaluate.
device: Target providing the basis gate set.
error_rates: Mapping ``basis_gate -> error_probability``.

Returns:
Approximate fidelity in [0, 1].
"""
basis = get_basis_gates_from_target(device)
counts = estimate_basis_gate_counts(qc, basis_gates=basis)
f = 1.0
for g, c in counts.items():
f *= (1.0 - error_rates.get(g, 0.0)) ** c
return float(max(min(f, 1.0), 0.0))


def approx_estimated_success_probability(
qc: QuantumCircuit,
*,
device: Target,
error_rates: dict[str, float],
gate_durations: dict[str, float],
tbar: float | None,
par_feature: float,
liv_feature: float,
n_qubits: int,
) -> float:
"""Approximate ESP using per-basis-gate error rates, durations, and coherence.

This combines:
(1) a gate-infidelity product term, and
(2) an idle/decoherence penalty based on an effective circuit duration.

Args:
qc: Circuit to evaluate.
device: Target providing the basis gate set.
error_rates: Mapping ``basis_gate -> error_probability``.
gate_durations: Mapping ``basis_gate -> duration`` (seconds).
tbar: Representative coherence time (seconds). If None, idle penalty is skipped.
par_feature: Parallelism feature in [0, 1].
liv_feature: Liveness feature in [0, 1].
n_qubits: Number of qubits in the circuit.

Returns:
Approximate ESP in [0, 1].
"""
basis = get_basis_gates_from_target(device)
counts = estimate_basis_gate_counts(qc, basis_gates=basis)

f_gate = 1.0
for g, c in counts.items():
f_gate *= (1.0 - error_rates.get(g, 0.0)) ** c

n_q = max(n_qubits, 1)
k_eff = 1.0 + (n_q - 1.0) * float(par_feature)

total_gate_time = sum(counts[g] * gate_durations.get(g, 0.0) for g in basis) / k_eff

idle_fraction = max(0.0, 1.0 - float(liv_feature))
idle_factor = 1.0 if tbar is None or tbar <= 0.0 else float(np.exp(-(total_gate_time * idle_fraction) / tbar))

esp = f_gate * idle_factor
return float(max(min(esp, 1.0), 0.0))
Loading
Loading