Skip to content
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

Merged
merged 11 commits into from
Dec 19, 2020

Conversation

JiahaoYao
Copy link
Contributor

@JiahaoYao JiahaoYao commented Dec 14, 2020

@codecov
Copy link

codecov bot commented Dec 14, 2020

Codecov Report

Merging #963 (4630692) into master (e675ed7) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #963   +/-   ##
=======================================
  Coverage   97.82%   97.82%           
=======================================
  Files         150      150           
  Lines       10482    10495   +13     
=======================================
+ Hits        10254    10267   +13     
  Misses        228      228           
Impacted Files Coverage Δ
pennylane/ops/qubit.py 97.11% <100.00%> (+0.06%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e675ed7...4630692. Read the comment docs.

@JiahaoYao
Copy link
Contributor Author

How can i fix the black?

@josh146
Copy link
Member

josh146 commented Dec 14, 2020

Thanks @JiahaoYao for the contribution!

Regarding black, have you installed the black formatter (pip install black) and run it on the PL folder with a line length of 100?

black -l 100 pennylane/

If you have, you may need to upgrade your black version and run it again:

pip install black --upgrade
black -l 100 pennylane/

@josh146 josh146 changed the title fixes #895 Adds the generator to the PauliRot operation Dec 14, 2020
@JiahaoYao
Copy link
Contributor Author

thanks @josh146

@co9olguy
Copy link
Member

Hi @JiahaoYao, thanks for the contribution! Are you ready for this one to be reviewed?

@JiahaoYao
Copy link
Contributor Author

please @co9olguy

@co9olguy co9olguy added the review-ready 👌 PRs which are ready for review by someone from the core team. label Dec 16, 2020
Copy link
Contributor

@trbromley trbromley left a 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 Show resolved Hide resolved

if pauli_word[0] == 'I':
# this is the identity
expected_gen = qml.PauliZ(wires=0) @ qml.PauliZ(wires=0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_gen = qml.PauliZ(wires=0) @ qml.PauliZ(wires=0)
expected_gen = qml.Identity(wires=0)

would this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agreed

Comment on lines 1075 to 1076
expected_gen = expected_gen @ qml.PauliZ(
wires=i) @ qml.PauliZ(wires=i)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expected_gen = expected_gen @ qml.PauliZ(
wires=i) @ qml.PauliZ(wires=i)
expected_gen = expected_gen @ qml.Identity(wires=i)

Copy link
Contributor Author

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.

Comment on lines 1175 to 1180
spy = mocker.spy(qml.utils, "pauli_eigs")

op.generator
spy.assert_not_called()


Copy link
Contributor

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.

Copy link
Contributor Author

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!

@trbromley trbromley mentioned this pull request Dec 18, 2020
4 tasks
@JiahaoYao
Copy link
Contributor Author

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.

Sorry, by the way, how can I add the name to the change log?

@JiahaoYao
Copy link
Contributor Author

changed

Copy link
Member

@josh146 josh146 left a 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]
Copy link
Member

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh146, totally agree!

Copy link
Member

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 👍

Comment on lines +987 to +988
# 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really helpful comments!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool!

@JiahaoYao
Copy link
Contributor Author

@josh146 cool, added!

@trbromley trbromley self-requested a review December 18, 2020 14:22
Copy link
Contributor

@trbromley trbromley left a 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.

Comment on lines 101 to 103
* 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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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.

Copy link
Contributor Author

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]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@josh146, totally agree!

tests/ops/test_qubit_ops.py Show resolved Hide resolved
@josh146 josh146 merged commit bd61abd into PennyLaneAI:master Dec 19, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review-ready 👌 PRs which are ready for review by someone from the core team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants