✨ Add native-gates menu derivation and progressive targetNative targeting - #1969
✨ Add native-gates menu derivation and progressive targetNative targeting#1969simon1hofmann wants to merge 16 commits into
targetNative targeting#1969Conversation
Add NativeGateset::fromOperationNames / toMenuString and Python helpers so FoMaC/QDMI devices can produce menus for fuse-two-qubit-unitary-runs.
Wire decompose → optional place/route → fuse via QCOProgram::targetBackend, Python target_backend/target_device, and mqt-cc --coupling-map.
Match main / fuse tip (b5143e7): native-gates coverage stays in the compiler API and native-synthesis suite; only keep --coupling-map driver tests.
…enu string representation
…and `test_compiler_pipeline.cpp`
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
|
@coderabbitai full review |
✅ Action performedFull review finished. |
📝 WalkthroughSummary by CodeRabbit
WalkthroughProgressive native targeting adds native-gate menu derivation, QCO targeting with optional coupling graphs, ChangesProgressive native targeting
Estimated code review effort: 4 (Complex) | ~45 minutes Possibly related PRs
Suggested labels: Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant Device
participant PythonBinding
participant QCOProgram
participant MappingPass
Device->>PythonBinding: provide operations and coupling_map
PythonBinding->>PythonBinding: derive native gate menu
PythonBinding->>QCOProgram: call targetNative(menu, coupling)
QCOProgram->>MappingPass: route over coupling edges
QCOProgram-->>PythonBinding: update targeted QCO program
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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: 3
🤖 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 `@bindings/mlir/register_mlir.cpp`:
- Around line 586-588: Document the ValueError contract in the
native_gates_from_operation_names binding docstring for nativeGatesMenuOrThrow
by adding a Raises: ValueError section. Then regenerate python/mqt/core/mlir.pyi
so its generated documentation reflects the binding change; do not edit the stub
directly.
In `@CHANGELOG.md`:
- Around line 15-17: Update the progressive native targeting entry in
CHANGELOG.md to include the required pull-request reference ([`#1969`]) while
preserving the existing feature description and `@simon1hofmann` attribution.
In `@mlir/unittests/Compiler/test_compiler_pipeline.cpp`:
- Around line 583-600: Strengthen TargetNativeAcceptsOneWayCoupling by building
the symmetrized coupling set in the same form as
TargetNativeWithCouplingLowersSwaps and asserting the resulting IR with
isExecutableStraightLine. Keep the existing swap and control-gate checks, but
use the adjacency assertion to verify the routed CX(0,2) is executable on the
symmetrized hardware topology.
🪄 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 Plus
Run ID: 2cc4b060-82b9-41fb-a820-8094a8d00e60
📒 Files selected for processing (17)
CHANGELOG.mdbindings/mlir/register_mlir.cppbindings/patterns.txtmlir/include/mlir/Compiler/Programs.hmlir/include/mlir/Dialect/QCO/Transforms/Decomposition/NativeGateset.hmlir/lib/Compiler/Programs.cppmlir/lib/Dialect/QCO/Transforms/Decomposition/NativeGateset.cppmlir/tools/mqt-cc/CMakeLists.txtmlir/tools/mqt-cc/mqt-cc.cppmlir/tools/mqt-cc/tests/check-coupling-map-requires-native-gates.cmakemlir/tools/mqt-cc/tests/check-mqt-cc-fails.cmakemlir/tools/mqt-cc/tests/coupling-line.qasmmlir/unittests/Compiler/test_compiler_pipeline.cppmlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpppython/mqt/core/mlir.pyitest/python/test_native_gates_from_device.pytest/python/test_target_native.py
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mlir/unittests/Compiler/test_compiler_pipeline.cpp (1)
87-92: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winReturn
falseinstead of relying onassertfor oversized unitaries.At Line 89,
assertis removed underNDEBUG; a 3+ qubit operation then continues and only its first two operands are checked, so invalid output can pass this helper. In assertion-enabled builds, it aborts the test process instead of reporting a failed check.Proposed guard
if (!isa<BarrierOp>(op) && unitaryOp.getNumQubits() > 1) { - assert(unitaryOp.getNumQubits() <= 2 && "expected two-qubit decomp."); + if (unitaryOp.getNumQubits() > 2) { + return false; + }🤖 Prompt for 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. In `@mlir/unittests/Compiler/test_compiler_pipeline.cpp` around lines 87 - 92, Update the unitary validation logic around UnitaryOpInterface to return false immediately when getNumQubits() exceeds two, replacing the assert-based guard. Preserve the existing BarrierOp handling and two-qubit coupling checks for valid operations.
🤖 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.
Outside diff comments:
In `@mlir/unittests/Compiler/test_compiler_pipeline.cpp`:
- Around line 87-92: Update the unitary validation logic around
UnitaryOpInterface to return false immediately when getNumQubits() exceeds two,
replacing the assert-based guard. Preserve the existing BarrierOp handling and
two-qubit coupling checks for valid operations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ada9b320-7059-40d0-aaf9-529f07b80981
📒 Files selected for processing (4)
CHANGELOG.mdbindings/mlir/register_mlir.cppmlir/unittests/Compiler/test_compiler_pipeline.cpppython/mqt/core/mlir.pyi
targetNative targeting
Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
Removed entries related to binary-safe QDMI program submission and versioned configuration from the changelog. Signed-off-by: simon1hofmann <119581649+simon1hofmann@users.noreply.github.com>
Assisted-by: Cursor Grok 4.5 via Cursor
Scalar `qubit q` programs are DCE'd by QCO cleanup with the current OpenQASM lowering; use a one-qubit register instead. Assisted-by: Cursor Grok 4.5 via Cursor
|
🤖 AI text below 🤖 This draft is superseded by #1998, which replaces the native-gate menu and progressive targeting API with the MLIR-owned The relevant work and authorship from this branch are preserved in #1998, including credit to @simon1hofmann. Closing this draft keeps the integration series focused. |
🤖 AI text below 🤖
Summary
native-gatesmenu from backend/device operation names (NativeGateset::fromOperationNames/toMenuString), including aliases (prx→r,u3→u,cnot→cx) and all entangler tokens from #1961 (rxx/ryy/rzx/rzz/iswap/cz/cx/ecr).QCOProgram::targetNative/ Pythontarget_native(and FoMaC conveniencetarget_device) runs decompose → optional place/route → fuse. Coupling is treated as undirected; the menu is validated before any IR mutation.mqt-cc --coupling-map=0-1,1-2,…(requires existing--native-gates). QDMI device load on the CLI is intentionally not added here.Related PRs
mqt-cc --qdmi-*device loading; this PR stays on explicit--native-gates+--coupling-map. Follow-up: derive menu + coupling from--qdmi-deviceafter ✨ Integrate QDMI Devices #1687 is merged.target_devicedepth.Checklist
If PR contains AI-assisted content:
🤖 *AI text below* 🤖(titles are exempt).