-
Notifications
You must be signed in to change notification settings - Fork 575
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
Add object _queue_category
property and use it for sorting in tapes
#2408
Conversation
Thanks for giving this a shot! I am wondering if this is the best fix: what if we have an If it is possible to just relax the idea of two queues, I'd much prefer that one - is this worth trying? |
Codecov Report
@@ Coverage Diff @@
## master #2408 +/- ##
==========================================
+ Coverage 95.20% 99.47% +4.27%
==========================================
Files 244 244
Lines 19422 19427 +5
==========================================
+ Hits 18490 19325 +835
+ Misses 932 102 -830
Continue to review full report at Codecov.
|
@mariaschuld The adjoint of an observable would still be an observable, which would not be processed. I'm going to play around with getting rid of the differences between the three queues and see how many things that breaks. |
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, this should be enough to run simple workflows with the wrapper classes
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 Christina! I don't want to drag this out, but there are these two things left:
-
I strongly suggest having comments everywhere to say that this is a temporary fix (see suggestions). Otherwise I think this is the best solution.
-
About the checks: there is one serious issue that users try a lot when implementing quantum kernels with AmplitudeEmbedding:
AmplitudeEmbedding(...)
qml.adjoint(AmplitudeEmbedding())
...
A user does not know that this template, which refers to some routine, is implemented by QubitStatePreparation
, must always be the first operation.
Another example is if QubitStatePreparation is first applied to some qubits and then to others - a user cannot guess that this leads to a wrong result (at least I think it should reset the first qubits to zero).
In other words, if we have operators that need to be first in the circuit but this rule is opaque to users I feel we have to throw an error, and this won't change in future either?
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
Currently,
qml.tape.QuantumTape._process_queue
usesisinstance
checks to sort objects into_prep
,_ops
, and_measurement
lists.This implementation is reliant on inheritance details and implementations of the various operators and measurements. We change inheritance implementation for operators, we break quantum tapes. This will be especially relevant coming up with Arithmetic Wrapper classes.
So instead we want to rely on polymorphism and duck typing. Objects themselves will decide how they want to be processed by the tape, instead of the tape deciding how to process the objects.
This is accomplished by adding a
_queue_category
property to relevant objects. The_queue_category
can take on the values:"_prep"
"_ops"
"_measurements"
None
This also eliminates the need to maintain the
STATE_PREP_OPS
list inpennylane/tape/tape.py
, reducing the maintenance burden and the amount of code that needs to be modified when adding a single new operation.