-
Notifications
You must be signed in to change notification settings - Fork 627
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 creating a prod op with a qfunc #4011
Conversation
Hello. You may have forgotten to update the changelog!
|
Codecov Report
@@ Coverage Diff @@
## master #4011 +/- ##
=======================================
Coverage 99.71% 99.71%
=======================================
Files 345 345
Lines 30726 30737 +11
=======================================
+ Hits 30639 30650 +11
Misses 87 87
|
[sc-37068] |
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.
Bringing in @trbromley for this discussion. What do we think about the syntax:
qml.prod(qfunc)(*args, **kwargs)
Yes in this case we will return a function instead of a Prod
operator, but we do support this behaviour in other places already, like adjoint
.
If we don't want to have the same function with different arguments and outputs, maybe we could just create a new function qml.qfunc_to_opeator
, or something else better named?
+1 to having @DSGuala @Jaybsoni will this help solve the issue with using |
sounds good. I've already updated the PR to match that, but I also updated the 4 cases of concern I thought of. One highlights why this isn't the same as |
the behaviour surrounding single-op qfuncs (and single-operand Prods in general) is too varied, and this concept (converting from some input type to a single operator) needs more consideration. We will pick this up in a new manner for the next release |
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.
I like this solution and think it will end up being very useful.
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 to me
Context:
Quantum functions (aka qfuncs) are helpful ways of encapsulating a collection of operators. So is the new Prod operator!
Description of the Change:
Users can pass a qfunc to
qml.prod
in order to effectively convert from a qfunc to a ProdBenefits:
qfuncs are loosely defined, since they are vanilla python callables and PennyLane can't do much with them. Prods are PennyLane operators and generally much more powerful objects. This will hopefully make stuff easier for users as well.
Possible Drawbacks:
Errors/behaviour can get uglier when mis-used, but I don't think it's worth the extra type-checking (lmk if you want it though). Here are some examples to open discussion:
AttributeError: 'function' object has no attribute 'wires'
because we can't combine function arguments with operators:ParametrizedEvolution
is an Operator but it's also a callable, soprod
would confuse it as a qfunc if passed on its own (which used to fail saying you need multiple operands), and now it just returns another wrapper whose behaviour honestly confuses me:qml.adjoint
because it can accept an operator or a function.qml.adjoint(qfunc())
also fails likeprod
, butqml.adjoint(some_op())
doesn't fail. There's no analog for this withprod
.here's the link to page in docs if you wanna see the example rendered