-
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
Adds the generator to the PauliRot operation #963
Conversation
Codecov Report
@@ Coverage Diff @@
## master #963 +/- ##
=======================================
Coverage 97.82% 97.82%
=======================================
Files 150 150
Lines 10482 10495 +13
=======================================
+ Hits 10254 10267 +13
Misses 228 228
Continue to review full report at Codecov.
|
How can i fix the |
Thanks @JiahaoYao for the contribution! Regarding black, have you installed the black formatter ( black -l 100 pennylane/ If you have, you may need to upgrade your pip install black --upgrade
black -l 100 pennylane/ |
thanks @josh146 |
Hi @JiahaoYao, thanks for the contribution! Are you ready for this one to be reviewed? |
please @co9olguy |
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 @JiahaoYao, will be nice to add this in! I just left a few comments, but will be happy to approve once they are sorted.
Also, don't forget to add the change and your name to the change log.
tests/ops/test_qubit_ops.py
Outdated
|
||
if pauli_word[0] == 'I': | ||
# this is the identity | ||
expected_gen = qml.PauliZ(wires=0) @ qml.PauliZ(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.
expected_gen = qml.PauliZ(wires=0) @ qml.PauliZ(wires=0) | |
expected_gen = qml.Identity(wires=0) |
would this work?
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.
agreed
tests/ops/test_qubit_ops.py
Outdated
expected_gen = expected_gen @ qml.PauliZ( | ||
wires=i) @ qml.PauliZ(wires=i) |
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.
expected_gen = expected_gen @ qml.PauliZ( | |
wires=i) @ qml.PauliZ(wires=i) | |
expected_gen = expected_gen @ qml.Identity(wires=i) |
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.
cool, i just want this operator.
tests/ops/test_qubit_ops.py
Outdated
spy = mocker.spy(qml.utils, "pauli_eigs") | ||
|
||
op.generator | ||
spy.assert_not_called() | ||
|
||
|
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.
What is the motivation for removing this part? I think it's not strictly required in terms of test coverage, but was a nice addition to check that the generator is not reconstructed each time it is accessed.
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 see, previously when i saw this op.generator
, I thought this was something that was forgotten to remove. no problem!
Sorry, by the way, how can I add the name to the change log? |
changed |
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 for this useful addition @JiahaoYao! There is one pending suggestion from @trbromley, but this looks good from my end once that is addressed.
Oh, and don't forget to update the changelog (.github/CHANGELOG.md
) with
- A short description of the change
- A link back to this PR
- Your name in the contributors section!
|
||
# Simplest case is if the Pauli is the identity matrix | ||
if pauli_word == "I" * len(pauli_word): | ||
self._generator = [np.eye(2 ** len(pauli_word)), -1 / 2] |
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.
@trbromley: we should overhaul how generators work. Rather than returning an operation class or a matrix, we should instead allow returning an operation instance or a matrix.
That way we could support returning qml.Identity(wires=self.wires)
here, which avoids creating a large identity matrix.
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.
@josh146, totally agree!
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'll turn this into a GitHub issue 👍
# We first generate the matrix excluding the identity parts and expand it afterwards. | ||
# To this end, we have to store on which wires the non-identity parts act |
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 helpful comments!
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.
cool!
@josh146 cool, added! |
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 @JiahaoYao, approved! Although I left one comment on the changelog.
.github/CHANGELOG.md
Outdated
* Adds the following generators to the `qml.operation` module: `MultiRZ`, `PauliRot`. These | ||
generators are required to construct the metric tensor for some optimizer. | ||
[(#895)](https://github.com/PennyLaneAI/pennylane/pull/895) |
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.
* Adds the following generators to the `qml.operation` module: `MultiRZ`, `PauliRot`. These | |
generators are required to construct the metric tensor for some optimizer. | |
[(#895)](https://github.com/PennyLaneAI/pennylane/pull/895) | |
* Adds the `PauliRot` generator to the `qml.operation` module. This | |
generator is required to construct the metric tensor. | |
[(#963)](https://github.com/PennyLaneAI/pennylane/pull/963) |
Thanks! Removing the mention of MultiRZ
since we added a line for that in the previous 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.
no problem
|
||
# Simplest case is if the Pauli is the identity matrix | ||
if pauli_word == "I" * len(pauli_word): | ||
self._generator = [np.eye(2 ** len(pauli_word)), -1 / 2] |
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.
@josh146, totally agree!
PauliRot
Add generators to some operations #895