Skip to content

✨Map scf.for operations by restoration using the 4-approximation token swap algorithm#1805

Open
MatthiasReumann wants to merge 62 commits into
mainfrom
enh/sc-map-scf-for-loops
Open

✨Map scf.for operations by restoration using the 4-approximation token swap algorithm#1805
MatthiasReumann wants to merge 62 commits into
mainfrom
enh/sc-map-scf-for-loops

Conversation

@MatthiasReumann

@MatthiasReumann MatthiasReumann commented Jun 23, 2026

Copy link
Copy Markdown
Collaborator

Changes

  • ✨Add functionality to handle operation with nested operations.
  • ✨ Implement the 4-Approximation Algorithm described in arXiv:1602.05150v3.
  • ✨Add two unit tests for quantum programs using scf.for operations and one unrolling unit test.
  • 📝 Use LLVM codebase style function description (consistent with the IRVerifier and some other parts of the cc).
  • 🚛 Move Layout class to separate file.

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 self-assigned this Jun 23, 2026
@MatthiasReumann MatthiasReumann added enhancement Improvement of existing feature c++ Anything related to C++ code MLIR Anything related to MLIR labels Jun 23, 2026
@MatthiasReumann MatthiasReumann added this to the MLIR Support milestone Jun 23, 2026
@mergify mergify Bot added the conflict label Jun 23, 2026
@MatthiasReumann MatthiasReumann marked this pull request as ready for review June 26, 2026 10:16
@MatthiasReumann

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@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: 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 `@CHANGELOG.md`:
- Around line 45-46: The changelog entry currently groups `#1805` under the
initial infrastructure bullet, but it belongs with the place-and-route work.
Update the CHANGELOG.md release note so the reference to `#1805` is moved from the
initial infrastructure list to the existing place-and-route entry, keeping the
mapping aligned with the scf.for restoration support described by that PR.

In `@mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h`:
- Around line 27-29: The createMappingPass API currently takes only the coupling
edge set, which loses explicit qubit cardinality and breaks devices with
isolated qubits. Update the pass interface in Mapping.h so createMappingPass
preserves nqubits explicitly, or accepts a separate node set alongside the
DenseSet of couplings. Then propagate that preserved cardinality through the
mapping pass implementation so capacity checks and layout generation can still
account for disconnected qubits.
🪄 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: 338ea373-9f6e-4be1-8acd-5f865529457a

📥 Commits

Reviewing files that changed from the base of the PR and between 95e7e05 and b7950da.

📒 Files selected for processing (15)
  • CHANGELOG.md
  • mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h
  • mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h
  • mlir/include/mlir/Dialect/QCO/Utils/Drivers.h
  • mlir/include/mlir/Dialect/QCO/Utils/Graph.h
  • mlir/include/mlir/Dialect/QCO/Utils/Layout.h
  • mlir/include/mlir/Dialect/QCO/Utils/Qubits.h
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
  • mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
  • mlir/lib/Dialect/QCO/Utils/Graph.cpp
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp
  • mlir/lib/Dialect/QCO/Utils/Qubits.cpp
  • mlir/lib/Dialect/QTensor/Utils/TensorIterator.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
  • mlir/unittests/Dialect/QCO/Utils/test_drivers.cpp
💤 Files with no reviewable changes (6)
  • mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
  • mlir/include/mlir/Dialect/QCO/Utils/Drivers.h
  • mlir/include/mlir/Dialect/QCO/Utils/Qubits.h
  • mlir/unittests/Dialect/QCO/Utils/test_drivers.cpp
  • mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h
  • mlir/lib/Dialect/QCO/Utils/Qubits.cpp

Comment thread CHANGELOG.md Outdated
Comment thread mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h
@MatthiasReumann

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@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: 1

🤖 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/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp`:
- Around line 743-750: The unhappy-swap path in Mapping.cpp continues iterating
over the stale F-graph after curr is mutated, so later choices in the same pass
use outdated distances. Update the logic around the loop over f.getNodes() and
f.getNeighbours(u) to perform only the first eligible unhappy SWAP, then stop
the pass and rebuild f from the updated curr before any further swap selection.
Use the existing swap selection block and swaps bookkeeping to ensure the new
F-graph is always derived from the latest state.
🪄 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: b6632d43-9dc0-4580-8fd2-bddc0b62283a

📥 Commits

Reviewing files that changed from the base of the PR and between cad617b and df5c584.

📒 Files selected for processing (15)
  • CHANGELOG.md
  • mlir/include/mlir/Dialect/QCO/Transforms/Mapping/Mapping.h
  • mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h
  • mlir/include/mlir/Dialect/QCO/Utils/Drivers.h
  • mlir/include/mlir/Dialect/QCO/Utils/Graph.h
  • mlir/include/mlir/Dialect/QCO/Utils/Layout.h
  • mlir/include/mlir/Dialect/QCO/Utils/Qubits.h
  • mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
  • mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
  • mlir/lib/Dialect/QCO/Utils/Graph.cpp
  • mlir/lib/Dialect/QCO/Utils/Layout.cpp
  • mlir/lib/Dialect/QCO/Utils/Qubits.cpp
  • mlir/lib/Dialect/QTensor/Utils/TensorIterator.cpp
  • mlir/unittests/Dialect/QCO/Transforms/Mapping/test_mapping.cpp
  • mlir/unittests/Dialect/QCO/Utils/test_drivers.cpp
💤 Files with no reviewable changes (6)
  • mlir/include/mlir/Dialect/QCO/Utils/Algorithms.h
  • mlir/lib/Dialect/QCO/Utils/Qubits.cpp
  • mlir/lib/Dialect/QCO/Utils/Algorithms.cpp
  • mlir/include/mlir/Dialect/QCO/Utils/Qubits.h
  • mlir/include/mlir/Dialect/QCO/Utils/Drivers.h
  • mlir/unittests/Dialect/QCO/Utils/test_drivers.cpp

Comment thread mlir/lib/Dialect/QCO/Transforms/Mapping/Mapping.cpp
@mergify mergify Bot added the conflict label Jun 29, 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 conflict enhancement Improvement of existing feature MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant