✨ Add Additional Canonicalization Patterns for QTensor#1728
Conversation
(cherry picked from commit 0ce2d8b1e7fac64c25b160e2f8c1cd860c26d98e)
…ub.com/munich-quantum-toolkit/core into enh/additional-tensor-canonicalization
|
If I understood this correctly, then this complements the Furthermore: Does the bubbling canonicalization provide any "real" advantage besides sorting? Both canonicalizations can handle tensor chains well already without it, right? But I am most likely missing something 😌 |
Roughly yes. However, where the Extract-Insert one removes "no-ops": %q0_0, %t0_1 = extract %t0_0, 0
%t0_1 = insert %q0_0, %t0_1, 0
// transformed to
// <empty>the Insert-Extract removes double-extracts of the same index: %q0_0, %t0_1 = extract %t0_0, 0
%q0_1 = qco.h %q0_0
%t0_1 = insert %q0_1, %t0_1, 0
%q0_2, %t0_2 = extract %t0_1, 0
%q0_3 = qco.x %q0_2
%t0_3 = insert %q0_3, %t0_2, 0
// transformed to
%q0_0, %t0_1 = extract %t0_0, 0
%q0_1 = qco.h %q0_0
%q0_2 = qco.x %q0_1
%t0_2 = insert %q0_2, %t0_1, 0
This is probably true nonetheless. I was initially thinking about putting it to the
Yes.
I would argue the following (may be irrelevant or invalid)
Lastly, the pattern has been inspired by the |
Maybe I am stupid, but this is the same right. It is also removing a "no-op", it's just not an
Something really global would potentially better fit in the
Fair points. It is probably reasonable to aim for a canonical ordering here. Moreso a general observation: At some point we may think about whether we really want to run the full canonicalization at every stage in our pipeline or whether we'd rather run more targeted sequences of patterns. |
Now that I think about it, you are right 🫠
Probably also depends on how fast the end-to-end pipeline is, right? |
Yeah, small potential inefficiencies like these are particularly noticeable now since we do not yet have sophisticated passes running by default. |
(cherry picked from commit c6985f0190f8a9450086411b03096edae6534e12)
…ub.com/munich-quantum-toolkit/core into enh/additional-tensor-canonicalization
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ub.com/munich-quantum-toolkit/core into enh/additional-tensor-canonicalization
## Description This pull request adds the bi-directional `TensorIterator` class (the analog of the `WireIterator` for tensors). Cherry-picked from #1728 to ease the reviewing effort. ## Checklist <!--- This checklist serves as a reminder of a couple of things that ensure your pull request will be merged swiftly. --> - [x] The pull request only contains commits that are focused and relevant to this change. - [x] I have added appropriate tests that cover the new/changed functionality. - [x] I have updated the documentation to reflect these changes. - [x] I have added entries to the changelog for any noteworthy additions, changes, fixes, or removals. - [x] I have added migration instructions to the upgrade guide (if needed). - [x] The changes follow the project's style guidelines and introduce no new warnings. - [x] The changes are fully tested and pass the CI checks. - [x] I have reviewed my own code changes. **If PR contains AI-assisted content:** - [x] I have disclosed the use of AI tools in the PR description as per our [AI Usage Guidelines](https://github.com/munich-quantum-toolkit/core/blob/main/docs/ai_usage.md). - [x] AI-assisted commits include an `Assisted-by: [Model Name] via [Tool Name]` footer. - [x] I confirm that I have personally reviewed and understood all AI-generated content, and accept full responsibility for it. --------- Signed-off-by: burgholzer <burgholzer@me.com> Signed-off-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: burgholzer <burgholzer@me.com> Co-authored-by: Daniel Haag <121057143+denialhaag@users.noreply.github.com>
…ub.com/munich-quantum-toolkit/core into enh/additional-tensor-canonicalization
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughThis PR adds canonicalization support for QTensor extract and insert operations by introducing rewrite patterns that remove redundant extract–insert pairs and reorder operations when semantically safe. The implementation is wired into the build system through updated CMake dependencies. ChangesQTensor Extract/Insert Canonicalization
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
burgholzer
left a comment
There was a problem hiding this comment.
This looks good to me! Just one small typo. Feel free to merge afterwards.
Co-authored-by: Lukas Burgholzer <burgholzer@me.com> Signed-off-by: matthias <matthias@bereumann.com>
Description
This pull request adds two additional canonicalization patterns to the
qtensor::InsertOpoperation.As discussed in #1718, in combination with the
QuantumLoopUnrollpass, this should us allow to map any quantum program usingscf.foroperations to superconducting architectures that do not support backwards branching.For example, base profile backends and adaptive profile backends without backwards branching support can run the following pass pipeline to map their quantum program.
Changes
TensorIteratorfor existing patterns inInsertOp.cppRemoveExtractAfterInsertPatternandBubbleDownInsertPatterncanonicalization patternsFollow-Ups
scf.foroperations natively, implement an approximative algorithm to find a SWAP sequence that restores one layout to another.Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.