Skip to content

✨ Inject Coupling Map Into Mapping Pass#1709

Merged
burgholzer merged 13 commits into
mainfrom
enh/on-the-fly-architecture-mapping-pass
May 18, 2026
Merged

✨ Inject Coupling Map Into Mapping Pass#1709
burgholzer merged 13 commits into
mainfrom
enh/on-the-fly-architecture-mapping-pass

Conversation

@MatthiasReumann
Copy link
Copy Markdown
Collaborator

@MatthiasReumann MatthiasReumann commented May 15, 2026

Description

This pull request addresses the open issue of injecting a coupling map into the mapping pass. Contrary to #1687 a AugmentedDevice class is constructed from the coupling map instead of a QDMI device handle.

Changes

  • ✨Add a new constructor to the mapping pass.
  • ♻️ Removes the dependency of the QC dialect for the mapping pass unit-test.
  • 🔥 Remove Architecture.h and Architecture.cpp

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:

  • I have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

@MatthiasReumann MatthiasReumann added this to the MLIR Support milestone May 15, 2026
@MatthiasReumann MatthiasReumann added c++ Anything related to C++ code MLIR Anything related to MLIR labels May 15, 2026
@MatthiasReumann MatthiasReumann self-assigned this May 15, 2026
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@MatthiasReumann MatthiasReumann marked this pull request as ready for review May 15, 2026 08:56
@denialhaag denialhaag changed the title ✨Inject Coupling Map Into Mapping Pass ✨ Inject Coupling Map Into Mapping Pass May 15, 2026
Copy link
Copy Markdown
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

LGTM besides two small details.
Before merging, I'd also prompt at least one full review from CodeRabbit. Probably worth waiting until you addressed the two points.

Comment thread mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h Outdated
Comment thread mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp Outdated
@MatthiasReumann
Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

✅ Actions performed

Full review triggered.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

Release Notes

  • New Features

    • Added new graph algorithm utilities for quantum device path computation.
  • Bug Fixes

    • Updated mapping-pass API signature for improved device routing support.
  • Refactor

    • Simplified internal device architecture representation in the mapping pass.
    • Streamlined build dependencies for mapping tests.

Walkthrough

This PR refactors the mapping pass from an Architecture-based design to an AugmentedDevice model. It introduces new public graph-algorithm utilities, removes the Architecture class, updates the pass factory signature, and migrates tests to use direct QCO construction with device coupling constraints.

Changes

Mapping Pass Refactoring from Architecture to AugmentedDevice

Layer / File(s) Summary
Graph algorithms API foundations
mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h, mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
Introduces public Matrix and Edges type aliases for graph representation, and findAllShortestPaths() implementing Floyd–Warshall all-pairs shortest-path computation returning distance matrices.
Mapping pass API contract update
mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h
Changes createMappingPass signature from accepting shared_ptr<Architecture> to accepting size_t nqubits and const Edges& coupling alongside MappingPassOptions; includes new Algorithms header.
AugmentedDevice model and MappingPass construction
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
Introduces AugmentedDevice class that precomputes all-pairs shortest paths and exposes hardware connectivity (adjacency, neighbors, distances). Updates MappingPass constructors to build an internal AugmentedDevice from nqubits and coupling edges instead of accepting a shared Architecture pointer.
A search algorithm update to use device*
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
Refactors A* node goal test, heuristic function, branching factor, root/goal detection, and child expansion to use const AugmentedDevice& instead of Architecture& for all hardware index queries and distance lookups.
Routing and execution checks with device
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
Updates trial layout generation to iterate over device qubit count, switches gate executability checks from arch->areAdjacent to device.areAdjacent, and removes post-routing executability assertion.
Place function IR utilities update
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
Updates place function IR rewriting to use unqualified utility function calls (make_early_inc_range, to_vector, reverse) instead of llvm::-qualified versions while preserving IR transformation logic.
Pass factory function implementation
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
Implements updated createMappingPass to accept nqubits and coupling edges, construct an internal AugmentedDevice, and return a configured MappingPass.
Unit tests migration to device-coupling model
mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
Refactors tests from QC-to-QCO conversion with Architecture to direct QCO path using QCOProgramBuilder. Introduces DeviceSpec parameterization, isExecutable validation helper, and getNineQubitSquareGrid device generator; rewrites GHZ and Sabre tests; instantiates test suite with only NineQubitSquareGrid.
Build configuration and documentation updates
mlir/unittests/Dialect/QCO/Transforms/Mapping/CMakeLists.txt, CHANGELOG.md
Updates CMake test target to link against reduced set of libraries (removes QC-to-QCO conversion dependencies); adds CHANGELOG entry documenting the place-and-route pass changes with PR reference.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • munich-quantum-toolkit/core#1537: Introduces the heuristic mapping pass and Architecture model that this PR removes and replaces with AugmentedDevice.
  • munich-quantum-toolkit/core#1600: Modifies the mapping public API and execution-check wiring that this PR further refactors by removing the Architecture-based interface.
  • munich-quantum-toolkit/core#1574: Also modifies the A* routing implementation in Mapping.cpp; this PR switches the routing model from Architecture to AugmentedDevice.

Suggested labels

enhancement, refactor

Suggested reviewers

  • denialhaag
  • burgholzer

Poem

A quantum router's soul was replaced with care,
From Architecture's name to Device so fair.
Shortest paths now flow through algorithms new,
While A* searches dance in device's view.
🐰 ✨ Tests now speak the language QCO—hops gently

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.67% 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
Title check ✅ Passed The title clearly and concisely describes the main change: injecting a coupling map into the mapping pass. It directly relates to the primary objective of the PR.
Description check ✅ Passed The PR description covers the main objective, lists key changes, includes a completed checklist matching the template, and discloses AI usage as required. All major sections are present and substantive.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch enh/on-the-fly-architecture-mapping-pass

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 and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp (1)

381-384: 🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Consider adding a precondition check for device configuration.

If the pass is constructed via the default or options-only constructor (which may be required by MLIR pass infrastructure), device.nqubits() will be 0, causing empty trial layouts and likely silent failures or undefined behavior.

🛡️ Proposed fix to add an assertion
 void runOnOperation() override {
+  assert(device.nqubits() > 0 &&
+         "runOnOperation: device not configured; use createMappingPass()");
   assert(alpha > 0 && "runOnOperation: expected alpha > 0");
   assert(niterations > 0 && "runOnOperation: expected niterations > 0");
   assert(ntrials > 0 && "runOnOperation: expected ntrials > 0");
🤖 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/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp` around lines 381 - 384,
The runOnOperation method currently assumes device configuration is set; add a
precondition that device.nqubits() > 0 (or otherwise validate the device) before
using it to avoid empty trial layouts—e.g., in runOnOperation assert or
early-return when device.nqubits() == 0 and emit a clear diagnostic; reference
the runOnOperation function and the device.nqubits() call to locate where to add
this check.
🤖 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 `@mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp`:
- Around line 54-63: The guard currently uses op.getNumQubits() > 1 but only
validates operands 0 and 1; change the condition to require exactly two qubits
so multi-qubit (3+) unitaries don't bypass the check. Update the branch that
calls getInputQubit(0)/getInputQubit(1), TypedValue<QubitType> casts,
qubits.getIndex(...) and coupling.contains(...) to run only when
op.getNumQubits() == 2, leaving the WalkResult::interrupt() logic intact.

---

Outside diff comments:
In `@mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp`:
- Around line 381-384: The runOnOperation method currently assumes device
configuration is set; add a precondition that device.nqubits() > 0 (or otherwise
validate the device) before using it to avoid empty trial layouts—e.g., in
runOnOperation assert or early-return when device.nqubits() == 0 and emit a
clear diagnostic; reference the runOnOperation function and the device.nqubits()
call to locate where to add this check.
🪄 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: a24c177c-9233-4649-a32c-d7b471bfa185

📥 Commits

Reviewing files that changed from the base of the PR and between 9a03990 and d83b7da.

📒 Files selected for processing (9)
  • CHANGELOG.md
  • mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Architecture.h
  • mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h
  • mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Architecture.cpp
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
  • mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/CMakeLists.txt
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
💤 Files with no reviewable changes (2)
  • mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Architecture.h
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Architecture.cpp

Comment thread mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
Copy link
Copy Markdown
Member

@burgholzer burgholzer left a comment

Choose a reason for hiding this comment

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

Nice. LGTM 👍🏻

@burgholzer burgholzer merged commit e89c9f3 into main May 18, 2026
33 checks passed
@burgholzer burgholzer deleted the enh/on-the-fly-architecture-mapping-pass branch May 18, 2026 06:52
@burgholzer burgholzer added the refactor Anything related to code refactoring label May 18, 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 MLIR Anything related to MLIR refactor Anything related to code refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants