-
Notifications
You must be signed in to change notification settings - Fork 30
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
Allow standard qml.cond
usage of qml.cond(pred, qml.some_gate)(*args, **kwargs)
in qjit
#1232
base: v0.9.0-rc
Are you sure you want to change the base?
Conversation
qml.cond
usage of qml.cond(pred, qml.some_gate)(*args, wires=...)
qml.cond
usage of qml.cond(pred, qml.some_gate)(*args, wires=...)
in qjit
qml.cond
usage of qml.cond(pred, qml.some_gate)(*args, wires=...)
in qjitqml.cond
usage of qml.cond(pred, qml.some_gate)(*args, **kwargs)
in qjit
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## v0.9.0-rc #1232 +/- ##
==========================================
Coverage 97.96% 97.97%
==========================================
Files 77 77
Lines 11278 11318 +40
Branches 976 981 +5
==========================================
+ Hits 11049 11089 +40
Misses 180 180
Partials 49 49 ☔ View full report in Codecov by Sentry. |
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.
Looks good @paul0403, thanks! 🚀
I only have a few minor suggestions. I was also wondering if you could comment on the fact that the else_if
and otherwise
methods in CondCallable
also restrict their inputs to be functions without arguments. For example, would this be allowed/supported?
qml.cond(x > 42, qml.RY, qml.RX)(0.7, wires=0)
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.
Thanks it looks good, just one question 👍
Good catch! I'll add the other conditional branches. |
59e20de
to
90edf44
Compare
Hello. You may have forgotten to update the changelog!
|
Thanks for this! This gets us one step closer to making PennyLane's |
Done, now all three branches (true, false, sequence of else_ifs) are all supported |
Context:
The standard
qml.cond
usage for single gates fails with qjit:While users can work around this by using
catalyst.cond
syntax, it is a bit incovenient.Moreover, the fewer code changes required to qjit a pennylane circuit, the better. Since
qml.cond
just aliases tocatalyst.cond
within qjit, we should make sure qjit does not reject any valid plain pennylane use patterns.Description of the Change:
The error arises because the conditional branch functions are not allowed to have arguments. This is because the
CondCallable
class's__call__()
method does not take any arguments.While we do not want to change the overarching design of
CondCallable
, we can make a new class that inherits from it, which specifically deals with the case where the conditional branch function is a pennylane gate (likeqml.Hadamard
, ...).This new class, named
CondCallableSingleGateHandler
, has a__call__()
method that can take in arbitrary args and kwargs. The class creates a wrapper conditional function taking in no arguments and sends the wrapper to the usualCondCallable
, but the body of the wrapper calls the actual conditional branch function that is passed in. This allows us to perform the conditional branch function with arguments.Benefits:
The standard usage
qml.cond(predicate, qml.some_gate)(*args, **kwargs)
works within qjit.Related GitHub Issues: closes #449
[sc-55079]