You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update ChangeOpBasis to only accept operator inputs - #10511
Context:
Currently, change_op_basis cannot be used with program capture when receiving quantum functions as input. To circumvent this, we unroll it before capture so that we capture the compute, target, and uncompute operators separately. This creates a major source of inefficiency because we lose the ability to decompose controlled COBs efficiently, because the decomposition of controlled COBs does not need to add controls to the compute and uncompute operators. Since we now have qp.subcircuit, we can continue allowing the use of quantum functions as input while enabling true capture compatibility by enforcing its use in place of vanilla quantum functions.
Description of the Change:
Update change_op_basis to stop unrolling when program capture is enabled.
Raise an informative error if the inputs aren't operators
Update decomposition rules across the ecosystem that used change_op_basis with quantum functions to now use qp.subcircuit
To reproduce the passing case from #10357, install this PR's PennyLane branch with Catalyst 0.16.0.dev144, then run the issue's sample unchanged, including qp.specs(node, level="all")(0.6931). Keep Toffoli excluded from the gate set. The example completes with CNOT, RZ and PauliX resources and no Toffoli requirement. Resource counts are conservative upper bounds. Broader shared-wire cases still depend on Catalyst #3470.
Require operator operands under capture and retain legacy callable support outside capture. Cover composite identity and mixed-operand retracing.
Authored with assistance from an AI assistant (Codex).
Replace callable operands across the affected rules with registered subcircuits or direct operators. Preserve composite resource dependencies and provide an internal subcircuit import path for built-in rules.
Validate capture replay, resource declarations, numerical behavior, and control handling. Targeted validation passed 1,182 tests and 21 source examples; Catalyst compilation remains unverified because generated bindings lack RuntimeCallOp.
Authored with assistance from an AI assistant (Codex).
Restore subcircuit to its original module and defer utility imports that
depend on partially initialized operator or template classes. Keep
built-in subcircuit classes at module scope and preserve callable package
exports, including aliases and directly imported dependencies.
Add a fresh-process regression covering imports, decomposition registration,
and serialization.
Validation: 249 focused PennyLane tests and 36 Catalyst tests passed.
Authored with assistance from OpenAI Codex.
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.39%. Comparing base (58a3d98) to head (272bc4f). ⚠️ Report is 1 commits behind head on main.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Multi-wire MultiRZ QJIT remains broken behind expected-failure marks, and _SelectTHCBasis omits live angle-register wires needed by matrix construction and wire-based transforms.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Making rotation_data compilable embeds full QROM tables in capture metadata and resource keys, causing costly flattening and repeated full-table hashing for large THC inputs.
rotation_data includes all QROM table bits, so declaring it compilable puts those bits into capture metadata and _SelectTHCBasis resource keys instead of array operands. For large THC inputs, capture flattens the tables into scalar leaves and Operator2.__hash__ serializes the full tables on each call, adding repeated work proportional to their size. Keep only the precision and batch layout static; pass the tables as a dynamic boolean array and construct QROM resource declarations from its shape.
…operators (#3470)
**Context:**
Catalyst cannot currently support hybrid operators with multiple
operator arguments that share wires. This is a blocker for updates being
added to `change_op_basis` in
PennyLaneAI/pennylane#10511.
**Description of the Change:**
Frontend:
* When tracing a rule body, prepare dummy base-wire arguments in
alphabetical order of their wire argument names, with control work wires
appended separately. This keeps the generated slices consistent with
MLIR decomposition lowering.
* Lowering of the OperatorOp instance itself is unchanged, since it
already produces a sorted `qubit_map`.
* Pass abstract wire types to resource functions and compose nested
resource controls using operator objects.
MLIR:
* During decomposition lowering, gather rule wires by iterating through
`OperatorOp::getQubitMap()`, via `getRuleQubits()`.
* `OperatorOp::getWireLens()` now directly iterates through `qubit_map`
in both QRef and Quantum, without sorting it back into operand order.
* Allow `qref.operator` to opt out of the non-control qubit uniqueness
check. Control-control and control-target overlaps remain invalid.
* During value-semantics conversion, deduplicate aliased qubit operands
and remap `qubit_map` so each physical qubit is threaded once.
Regression tests exercise overlapping operator arguments using generic
composite operators. Existing tests continue to verify that
`change_op_basis` unrolls during capture.
**Benefits:**
Better support for composite operators
**Possible Drawbacks:**
**Related GitHub Issues:**
[sc-136999]
AI assistance was used with Codex
Reviewed using Codex Astra 6 on high.
Use PascalCase for @Subcircuit definitions because the decorator returns
an Operator2 subclass. Keep ordinary resource and decomposition functions
in snake_case, and preserve leading underscores for private classes.
Rename the 12 inconsistent subcircuits and update their references,
inspector output, and documentation examples.
Assisted by Codex.
Replace the private _THCSelect subcircuit with SelectTHC(...) @ Z(sign_wire). The product exposes both factors, preserves Z-then-SelectTHC execution order, and stays inside the enclosing compute-uncompute boundary.
Assisted by Codex.
Use a static reverse flag instead of separate forward and inverse subcircuit classes, matching the other basis helpers. Register direction-dependent resources and update the ordinary and phase-gradient callers and existing tests.
Assisted by Codex.
Add a shared test helper for validating a selected decomposition rule and the registered decompositions of its structured compute, target, and uncompute operands. Reuse it in the PPR, parametric basis change, and SingleExcitation tests, removing duplicated loops and operator-specific exclusions.
Assisted by Codex.
…3499)
- [x] TODO: bump version again after PL TestPyPI uploaded
Update the ordinary and symbolic resource-collection tests to expect
retained `ChangeOpBasis2` nodes instead of flattened gates.
Blocked by:
- #3470: shared-wire hybrid operands (this PR's base).
- PennyLaneAI/pennylane#10511: retained basis changes during capture.
Assisted by Codex.
---------
Co-authored-by: Mudit Pandey <mudit.pandey@xanadu.ai>
Co-authored-by: Mudit Pandey <18223836+mudit2812@users.noreply.github.com>
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
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.
Context:
Currently,
change_op_basiscannot be used with program capture when receiving quantum functions as input. To circumvent this, we unroll it before capture so that we capture the compute, target, and uncompute operators separately. This creates a major source of inefficiency because we lose the ability to decompose controlled COBs efficiently, because the decomposition of controlled COBs does not need to add controls to the compute and uncompute operators. Since we now haveqp.subcircuit, we can continue allowing the use of quantum functions as input while enabling true capture compatibility by enforcing its use in place of vanilla quantum functions.Description of the Change:
change_op_basisto stop unrolling when program capture is enabled.change_op_basiswith quantum functions to now useqp.subcircuitBenefits:
Possible Drawbacks:
Related GitHub Issues:
[sc-135561][sc-137499]
To reproduce the passing case from #10357, install this PR's PennyLane branch with Catalyst
0.16.0.dev144, then run the issue's sample unchanged, includingqp.specs(node, level="all")(0.6931). Keep Toffoli excluded from the gate set. The example completes withCNOT,RZandPauliXresources and noToffolirequirement. Resource counts are conservative upper bounds. Broader shared-wire cases still depend on Catalyst #3470.AI assistance was used with Codex