-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Controlled
subclasses no longer bind base class primitives on initialization
#6672
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have time to write some tests?
One way to test if this works if to do:
@DefaultQubitInterpreter(num_wires=3)
def f():
qml.CNOT((0,1))
return qml.state()
jax.jit(f)()
or something like that.
@albi3ro Thanks for the suggestion. I was stuck on what tests should be added 😄 . I'd like to localize the tests further, so I'm going to add a test that uses |
Even something like:
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #6672 +/- ##
==========================================
- Coverage 99.66% 99.64% -0.02%
==========================================
Files 467 467
Lines 44095 44119 +24
==========================================
+ Hits 43946 43963 +17
- Misses 149 156 +7 ☔ View full report in Codecov by Sentry. |
I ask this without detailed information about the PlxprInterpreter - would there be a way to have a version of the test in No worries if that's tricky to do, just wondering if we can add an easy check to make sure we remember to do this with future operations. |
Maybe:
|
@albi3ro @lillian542 mind if we make the |
I could actually add this in #6343 in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM then!
The constructors of subclasses of
Controlled
(CNOT
,CRX
, etc.) construct the base operator so that the parentControlled
class can be initialized correctly. However, in doing so, the primitive of the base operator is also binded. We don't want this, because calling constructors is part of the concrete implementation, and binding primitives can create abstract values (when usingmake_jaxpr
, etc.), which we don't want.Changes:
Controlled
to usetype.__call__(base_op_class, ...)
instead ofbase_op_class(...)
to construct the base operator. This skips the call toop._primitive.bind
and just directly creates the class we want to construct.Downsides:
Controlled
, so it is an additional detail that devs have to keep in mind when adding new controlled ops.[sc-79769]