-
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
[TAPE] Incorporate the tape refactor into core #823
Conversation
Codecov Report
@@ Coverage Diff @@
## master #823 +/- ##
==========================================
+ Coverage 91.05% 91.09% +0.03%
==========================================
Files 129 130 +1
Lines 8678 8701 +23
==========================================
+ Hits 7902 7926 +24
+ Misses 776 775 -1
Continue to review full report at Codecov.
|
Co-authored-by: antalszava <antalszava@gmail.com>
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.
Hi @josh146 this looks good overall! Left some questions/suggestions, would be keen to hear your thoughts, but overall would be good from my side. Also, I think there might be a couple of places where a search and replace might be needed to cover the qml.variable
, qml.various
occurrences in the tests.
A thing I was wondering about is if we'd like to move tape
out of beta
though it would stay an experimental feature. 🤔
Thanks for catching this Antal, I did use a lot of find and replace here 😬
It is definitely still an experimental feature. Perhaps we could raise a warning when the tape is enabled? Or would that be too annoying? |
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.
Perhaps we could raise a warning when the tape is enabled? Or would that be too annoying?
Hmm, it could indeed be a bit repetitive each time. I'm sort of on the fence. If users get to know about the features brought with tape
, they might already know that it's experimental, so it should be fine. Perhaps other reviewers would have further suggestions.
Thanks for the answers! Overall this looks good to me 😊
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 @josh146, looks awesome!
I noticed a few spots in test docstrings where qml.
had been added (my favourite was qml.various
). I left (a few too many) suggestions correcting them - sorry for the spam! (Just noticed @antalszava pointed it out too)
>>> with tf.GradientTape() as tape: | ||
... res = circuit(params) |
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.
Minor thing: could a novice reader get confused at seeing another "tape"-like object and be mixed up between our tape and the TF tape? A remedy to this could be to use the autograd interface for this example.
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.
Good point, I agree!
Co-authored-by: Tom Bromley <49409390+trbromley@users.noreply.github.com>
Thanks @trbromley and @antalszava! I've incorporated all your changes. Apologies for the |
Co-authored-by: Maria Schuld <mariaschuld@gmail.com>
import modified measurement functions within the quantum tape: | ||
|
||
>>> from pennylane.beta.queuing import expval, var, sample, probs | ||
As the quantum tape is a *beta* feature. See :mod:`pennylane.tape` |
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.
Maybe check the sentence above again, is the . supposed to be a comma?
sample(qml.PauliZ(0)) | ||
sample(qml.PauliX(1)) | ||
qml.sample(qml.PauliZ(0)) | ||
qml.sample(qml.PauliX(1)) |
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.
Hope you had a good search & replace function there :)
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.
Really a great idea to have tape mode! We can now extend the tape with new feature, staying in the experimental mode.
I checked out the branch and played around a bit, works like a charm.
🍾 |
Context:
pennylane.beta
, and better organized into a newpennylane.tape
subpackage. We also provide helper functions here to make it easier to use the new tape core if wanted.Description of the Change:
All tape components were moved into the new
pennylane.tape
directory. The tests were similarly restructured.Documentation has been written, see it here: https://pennylane--823.org.readthedocs.build/en/823/code/qml_tape.html
Three new mocks were added to the
QuantumTape()
context:That is, within a tape context, calling
qml.expval
et al. will instead result in a call to the functions within the newqml.tape.measure
module. After the context closes, these locations will resume pointing to the original core components.It is now possible to create a tape QNode by simply changing the qnode decorator to
qml.tape.qnode
:This allows a single Python file to contain a mixture of old and new QNodes.
Finally, two new convenience functions have been added;
qml.enable_tape()
andqml.disable_tape()
:This allows entire scripts/files to be globally switched to using the new tape core, by simply adding
qml.enable_tape()
near the top. This will be useful with testing compatibility, and benchmarking.In tape mode, we allow
qml.state()
to be used. Outside of tape mode, an error will be raised.Benefits: n/a
Possible Drawbacks:
In tape-mode, the QNode does not yet have feature-parity with the standard PennyLane QNode. Features currently not available in tape mode include:
Circuit drawing and visualization
Metric tensor computation
The ability to automatically extract the layer structure of variational circuits
Hashing and serialization.
The
qml.qnn
moduleThese can all be done in subsequent PRs.
Related GitHub Issues: n/a