Complete legacy tracing for dynamic magic wires#3027
Open
Qottmann wants to merge 2 commits into
Open
Conversation
This was referenced Jul 15, 2026
3 tasks
joshuasteier
pushed a commit
to joshuasteier/pennylane
that referenced
this pull request
Jul 21, 2026
## Summary - Extend `AllocateState` and `qp.allocate()` with `state="magic"` and `state="magic_conj"` for PBC-aligned magic state allocation. - Reject `restored=True` for magic state allocations since those states cannot be restored before deallocation. - Raise `AllocationError` in `resolve_dynamic_wires` for magic states until device simulator support is added. ## Test plan - [x] `tests/test_allocation.py` — enum values, capture jaxpr params, `restored=True` error, `resolve_dynamic_wires` error - [x] CI Merge this PR before the companion [Catalyst PR](PennyLaneAI/catalyst#3027) Made with [Cursor](https://cursor.com) Expose the PBC magic state preparation routine [sc-124605] --------- Co-authored-by: Cursor <cursoragent@cursor.com>
Qottmann
force-pushed
the
qottmann/allocate-magic
branch
from
July 22, 2026 10:02
56de60b to
57f2855
Compare
Qottmann
force-pushed
the
qottmann/allocate-magic
branch
from
July 22, 2026 10:17
57f2855 to
c1e71d2
Compare
Qottmann
force-pushed
the
qottmann/allocate-magic-core
branch
from
July 22, 2026 10:49
efcea1a to
541804b
Compare
Qottmann
force-pushed
the
qottmann/allocate-magic
branch
from
July 22, 2026 10:49
c1e71d2 to
265e202
Compare
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.
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
force-pushed
the
qottmann/allocate-magic
branch
from
July 22, 2026 11:03
265e202 to
8327ff1
Compare
…nyLaneAI/catalyst into qottmann/allocate-magic
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 all legacy (
capture=False) Catalyst support for magic-T dynamic wires. Stacks on #3029, which lands MLIR lowering and the capture path only.Diff: 6 files, +429 / −42 (single commit on top of #3029).
This PR owns every
jax_tracer.pychange (+218 lines): qref-mode tracing, allocate/deallocate, MCM/PPM routing, control-flow wire propagation, register lifetime, and a compiler fix.Enables TemporaryAND-style workflows: allocate magic-T ancillas → PPM → reactive
qp.cond.Legacy jax_tracer foundation
QRegPromiseqref mode + dynamic-wire → qubit mapping_trace_allocate/_trace_deallocatevia unifiedallocate_prim/deallocate_primMid-circuit measurement routing
MidCircuitPauliMeasure→qref_pauli_measure_pwhen dynamic wires presentMidCircuitMeasure→qref_measure_pwhen dynamic wires presentControl-flow dynamic-wire propagation
cond/for/while/ adjoint regionsdeallocateRegister lifetime & ordering
sort_eqns)ppr-to-ppm fix
quantum.dealloc_qbpast late PPM ops to avoid magic-qubit use-after-deallocTests (+114 pytest lines)
capture=True/False), pauli_measure, mid-circuit measureqp.condwith pre-allocated dynamic wiresReview guide
frontend/catalyst/jax_tracer.pyfrontend/catalyst/api_extensions/quantum_operators.pyfrontend/catalyst/api_extensions/control_flow.pyfrontend/catalyst/jax_extras/tracing.pymlir/lib/PBC/Transforms/ppr_to_ppm.cppTest plan
frontend/test/pytest/test_dynamic_qubit_allocation.py(legacy + dual-mode tests)make format check=1(clang-format, black, isort)Related
jax_tracer)