✨ Add SWAPAbsorption Pass#1683
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
| TEST_F(SwapAbsorbPassTest, PassDoesNotChangeSwaplessProgram) { | ||
|
|
||
| qco::QCOProgramBuilder builder(context.get()); | ||
| builder.initialize(); | ||
|
|
||
| const auto q00 = builder.allocQubit(); | ||
| const auto q10 = builder.allocQubit(); | ||
| const auto q20 = builder.allocQubit(); | ||
|
|
||
| const auto q01 = builder.h(q00); | ||
| const auto [q02, q11] = builder.cx(q01, q10); | ||
|
|
||
| builder.sink(q02); | ||
| builder.sink(q11); | ||
|
|
||
| auto moduleThroughPass = builder.finalize(); | ||
| auto originalModule = moduleThroughPass->clone(); | ||
|
|
||
| applySwapAbsorb(moduleThroughPass); | ||
| ASSERT_TRUE(mlir::OperationEquivalence::isEquivalentTo( | ||
| moduleThroughPass.get(), originalModule, | ||
| mlir::OperationEquivalence::Flags::IgnoreLocations)); | ||
| } |
There was a problem hiding this comment.
Because there is also a QCO program builder, we don't require the conversion from the QC to QCO dialect here.
There was a problem hiding this comment.
I took the liberty to remove the QC builder and the conversion. Make sure to study the changes!
There was a problem hiding this comment.
copy that!
this might lead to easier comparison of original and altered circuit as well. i can compare the indices of the static qubits afterwards as they should be changed by the pass, am i correct with this assumption? currently working on that to setup more test cases ...
There was a problem hiding this comment.
I think the easiest way to check this - without having to worry about the order of the static operations1 - is to verify that the quantum operations use the correct static indices as input.
Example:
0 ---X---[H]---.---<sink>
| |
1 ---X---------⨁---<sink>
↓ (absorb SWAPs)
1 ---[H]---.---<sink> // Input of `HOp` is `qco.static 1`?
| //
0 ---------⨁---<sink> // Input of `CtrlOp(target)` is `qco.static 0`?
Footnotes
-
Note that the order (from top to bottom) of the
qco.staticoperations doesn't matter. ↩
There was a problem hiding this comment.
works just fine 👍
i have the changes in my fork at the moment, is there any possibility to append the commit to this very PR somehow or do i have to create a separate PR from my fork?
There was a problem hiding this comment.
Although suboptimal, I locally merged your changes into the branch of the main repository. Seems to work.
Maybe once you think you are done, ping me again here in this thread and I will re-merge the changes 👀
| } | ||
|
|
||
| private: | ||
| static void insertStatics(ModuleOp anchor, IRRewriter& rewriter) { |
There was a problem hiding this comment.
This function isn't required anymore. Instead of using allocations in the unit tests simply use static qubits (via qco.static).
|
|
||
| def SwapAbsorptionPass : Pass<"absorb-swaps", "mlir::ModuleOp"> { | ||
| let dependentDialects = ["mlir::qco::QCODialect"]; | ||
| let summary = ""; |
There was a problem hiding this comment.
Make sure to add a nice summary and description of the swap-absorption pass here.
…-quantum-toolkit/core into feat/swap-absorption-pass
Cpp-Linter Report
|
|
a topic for another meeting might be all the checks and pipelines in the PRs. the Lint stage fails currently even if the pre-commit fixes fixed some linting stuff. (the Check failed because of the Lint-step i guess?) locally i use clang-tidy now |
You can always see the reason for lint job failures in the CI summary: https://github.com/munich-quantum-toolkit/core/actions/runs/25418523584/attempts/1#summary-74555188566 |
Description
This pull request adds the
SWAPAbsorptionpass, which absorbs SWAPs by exchanging static qubits.Checklist
If PR contains AI-assisted content:
Assisted-by: [Model Name] via [Tool Name]footer.