Skip to content

Commit 1d835bd

Browse files
Shaobo-ZhouShaobo ZhouLiu Keyuburgholzer
authored
🐛 Use basis_gates instead of target for checking native gates (#428)
<!--- This file has been generated from an external template. Please do not modify it directly. --> <!--- Changes should be contributed to https://github.com/munich-quantum-toolkit/templates. --> ## Description Fix a bug in `rl/predictorenv.py`: Use `basis_gates` instead of `target` as argument while checking native gates ## Checklist: <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [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: Shaobo Zhou <ge75qiv@mytum.de> Co-authored-by: Liu Keyu <keyul@DESKTOP-VF13J3A.localdomain> Co-authored-by: Lukas Burgholzer <burgholzer@me.com>
1 parent 04b697d commit 1d835bd

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/mqt/predictor/rl/predictorenv.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ def _apply_bqskit_action(self, action: Action, action_index: int) -> QuantumCirc
424424

425425
def determine_valid_actions_for_state(self) -> list[int]:
426426
"""Determines and returns the valid actions for the current state."""
427-
check_nat_gates = GatesInBasis(target=self.device)
427+
check_nat_gates = GatesInBasis(basis_gates=self.device.operation_names)
428428
check_nat_gates(self.state)
429429
only_nat_gates = check_nat_gates.property_set["all_gates_in_basis"]
430430

tests/compilation/test_predictor_rl.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from qiskit.circuit.library import CXGate
2020
from qiskit.qasm2 import dump
2121
from qiskit.transpiler import InstructionProperties, Target
22+
from qiskit.transpiler.passes import GatesInBasis
2223

2324
from mqt.predictor.rl import Predictor, rl_compile
2425
from mqt.predictor.rl.actions import (
@@ -89,8 +90,14 @@ def test_qcompile_with_newly_trained_models() -> None:
8990
)
9091

9192
qc_compiled, compilation_information = rl_compile(qc, device=device, figure_of_merit=figure_of_merit)
93+
94+
check_nat_gates = GatesInBasis(basis_gates=device.operation_names)
95+
check_nat_gates(qc_compiled)
96+
only_nat_gates = check_nat_gates.property_set["all_gates_in_basis"]
97+
9298
assert qc_compiled.layout is not None
9399
assert compilation_information is not None
100+
assert only_nat_gates, "Circuit should only contain native gates but was not detected as such"
94101

95102

96103
def test_qcompile_with_false_input() -> None:

0 commit comments

Comments
 (0)