Skip to content

Migrate --decompose-lowering to reference semantics - #3224

Merged
paul0403 merged 43 commits into
mainfrom
paul0403/decompose_lowering_qref
Sep 16, 2026
Merged

paul0403 merged 43 commits into
mainfrom
paul0403/decompose_lowering_qref

Conversation

@paul0403

@paul0403 paul0403 commented Sep 14, 2026

Copy link
Copy Markdown
Member

Context:
Although we are saying we just want functionality for Q3, but the qubit extract index walkback in --decompose-lowering is just way too extreme to overlook.

Description of the Change:
Migrate --decompose-lowering to reference semantics.

Benefits:
--decompose-lowering no longer performs a SSA qubit def-use chain walk back per gate instance.

Note that we are not changing any signature of the rules, so all the stablehlo/extract index stuff is still present.
All this PR does is get rid of the qubit SSA value walkback.

[sc-129852]

yde773786 and others added 24 commits September 9, 2026 14:34
… for gates that can be decomposable. Ensure closely followed implementation as in Quantum dialect
… decomposableGateInterface in Quantum dialect
Changelog generalized to include all PRs that implement DecomposableGateInterface across dialects

Co-authored-by: Ali Asadi <10773383+maliasadi@users.noreply.github.com>
… for gates that can be decomposable. Ensure closely followed implementation as in Quantum dialect
… decomposableGateInterface in Quantum dialect
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
@paul0403
paul0403 marked this pull request as ready for review September 15, 2026 19:48

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

❤️

Comment thread mlir/include/QRef/Utils/QubitIndex.h
Comment thread mlir/lib/QRef/Transforms/DecompUtils.cpp
@yde773786
yde773786 force-pushed the decomp/qref-decomposable-interface branch from ecf06c6 to bffe31d Compare September 16, 2026 14:38
Base automatically changed from decomp/qref-decomposable-interface to main September 16, 2026 15:02
Comment thread frontend/test/lit/GraphDecomposition/TestAdjointParametric.mlir
Comment thread frontend/test/lit/GraphDecomposition/TestCtrlDistributeRegion.mlir
Comment thread mlir/lib/Quantum/Transforms/reference_semantics_conversion.cpp
Comment thread mlir/lib/Quantum/Transforms/GraphDecomposition/graph_decomposition.cpp Outdated
Comment thread mlir/include/QRef/Utils/QubitIndex.h Outdated
Comment thread mlir/lib/QRef/Transforms/DecomposeLoweringImpl.hpp Outdated
Comment thread mlir/lib/QRef/Transforms/DecompUtils.cpp Outdated
Comment thread mlir/lib/QRef/Transforms/DecompUtils.hpp 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.

Thanks @paul0403!

Don't forget to update the changelog 🙂

@paul0403
paul0403 merged commit 97756a5 into main Sep 16, 2026
38 checks passed
@paul0403
paul0403 deleted the paul0403/decompose_lowering_qref branch September 16, 2026 16:56
maliasadi added a commit that referenced this pull request Sep 16, 2026
**Context:**
As `--decompose-lowering` is moved to ref semantics (#3224) and the pass
inlines a rule into the operator it decomposes by matching each rule
function's arguments to the operator's signature, the pass reads a
user-defined custom rule back as `func(qreg, param*, inWires*, ...)`.
Two independent defects broke that pipeline for `Operator2` gates and
crashed the pass with a `SmallVector` out-of-bounds / param-count
assertion in `findParamTypeRange`:

- args sorting/ordering in the frontend: the kwargs were serialized in a
single sorted-by-name order `subroutine` traces through `jax.jit` which
flattens keyword arguments in sorted-name order and a wire arg whose
name sorts before a parameter's (e.g. `reg` < `x`) placed ahead of the
param and mismatched the parameter/wire split. This is fixed now!

- unused args in the pass: The qref `DecomposeLoweringPass` no longer
erases unused rule args so I removed `removeUnusedFuncArgs` in this PR.
A rule whose body does not use one of its args had that arg stripped
from the function signature, after which the analyzer mistook the
wire-index operand for the arg and read past the end of the arg list.

**Related GitHub Issues:**
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.

4 participants