Repository navigation
fix(capture): distinguish operator tracers from tensor data - #10156
Merged
Merged
Conversation
andrijapau
commented
Sep 16, 2026
Co-authored-by: Andrija Paurevic <46359773+andrijapau@users.noreply.github.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #10156 +/- ##
==========================================
- Coverage 99.44% 99.44% -0.01%
==========================================
Files 617 617
Lines 68032 68037 +5
==========================================
+ Hits 67652 67656 +4
- Misses 380 381 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
andrijapau
added a commit
to PennyLaneAI/catalyst
that referenced
this pull request
Sep 16, 2026
**Context:** Two PRs from PennyLane caused failures: - PennyLaneAI/pennylane#10113 - Issue (JukeBox support): The observable in the test is `qp.Y(0) @ qp.X(1) + 3 * qp.X(2)`. Under capture, the two halves now have different Python types: ``` left = Prod2 isinstance(Operator)=True <- Operator2 returns an instance right = DynamicJaxprTracer isinstance(Operator)=False <- Operator1 SProd returns a tracer ``` Before #10113, `Y(0) @ X(1)` produced a legacy `Prod`, so both sides were tracers and + went through `AbstractOperator._add`. Now the left side is a real `Prod2`, so Python calls `Operator2.__add__`, which tests in this order: ``` if isinstance(other, Operator): # False for an operator-valued tracer return qp.sum(self, other, lazy=False) if isinstance(other, TensorLike): # True -- a JAX tracer is TensorLike return qp.sum(self, qp.s_prod(scalar=other, operator=qp.Identity(self.wires), lazy=False), ...) ``` So the right-hand operator gets used as a scalar coefficient, producing `SProd(scalar=<operator tracer>, base=Identity([0,1]))`, a stray Identity appears in the plxpr. That is silent at capture time. It explodes when Catalyst's from_plxpr re-traces: `Sum._build_pauli_rep` evaluates `new_rep[pw] += coeff` with `coeff` being that operator tracer, `0.0 + tracer` defers to `AbstractOperator._radd`, which doesn't exist. - Fix: Requires changes in PennyLane: PennyLaneAI/pennylane#10156 - PennyLaneAI/pennylane#10144 - Issue: Gave a `DecompositionRule` a name dunder - Fix: Adjust stale test and add a new one to ensure proper behaviour. [sc-130870]
Operator2
Operator2
mudit2812
requested changes
Oct 20, 2026
mudit2812
left a comment
Collaborator
There was a problem hiding this comment.
Happy to approve once the imports are top-level in the tests
albi3ro
approved these changes
Oct 20, 2026
mudit2812
approved these changes
Oct 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.
Note
Partner PR in Catalyst: PennyLaneAI/catalyst#3371 that removes xfails
Context:
During capture, PennyLane treated some operators as scalar values. This added an unwanted
Identityand broke expressions such asqp.Y(0) @ qp.X(1) + 3 * qp.X(2)(sc-130866).Description of the Change:
InterfaceTensorhelper.Benefits:
Fixes mixed operator arithmetic during capture without losing Python 3.12 or static typing support.
Possible Drawbacks:
Code that inspects
TensorLikeat runtime will now see a class instead of a union. The runtime checks and static type definition must be kept in sync.AI Assistance:
Developed with assistance from OpenAI Codex.
[sc-130866]