Repository navigation
Preserve change-op-basis structure in adjoint rule of ChangeOpBasis2 - #10568
Merged
Merged
Conversation
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.
Assisted by Codex.
Assisted by Codex.
Assisted by Codex.
Remove the temporary companion-wheel CI setup and match only the known shared-qubit compiler error in the four affected cases. Assisted by Codex.
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Assisted-by: Codex
Updated changelog to reflect changes in change_op_basis function regarding operator instances and program capture. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Assisted-by: Codex
Assisted-by: Codex
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Assisted-by: Codex
Assisted-by: Codex
Co-authored-by: David Wierichs <david.wierichs@xanadu.ai>
Assisted-by: Codex
Assisted by Codex.
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.
Describe the current initialization order: import the subcircuit decorator before the operator modules that use it. 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.
The adjoint rule of ChangeOpBasis2 now emits a ChangeOpBasis2 with the inverted target, so that controlling the adjoint only controls the target. The adjoint also inverts and swaps compute and uncompute, which fixes adjoints with an explicit uncompute_op that is not the adjoint of compute_op. Assisted-by: Cursor (Claude) Co-authored-by: Cursor <cursoragent@cursor.com>
Assisted-by: Cursor (Claude) Co-authored-by: Cursor <cursoragent@cursor.com>
dwierichs
marked this pull request as ready for review
November 20, 2026 08:22
ChangeOpBasis2ChangeOpBasis2
The adjoint rule now introduces basis-change nodes, which adds 10 entries to the all_decomps doctest and flips an RX/RZ cost tie in the decomposition inspector test. Restore the pylint suppression that CI requires. Assisted-by: Cursor (Claude) Co-authored-by: Cursor <cursoragent@cursor.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10568 +/- ##
==========================================
- Coverage 99.38% 99.38% -0.01%
==========================================
Files 613 613
Lines 67668 67673 +5
==========================================
+ Hits 67255 67259 +4
- Misses 413 414 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The legacy Adjoint(ChangeOpBasis) rule applied compute, adjoint(target) and uncompute, which is only correct if uncompute is the adjoint of compute. It now applies the adjoints of uncompute, target and compute, unwrapping operands that already are adjoints. The adjoint tests now also run with program capture enabled, and the changelog entry for the structured adjoint is limited to Operator2 operands. Assisted-by: Cursor (Claude) Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com> # Conflicts: # doc/releases/changelog-dev.rst # pennylane/decomposition/all_decomps.py
Contributor
Author
|
Review by Opus 5.5 on high effort.
|
JerryChen97
approved these changes
Nov 20, 2026
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.
Context:
Since #10511 we keep
ChangeOpBasis2intact under program capture, soC(ChangeOpBasis2)only controls the target. The adjoint rule, however, still splits the operator into three plain operations: compute,adjoint(target), uncompute, without the change-op-basis structure.Thus, controlled adjoints end up controlling all three parts.
While fixing this, I found that the adjoint was also wrong when
uncompute_opis given explicitly and isn't the adjoint ofcompute_op. Both the rule andChangeOpBasis2.adjoint()kept compute and uncompute unchanged, which only gives the right unitary when uncompute is the adjoint of compute. The existing testtest_adjoint_decomposition_with_explicit_uncomputedidn't catch this, because the operator's matrix is computed from the same decomposition.Description of the Change:
Adjoint(ChangeOpBasis2)rule now emits a singleChangeOpBasis2(adjoint(uncompute), adjoint(target), inv(compute)), and its resources are that one operator.change_op_basisChangeOpBasis2.adjoint()now inverts and swaps compute and uncompute in the same way._inversehelper unwraps an existingAdjoint/Adjoint2rather than nesting another adjoint. In the common case where uncompute defaults toadjoint(compute), the adjoint keeps the originalcompute_op, with noAdjoint(Adjoint(...))resource keys.Benefits:
ChangeOpBasisto only accept operator inputs #10511.Possible Drawbacks:
Related GitHub Issues:
Follow-up to #10511.
Made with AI