Skip to content

Decomp/qref decomposable interface - #3161

Merged
paul0403 merged 15 commits into
mainfrom
decomp/qref-decomposable-interface
Sep 16, 2026
Merged

paul0403 merged 15 commits into
mainfrom
decomp/qref-decomposable-interface

Conversation

@yde773786

Copy link
Copy Markdown
Contributor

Context:

The DecomposableGate Interface was introduced to provide a generic interface for decomposition of quantum gates. We want to migrate the graph-decomposition and decompose-lowering passes to reference semantics, but this will require the DecomposableGate interface be implemented for reference semantics gates

Description of the Change:

The DecomposableGate Interface is added for the Qref dialect, and the decomposable gates inherit this interface appropriately. The format used is identical to how the interface is defined and used in the Quantum dialect.

gtest for this interface addition added.

Using MLIR types in the GOID as defined here is used.
A corresponding test that should fail with the previous (python style types in GOID) is also added to the Qref dialect's DecomposableGate Interface gtests.

Benefits:

Unblocks implementation of graph-decomposition and decompose-lowering passes in reference semantics.

Possible Drawbacks:

Code duplication exists with the Quantum dialect's implementation of DecomposableGate. Modifications need to be applied in both places.

Related GitHub Issues:

[sc-128397]

@yde773786
yde773786 requested review from a team and kipawaa August 28, 2026 14:47
@yde773786
yde773786 marked this pull request as ready for review August 28, 2026 14:47
@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.65%. Comparing base (9d2bd1d) to head (bffe31d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3161   +/-   ##
=======================================
  Coverage   95.65%   95.65%           
=======================================
  Files         177      177           
  Lines       21011    21011           
  Branches     2117     2117           
=======================================
  Hits        20098    20098           
  Misses        725      725           
  Partials      188      188           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dime10

dime10 commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

We want to migrate the graph-decomposition and decompose-lowering passes to reference semantics

@kipawaa Could you provide more info on this?

@paul0403

paul0403 commented Aug 28, 2026

Copy link
Copy Markdown
Member

We want to migrate the graph-decomposition and decompose-lowering passes to reference semantics

@kipawaa Could you provide more info on this?

There's at least two points in the current graph decomp pass that's very inefficient.

  1. It is performing the infamous "value semantics walk back" to determine what qubits have what extract indices when inlining the rules back into the actual program's gates.
  2. The rules are littered with stablehlo ops everywhere. It is because in the rules' arguments, we are manually taking in extract indices packed in a tensor argument, and then in the rules' bodies stablehlo.extract these qubit extract indices and quantum.extract. Linking the whole file: a bit hard to isolate a single line to link to

Issue 1 I'm very confident is non existent if the pass were in reference semantics. So at least there's that. We have too many separate implementations of the walkback, and each of these must be maintained separately (e.g. bug found in #3156 ). Any pass that is walking back should just be in reference semantics since the "walkback" in the semantics conversion pass is the most tested!

Issue 2 might be more tricky. The rules are generated from the frontend as quantum subroutines, which takes in wires as (a tensor of) integers (aka "extract indices). I would really love it if the frontend can generate rules that act on qref.bit directly instead of extract indices. That is its own problem; but in a world where we have support for that in the frontend, the decompose lowering pass would need to be in reference semantics to enjoy the benefit. The inlining of the rules back into the user circuit would not need to worry about any qubit dataflow: just grab the qref.bit SSA value on the user program's gate, replace some uses and we're done! This might also be possible in value semantics but it will be more involved.

@kipawaa

kipawaa commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

We want to migrate the graph-decomposition and decompose-lowering passes to reference semantics

@kipawaa Could you provide more info on this?

@paul0403 Made the major points above, but to add to this is that the on-demand rules (and truly all rules) are initially lowered in reference semantics and then have to be converted to value semantics for compatibility with the passes. I think it would be nice to migrate the entire graph-decomps system to reference semantics for all of these reasons. We could then place the rules in their own module separate from the user circuit, and this way they can be isolated from the user program and remain in reference semantics throughout their lifetime.

@kipawaa

kipawaa commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Nice work @yde773786! Sorry to spring this on you right after you finished the work, but could you update to accommodate controls that were introduced in #3127?

@yde773786

Copy link
Copy Markdown
Contributor Author

@kipawaa

Added the tests. I found no need to make any changes, so ported identical functionality/tests from quantum to qref for the above.

Did want to bring attention to this test again, though (since it's a test that is not present in the quantum dialect). It's for testing the N types to 1 GOID bug that 3158 fixes and could be added to the Quantum dialect as well.

@yde773786
yde773786 force-pushed the decomp/qref-decomposable-interface branch 2 times, most recently from 8af2e84 to ebf9f03 Compare August 31, 2026 15:52

@kipawaa kipawaa 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.

Great work, thanks @yde773786!

Comment thread mlir/unittests/QRef/TestDecomposableGateInterface.cpp
Comment thread mlir/unittests/QRef/TestDecomposableGateInterface.cpp Outdated
@yde773786
yde773786 force-pushed the decomp/qref-decomposable-interface branch from ebf9f03 to 3fd9dd7 Compare September 9, 2026 18:40
Comment thread mlir/lib/QRef/IR/QRefInterfaces.cpp Outdated
}

template <typename T, typename PrintFunc>
void printSortedMap(const llvm::StringMap<T> &map, llvm::raw_string_ostream &ss,

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.

wrapModifiers, printSortedMap, printDynamicShape and printWireLens are all copies that are not specific to the either dialect, and should be factored out

@yde773786 yde773786 Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this applies here as well.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since it's tracked, let's tackle it in a follow up PR.

@dime10 dime10 Sep 16, 2026

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.

I don't think an interface is necessary here, this is just about factoring out duplicate helper functions. But please do tackle this in a follow up!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the idea is to put the interface itself in the Catalyst dialect, which means all these helpers would exist just once in Catalyst dialect too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Although I don't necessarily agree with putting quantum things in Catalyst, I can't really think of a better place 😅

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.

Yeah Catalyst doesn't sound like the right place for a quantum related interface, it should just go into quantum. Regarding the helpers, if they are moved to the interface that's fine too, I'm just saying all that was necessary here was moving them to a header from which they can be imported into both dialects.

Comment thread doc/releases/changelog-dev.md Outdated
Comment thread mlir/lib/QRef/IR/QRefInterfaces.cpp
Comment thread mlir/lib/QRef/IR/QRefInterfaces.cpp
Comment thread mlir/unittests/QRef/TestDecomposableGateInterface.cpp
Comment thread mlir/unittests/QRef/TestDecomposableGateInterface.cpp
@paul0403

Copy link
Copy Markdown
Member

I am branching off this PR to migrate --decompose-lowering to reference semantics.

Comment thread doc/releases/changelog-dev.md Outdated

@maliasadi maliasadi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! Thanks @yde773786

yde773786 and others added 8 commits September 16, 2026 10:35
Changelog generalized to include all PRs that implement DecomposableGateInterface across dialects

Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
…ate required in all corresponding DecompGate Interfaces
Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
@yde773786
yde773786 force-pushed the decomp/qref-decomposable-interface branch from ecf06c6 to bffe31d Compare September 16, 2026 14:38
@paul0403
paul0403 merged commit 3f3e648 into main Sep 16, 2026
38 checks passed
@paul0403
paul0403 deleted the decomp/qref-decomposable-interface branch September 16, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants