Support magic-T allocation via qp.allocate (MLIR + capture path) - #3029
Open
Qottmann wants to merge 34 commits into
Open
Support magic-T allocation via qp.allocate (MLIR + capture path)#3029Qottmann wants to merge 34 commits into
Qottmann wants to merge 34 commits into
Conversation
This was referenced Jul 16, 2026
Qottmann
added a commit
that referenced
this pull request
Jul 22, 2026
Own all jax_tracer legacy support on top of #3029: qref-mode dynamic wires, allocate/deallocate tracing, MCM/PPM routing, control-flow wire propagation, qref register lifetime, and ppr-to-ppm deallocation ordering. Includes legacy and dual-mode pytest coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
Update SpecsResources field names and bump the PennyLane pin to 0.46.0.dev62 so CI uses the latest resource hierarchy. Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
force-pushed
the
qottmann/allocate-magic-core
branch
from
July 22, 2026 10:49
efcea1a to
541804b
Compare
Qottmann
added a commit
that referenced
this pull request
Jul 22, 2026
Own all jax_tracer legacy support on top of #3029: qref-mode dynamic wires, allocate/deallocate tracing, MCM/PPM routing, control-flow wire propagation, qref register lifetime, and ppr-to-ppm deallocation ordering. Includes legacy and dual-mode pytest coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
added a commit
that referenced
this pull request
Jul 22, 2026
Restore capture=False allocate error coverage, add negative deallocate tests, consolidate deallocate guard logic, document staged fabricate primitives for Co-authored-by: Cursor <cursoragent@cursor.com> #3027, and fix the sharp_bits.rst cross-reference syntax.
Qottmann
added a commit
that referenced
this pull request
Jul 22, 2026
Own all jax_tracer legacy support on top of #3029: qref-mode dynamic wires, allocate/deallocate tracing, MCM/PPM routing, control-flow wire propagation, qref register lifetime, and ppr-to-ppm deallocation ordering. Includes legacy and dual-mode pytest coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
Update resource specs tests, Operator2 PLXPR expectations, and decomposition graph handling for abstract Adjoint/Controlled resource reps introduced with magic-T and the new resource API. Co-authored-by: Cursor <cursoragent@cursor.com>
dime10
requested changes
Jul 22, 2026
dime10
left a comment
Contributor
There was a problem hiding this comment.
Nice work! I think we just need to sort out the jax primitive situation
Skip C(...) decomposition-graph nodes for Operator2 controlled reps, restore exact SpecsResources type equality in specs tests, and add a changelog entry. Co-authored-by: Cursor <cursoragent@cursor.com>
Test-suite and dependency-pin updates are not user-facing release notes. Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
added a commit
that referenced
this pull request
Jul 23, 2026
Own all jax_tracer legacy support on top of #3029: qref-mode dynamic wires, allocate/deallocate tracing, MCM/PPM routing, control-flow wire propagation, qref register lifetime, and ppr-to-ppm deallocation ordering. Includes legacy and dual-mode pytest coverage. Co-authored-by: Cursor <cursoragent@cursor.com>
When controls are applied via qfunc form (e.g. qp.ctrl(qp.S, wire)(0)), PennyLane stores control wires on the interpreter rather than in operator_p.n_ctrls. Merge self.control_wires into handle_operator and add regression tests from #3035. Co-authored-by: Cursor <cursoragent@cursor.com>
Lower state="magic" and state="magic_conj" to pbc.ref.fabricate with qref deallocation, and enable the legacy tape path for dynamic wire allocation. Co-authored-by: Cursor <cursoragent@cursor.com>
Erase dead pbc.ref.fabricate and qref.alloc_qb anchor ops at the end of conversion so they do not reach LLVM lowering, and update TestPBC checks. Co-authored-by: Cursor <cursoragent@cursor.com>
Fix import ordering, apply black formatting, and add a changelog entry. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Both capture and legacy frontends now emit allocate/deallocate at the jaxpr level; MLIR lowering selects qref.alloc or pbc.ref.fabricate from the state argument. Co-authored-by: Cursor <cursoragent@cursor.com>
Map the new Python state strings to existing MLIR magic enums during allocate lowering and update tests and docs accordingly. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Restore capture=False allocate error coverage, add negative deallocate tests, consolidate deallocate guard logic, document staged fabricate primitives for Co-authored-by: Cursor <cursoragent@cursor.com> #3027, and fix the sharp_bits.rst cross-reference syntax.
Describe the capture-path allocate feature in terms of user benefit rather than implementation details, per changelog guidelines. Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
force-pushed
the
qottmann/allocate-magic-core
branch
from
July 23, 2026 10:34
bb4d012 to
391268d
Compare
Graph decomposition tests used state="any" and restored=True, which now correctly raise CompileError per review feedback; zero-state allocation matches the previous Catalyst behaviour for these cases. Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
commented
Jul 23, 2026
Match the style of other tests in test_from_plxpr.py per review feedback. Co-authored-by: Cursor <cursoragent@cursor.com>
…AI/catalyst into qottmann/allocate-magic-core
dime10
approved these changes
Jul 23, 2026
This was referenced Jul 23, 2026
paul0403
reviewed
Jul 23, 2026
paul0403
reviewed
Jul 23, 2026
JerryChen97
pushed a commit
that referenced
this pull request
Jul 23, 2026
## Summary PennyLane **dev62** is the minimum pin that includes both [PennyLaneAI/pennylane#9846](PennyLaneAI/pennylane#9846) (`magic-T`) and [PennyLaneAI/pennylane#9841](PennyLaneAI/pennylane#9841) (resource API). This PR bumps Catalyst to that pin and fixes the resulting fallout. **Resource API migration (#9841)** - Bump PennyLane to `0.46.0.dev62` in `.dep-versions` and `doc/requirements.txt` - Replace `SymbolicSpecsResources` checks with `SpecsResources.is_symbolic` - Rename resource fields in tests: `gate_types`/`gate_counts` → `quantum_operations`, `measurements` → `measurement_processes`, `num_gates` → `total_quantum_operations` - Drop `gate_sizes` assertions (no longer tracked) - Handle `PBCSpecsResources` in PPR specs tests (depth fields) **dev62 fallout (Operator2 / magic-T)** - `decompose.py`: safe `.params` access for Operator2 ops; skip abstract `Adjoint(...)` / `Controlled(...)` decomposition-graph nodes that lack `op_type` - PLXPR tests: single-qubit ops like `S`/`T` now lower to `qref_operator` instead of `qref_qinst` - `test_adjoint.py`: replace removed `qp.Rotation` with `qp.Rot` - `test_quantum_control.py`: compare `ControlledOp2` decompositions with `qp.equal` - `test_specs.py`: normalize doubly-controlled `C(S)` counts in `test_complex` This is the base branch for the magic-state allocation stack (`#3029` → `#3027`). --------- Co-authored-by: Cursor <cursoragent@cursor.com>
…ottmann/allocate-magic-core
Document static num_wires in allocate lowering, drop redundant magic MLIR pytest covered by lit, and add value-semantics CHECKs for magic_conj fabricate. Co-authored-by: Cursor <cursoragent@cursor.com>
Mirror handleRefFabricate in reference_semantics_conversion and cover magic and magic_conj in Quantum SemanticsConversion lit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Use quantum.custom result wires in reference-semantics conversion tests and tie ref-side CHECKs to the fabricated qubit in QRef fabricate lit tests. Co-authored-by: Cursor <cursoragent@cursor.com>
paul0403
reviewed
Jul 24, 2026
Co-authored-by: Cursor <cursoragent@cursor.com>
Deallocate the PauliX result wire after ref-to-value conversion, matching value-semantics gate behaviour. Co-authored-by: Cursor <cursoragent@cursor.com>
Use state="zero" in decomposition lit tests, ignore the restored flag in handle_allocate so PennyLane work-wire decomps compile, and align docs/tests. Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3029 +/- ##
==========================================
- Coverage 96.97% 96.94% -0.03%
==========================================
Files 165 165
Lines 19111 19160 +49
Branches 1819 1831 +12
==========================================
+ Hits 18532 18575 +43
- Misses 424 427 +3
- Partials 155 158 +3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
albi3ro
reviewed
Aug 5, 2026
Comment on lines
+1379
to
+1382
| - The ``state="any"`` configuration is not supported by Catalyst and will raise a | ||
| compilation error. The ``restored`` keyword is ignored. Catalyst supports | ||
| ``state="zero"`` initialization (the default), as well as magic state | ||
| initialization (see below). |
Contributor
There was a problem hiding this comment.
Why can't we just continue treating state="any" as state="zero"? A little less efficient, but should still work?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds capture-path (
qjit(capture=True)) support forqp.allocate(..., state="magic-T"|"magic-T-adj"), pairing with the merged PennyLaneAI/pennylane#9846. Magic states lower through qref/PBC topbc.fabricate(H+T / H+T†).This is PR 1 of 2. #3027 adds all legacy (
capture=False) tracing on top of this PR.User-facing state strings:
"magic-T"and"magic-T-adj". MLIR/PBC enums remainmagic/magic_conj; Catalyst maps at lowering time.MLIR / PBC lowering
pbc.ref.fabricatefor magic and magic-conjugate preparationpbc.ref.fabricate→pbc.fabricatein value-semantics conversion, with dead-anchor cleanupUnified allocate/deallocate jaxpr
allocate_prim/deallocate_primqref_jax_primitives.pyselectsqref.allocvspbc.ref.fabricatefromstate"magic-T"/"magic-T-adj"→ MLIRmagic/magic_conjCapture path only
qfunc_interpreter.pyhandles allocate/deallocate via unified jaxpr primitivesCI / deps
0.46.0.dev62(.dep-versions,doc/requirements.txt)Tests & docs (capture-only)
capture=True)capture=Trueonly)sharp_bits.rst+ changelogReview guide
mlir/include/PBC/IR/PBCRefOps.td,mlir/lib/QRef/Transforms/value_semantics_conversion.*,mlir/lib/PBC/IR/PBCOps.cppfrontend/catalyst/from_plxpr/qref_jax_primitives.pyfrontend/catalyst/from_plxpr/qfunc_interpreter.py,frontend/catalyst/device/verification.pyTest plan
make format check=1(clang-format, black, isort)Related
jax_tracerwork