🐛 Support BQSKit conversion of IQM's native r gate#679
Conversation
## Description This PR addresses critical bugs in the RL training process with the following key changes: **Structure Improvements:** - **Redesigned action validation logic** (`predictorenv.py`): Rewrote `determine_valid_actions_for_state()` with a more structured (but equivalent) state machine that explicitly tracks three circuit states (synthesized, laid_out, routed) and handles 6 different state combinations. - Added helper methods `is_circuit_laid_out()` and `is_circuit_routed()` to replace the buggy `CheckMap` pass with more reliable state checking. The new logic supports both the original restricted MDP and a flexible general MDP mode. - **Fixed type annotation** (`actions.py`): Corrected `do_while` parameter type from `dict[str, Circuit]` to `PropertySet` and added missing import for Qiskit's `PropertySet`. - **Added reproducibility** (`predictor.py`): Set random seed for non-test training runs to ensure reproducible results. - **Improved VF2Layout error handling** (`predictorenv.py`): Replaced assertion failures with warning logs when VF2Layout doesn't find a solution, preventing crashes during training. **Test Updates:** - Suppressed deprecation warnings in tket routing test --------- Signed-off-by: Patrick Hopf <81010725+flowerthrower@users.noreply.github.com> Co-authored-by: flowerthrower <flowerthrower@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
r gate
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis PR adds support for IQM's native ChangesIQM r-gate support in BQSKit
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/mqt/predictor/rl/parsing.py`:
- Around line 189-206: Add a Google-style docstring to bqskit_to_qiskit
explaining purpose, Args (circuit: BqskitCircuit), Returns (QuantumCircuit) and
any Raises, and then replace the fragile qasm.replace("U1q(", "r(") with a
robust transformation: obtain the QASM via OPENQASM2Language().encode(circuit),
then perform a targeted substitution that only replaces the U1q gate tokens (not
occurrences inside comments or identifiers) before calling qasm2.loads; update
references to the r gate constructor (r_gate/r_gate_constructor) and the
qasm2.loads custom_instructions usage accordingly so the new replacement
preserves token boundaries and avoids touching comments or gate names.
In `@tests/compilation/test_helper_rl.py`:
- Around line 64-73: The test test_bqskit_to_qiskit_converts_u1q_to_r_gate uses
exact equality to compare floating params; replace the direct equality checks on
qc.data[0].operation.params with an approximate comparison (e.g., use
pytest.approx or math.isclose for each element) so floating-point precision
won't cause flaky failures; update assertions referencing
qc.data[0].operation.params accordingly to compare each parameter with an
approximate tolerance.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 3f19cc14-6cfb-43bc-b9de-c41095c7af81
📒 Files selected for processing (5)
CHANGELOG.mdsrc/mqt/predictor/rl/parsing.pysrc/mqt/predictor/rl/predictorenv.pytests/compilation/test_helper_rl.pytests/compilation/test_integration_further_SDKs.py
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
burgholzer
left a comment
There was a problem hiding this comment.
LGTM 👍🏻
Would be nice to contribute an upstream fix for the conversion to BQSKit at some point.
Description
Fixes #547, which reports
Assisted-by: GPT-5.5 via Codex
Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.