Skip to content

✨ Add absorb-swaps pass#1750

Open
jmoosburger wants to merge 24 commits into
munich-quantum-toolkit:mainfrom
jmoosburger:feat/swap-absorption-pass
Open

✨ Add absorb-swaps pass#1750
jmoosburger wants to merge 24 commits into
munich-quantum-toolkit:mainfrom
jmoosburger:feat/swap-absorption-pass

Conversation

@jmoosburger
Copy link
Copy Markdown

@jmoosburger jmoosburger commented May 28, 2026

Description

  • add new qco pass as warmup task (in cooperation with @MatthiasReumann)
  • remove leading swap-gates in a circuit
  • reorder static qubits instead

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jmoosburger jmoosburger changed the title Feat/swap absorption pass ✨ Feat/swap absorption pass May 28, 2026
@jmoosburger
Copy link
Copy Markdown
Author

@MatthiasReumann

works fine now 💪
nice setup with the CMakePresets by the way... :)

i have another conceptional question though: which of the following circuits is correct?

circuit 120

q0 ----X---------- q1
       |
q1 ----X----X----- q2
            |
q2 ---------X----- q0

or:

circuit 201

q0 ----X---------- q2
       |
q1 ----X----X----- q0
            |
q2 ---------X----- q1

in my opinion its the second circuit 201, but the implementation we discussed produces the first result.
i just wanted to make sure that i'm correct in my assumption before i fix it :)

@jmoosburger
Copy link
Copy Markdown
Author

jmoosburger commented May 28, 2026

the linter produces warnings on the one hand, but failes because of a http-error 403 (unauthorized) on the other hand. see here: https://github.com/munich-quantum-toolkit/core/actions/runs/26597942119/job/78373906843?pr=1750

is there anything i can do about it?

@denialhaag
Copy link
Copy Markdown
Member

the linter produces warnings on the one hand, but failes because of a http-error 403 (unauthorized) on the other hand. see here: https://github.com/munich-quantum-toolkit/core/actions/runs/26597942119/job/78373906843?pr=1750

is there anything i can do about it?

Unfortunately, the action cannot post comments on PRs coming from a fork. 😕

That said, the report can also be found in the summary of the run: https://github.com/munich-quantum-toolkit/core/actions/runs/26597942119/attempts/1#summary-78373906843

@denialhaag denialhaag changed the title ✨ Feat/swap absorption pass ✨ Add absorb-swaps pass May 29, 2026
@denialhaag denialhaag added feature New feature or request MLIR Anything related to MLIR labels May 29, 2026
@denialhaag denialhaag added this to the MLIR Support milestone May 29, 2026
@MatthiasReumann
Copy link
Copy Markdown
Collaborator

@jmoosburger

i have another conceptional question though: which of the following circuits is correct?

The best way to visualize this is to apply the SWAPs sequentially:

circuit 120

q0 ----X-- q1 ------------ q1
       |
q1 ----X-- q0 --X-- q2 --- q2
                |
q2 -------------X-- q0 --- q0

@jmoosburger
Copy link
Copy Markdown
Author

the linter produces warnings on the one hand, but failes because of a http-error 403 (unauthorized) on the other hand. see here: https://github.com/munich-quantum-toolkit/core/actions/runs/26597942119/job/78373906843?pr=1750
is there anything i can do about it?

Unfortunately, the action cannot post comments on PRs coming from a fork. 😕

That said, the report can also be found in the summary of the run: https://github.com/munich-quantum-toolkit/core/actions/runs/26597942119/attempts/1#summary-78373906843

so if i resolve all the warnings the lint check will succeed, as it does not post a comment?

@MatthiasReumann
Copy link
Copy Markdown
Collaborator

MatthiasReumann commented May 29, 2026

so if i resolve all the warnings the lint check will succeed, as it does not post a comment?

If you resolve all warnings the CI / Lint / 🚨 Lint (pull request) workflow will succeed. The pull request will look like this one.

@jmoosburger
Copy link
Copy Markdown
Author

so if i resolve all the warnings the lint check will succeed, as it does not post a comment?

If you resolve all warnings the CI / Lint / 🚨 Lint (pull request) workflow will succeed. The pull request will look like this one.

Which way is recommended?
the contribution.md suggests clang-tidy and the section Development Setup in installation.md suggests nox -s lint...

@denialhaag
Copy link
Copy Markdown
Member

Which way is recommended? the contribution.md suggests clang-tidy and the section Development Setup in installation.md suggests nox -s lint...

nox -s lint lints everything but C++ files, so you would need to run clang-tidy locally. That said, I usually just use the error messages from the CI because clang-tidy might report different errors locally. 😬

@jmoosburger
Copy link
Copy Markdown
Author

jmoosburger commented May 29, 2026

nox -s lint lints everything but C++ files, so you would need to run clang-tidy locally. That said, I usually just use the error messages from the CI because clang-tidy might report different errors locally. 😬

ahh, that explains a thing 👍
does the PR get squashed on merge then, right?

@denialhaag
Copy link
Copy Markdown
Member

ahh, that explains a thing 👍 does the PR get squashed on merge then, right?

Yeah, we often squash, but it's not a must. Either way, we generally don't stress too much about having the perfect commit history in a PR.

@jmoosburger
Copy link
Copy Markdown
Author

the linter suggests to pass a const reference in SwapAbsoption.findSwapsReadyForAbsorption():

Warning: the parameter 'wires' of type 'SmallVector' is copied for each invocation but only used as a const reference; consider making it a const reference

but this results in SegementationFaultExceptions ...
shall I rewrite the code or ignore the warning °^^

the other lint warnings are fixed 👍

@denialhaag
Copy link
Copy Markdown
Member

the linter suggests to pass a const reference in SwapAbsoption.findSwapsReadyForAbsorption():

Warning: the parameter 'wires' of type 'SmallVector' is copied for each invocation but only used as a const reference; consider making it a const reference

but this results in SegementationFaultExceptions ... shall I rewrite the code or ignore the warning °^^

I tried around a bit locally and just pushed a potential fix. I think this was actually pointing to an issue. 🤔

Let me know if this looks good to you! 🙂

@jmoosburger
Copy link
Copy Markdown
Author

I tried around a bit locally and just pushed a potential fix. I think this was actually pointing to an issue. 🤔

Let me know if this looks good to you! 🙂

fine with me 👍

do you have any other feedback, as this is pretty much what we've discussed on this feature?

@MatthiasReumann
Copy link
Copy Markdown
Collaborator

@jmoosburger If you think the pull request is ready to review, feel happy to request a review from someone (me) for on the top right of the pull request page.

@jmoosburger
Copy link
Copy Markdown
Author

@jmoosburger If you think the pull request is ready to review, feel happy to request a review from someone (me) for on the top right of the pull request page.

Unfortunately i cannot edit the reviewers-section °^^
image

But i recognized, i need to add a summary and a description for the new pass first ☝️

Signed-off-by: Johannes Moosburger <96540096+jmoosburger@users.noreply.github.com>
@jmoosburger
Copy link
Copy Markdown
Author

But i recognized, i need to add a summary and a description for the new pass first ☝️

I added a rather short description as i think it's not that complicated. feel free to share your personal opinion on that!

@burgholzer burgholzer mentioned this pull request Jun 1, 2026
1 task
Copy link
Copy Markdown
Collaborator

@MatthiasReumann MatthiasReumann left a comment

Choose a reason for hiding this comment

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

It took us a pretty long time and three pull requests but we are finally here! Congratulations on your potentially first contribution to the MLIR compiler collection 🎉

I've left some small remarks which should be fairly easy to integrate. Otherwise, great job! 🚀

Comment thread mlir/include/mlir/Dialect/QCO/Transforms/Passes.td Outdated
Comment thread mlir/unittests/Dialect/QCO/Transforms/Optimizations/test_swapabsorption.cpp Outdated
Comment thread mlir/lib/Dialect/QCO/Transforms/Optimizations/SwapAbsorption.cpp Outdated
Co-authored-by: matthias <matthias@bereumann.com>
Signed-off-by: Johannes Moosburger <96540096+jmoosburger@users.noreply.github.com>
jmoosburger and others added 2 commits June 2, 2026 11:15
Co-authored-by: matthias <matthias@bereumann.com>
Signed-off-by: Johannes Moosburger <96540096+jmoosburger@users.noreply.github.com>
Signed-off-by: Johannes Moosburger <96540096+jmoosburger@users.noreply.github.com>
@jmoosburger
Copy link
Copy Markdown
Author

It took us a pretty long time and three pull requests but we are finally here! Congratulations on your potentially first contribution to the MLIR compiler collection 🎉

I've left some small remarks which should be fairly easy to integrate. Otherwise, great job! 🚀

Thanks for your help and patience!
Hopefully there will be more in the future 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request MLIR Anything related to MLIR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants