Skip to content

✨ Add native-gates menu derivation and progressive targetNative targeting - #1969

Closed
simon1hofmann wants to merge 16 commits into
mainfrom
feat/target-native
Closed

✨ Add native-gates menu derivation and progressive targetNative targeting#1969
simon1hofmann wants to merge 16 commits into
mainfrom
feat/target-native

Conversation

@simon1hofmann

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Summary

  • Derive a supported native-gates menu from backend/device operation names (NativeGateset::fromOperationNames / toMenuString), including aliases (prxr, u3u, cnotcx) and all entangler tokens from #1961 (rxx/ryy/rzx/rzz/iswap/cz/cx/ecr).
  • Add progressive native targeting: QCOProgram::targetNative / Python target_native (and FoMaC convenience target_device) runs decompose → optional place/route → fuse. Coupling is treated as undirected; the menu is validated before any IR mutation.
  • Wire 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

  • #1687 — owns mqt-cc --qdmi-* device loading; this PR stays on explicit --native-gates + --coupling-map. Follow-up: derive menu + coupling from --qdmi-device after ✨ Integrate QDMI Devices #1687 is merged.
  • #1901 — QDMI device-management redesign; not a prerequisite for this PR, but may affect later FoMaC/target_device depth.
  • #1967 — typed QDMI config transport; independent of menus/coupling for now.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • I have added appropriate tests that cover the new/changed functionality.
  • I have updated the documentation to reflect these changes.
  • I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • I have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • I have reviewed my own code changes.

If PR contains AI-assisted content:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our AI Usage Guidelines.
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • I have disclosed AI assistance in the PR description.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

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.
@simon1hofmann simon1hofmann changed the title Feat/target native ✨ Add native-gates menu derivation and progressive targetNative targeting Jul 30, 2026
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.53073% with 8 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
mlir/tools/mqt-cc/mqt-cc.cpp 90.6% 4 Missing ⚠️
...ect/QCO/Transforms/Decomposition/NativeGateset.cpp 97.3% 3 Missing ⚠️
mlir/lib/Compiler/Programs.cpp 95.4% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@simon1hofmann

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added progressive native-gate targeting with optional coupling-map constrained routing.
    • Added device-based targeting plus helper functions to derive the supported native-gate menu from operation names or device capabilities.
    • Added --coupling-map support to the compiler tool (with coupling-edge parsing).
  • Bug Fixes
    • Improved validation and diagnostics for missing/empty native-gate menus and invalid menu/coupling configurations.
  • Tests
    • Added coverage for native-gate derivation, target behavior, coupling handling (including one-way inputs), and expected success/failure cases.

Walkthrough

Progressive native targeting adds native-gate menu derivation, QCO targeting with optional coupling graphs, mqt-cc --coupling-map routing, Python bindings, type stubs, tests, and changelog documentation.

Changes

Progressive native targeting

Layer / File(s) Summary
Native gateset derivation
mlir/include/mlir/Dialect/QCO/Transforms/Decomposition/NativeGateset.h, mlir/lib/Dialect/QCO/Transforms/Decomposition/NativeGateset.cpp, mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp
Native gate aliases are normalized, supported Euler bases and entanglers are resolved, and deterministic menu strings are generated and tested.
QCO native targeting
mlir/include/mlir/Compiler/Programs.h, mlir/lib/Compiler/Programs.cpp, mlir/unittests/Compiler/test_compiler_pipeline.cpp
QCOProgram::targetNative validates menus, decomposes multi-controlled gates, optionally routes over symmetric coupling edges, fuses operations, and is covered by compiler pipeline tests.
mqt-cc coupling-map pipeline
mlir/tools/mqt-cc/*
The CLI parses and validates --coupling-map, enforces related option constraints, adds mapping to the QCO pipeline, and adds success and failure tests.
Python targeting bindings and validation
bindings/mlir/register_mlir.cpp, bindings/patterns.txt, python/mqt/core/mlir.pyi, test/python/*native*
Python exposes native-menu derivation, target_native, and target_device; tests cover device metadata, coupling behavior, invalid menus, and error handling.
Release note
CHANGELOG.md
The unreleased changelog records progressive native targeting and the related APIs and CLI option.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested labels: feature, c++, MLIR, python

Suggested reviewers: denialhaag, burgholzer

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
Loading

Poem

I’m a rabbit hopping through gates,
With coupling maps that open new paths.
Native menus sparkle bright,
QCO routes qubits just right—
And tests leave tidy tracks! 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 47.06% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly describes the main change: native-gates menu derivation and progressive targetNative targeting.
Description check ✅ Passed The description covers the change summary, related context, dependencies, checklist, and AI disclosure required by the template.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/target-native

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between fe36393 and 729ef97.

📒 Files selected for processing (17)
  • CHANGELOG.md
  • bindings/mlir/register_mlir.cpp
  • bindings/patterns.txt
  • mlir/include/mlir/Compiler/Programs.h
  • mlir/include/mlir/Dialect/QCO/Transforms/Decomposition/NativeGateset.h
  • mlir/lib/Compiler/Programs.cpp
  • mlir/lib/Dialect/QCO/Transforms/Decomposition/NativeGateset.cpp
  • mlir/tools/mqt-cc/CMakeLists.txt
  • mlir/tools/mqt-cc/mqt-cc.cpp
  • mlir/tools/mqt-cc/tests/check-coupling-map-requires-native-gates.cmake
  • mlir/tools/mqt-cc/tests/check-mqt-cc-fails.cmake
  • mlir/tools/mqt-cc/tests/coupling-line.qasm
  • mlir/unittests/Compiler/test_compiler_pipeline.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Decomposition/test_weyl_decomposition.cpp
  • python/mqt/core/mlir.pyi
  • test/python/test_native_gates_from_device.py
  • test/python/test_target_native.py

Comment thread bindings/mlir/register_mlir.cpp Outdated
Comment thread CHANGELOG.md
Comment thread mlir/unittests/Compiler/test_compiler_pipeline.cpp
@simon1hofmann

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 win

Return false instead of relying on assert for oversized unitaries.

At Line 89, assert is removed under NDEBUG; 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

📥 Commits

Reviewing files that changed from the base of the PR and between 729ef97 and a0d8959.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • bindings/mlir/register_mlir.cpp
  • mlir/unittests/Compiler/test_compiler_pipeline.cpp
  • python/mqt/core/mlir.pyi

@simon1hofmann simon1hofmann changed the title ✨ Add native-gates menu derivation and progressive targetNative targeting ✨ Add native-gates menu derivation and progressive targetNative targeting Jul 30, 2026
@mergify mergify Bot added the conflict label Jul 30, 2026
@simon1hofmann simon1hofmann self-assigned this Jul 30, 2026
@simon1hofmann simon1hofmann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Jul 30, 2026
@simon1hofmann simon1hofmann added this to the MLIR Support milestone Jul 30, 2026
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>
@mergify mergify Bot added conflict and removed conflict labels Jul 30, 2026
simon1hofmann and others added 3 commits August 3, 2026 09:14
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
@burgholzer

Copy link
Copy Markdown
Member

🤖 AI text below 🤖

This draft is superseded by #1998, which replaces the native-gate menu and progressive targeting API with the MLIR-owned CompilerTarget, target-independent optimization, post-routing native synthesis, and final target-conformance verification.

The relevant work and authorship from this branch are preserved in #1998, including credit to @simon1hofmann. Closing this draft keeps the integration series focused.

@burgholzer burgholzer closed this Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Anything related to C++ code enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants