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

Add a projector observable to CirqDevice #62

Merged
merged 13 commits into from
Jun 4, 2021

Conversation

wongwsvincent
Copy link
Contributor

@wongwsvincent wongwsvincent commented May 27, 2021

Context:
Adding a projector observable to CirqDevice.

Description of the Change:
Implementing projector observable with Cirq's own cirq.ProductState.projector method.

Related GitHub PR:
Work coherently with PR #1356

@codecov
Copy link

codecov bot commented May 28, 2021

Codecov Report

Merging #62 (d86c2d8) into master (6fe3a57) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #62   +/-   ##
=======================================
  Coverage   99.14%   99.14%           
=======================================
  Files           8        8           
  Lines         349      349           
=======================================
  Hits          346      346           
  Misses          3        3           
Impacted Files Coverage Δ
pennylane_cirq/cirq_device.py 98.90% <ø> (ø)

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 6fe3a57...d86c2d8. Read the comment docs.

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 @wongwsvincent! Before I can approve, would you be able to add a small test for the projector observable, to make sure that it works correctly? Since it will be using Cirq directly to compute the expectation, rather than using the logic you added to QubitDevice (I believe).

I think there are two options here:

  • Add a small unit test using the device methods directly

  • Write an integration test using a QNode (this would require modifying the requirements.txt file so that the latest master of PennyLane is installed instead, e.g.

    git+https://github.com/PennyLaneAI/pennylane.git

Thank you for adding this!

CHANGELOG.md Outdated Show resolved Hide resolved
wongwsvincent and others added 3 commits May 28, 2021 10:15
@wongwsvincent
Copy link
Contributor Author

@josh146, I have only added a test_projector_expectation function in tests/test_expval.py as a start, as I have trouble setting up qsimcirq on my Mac, so I can't run make test locally and I'm hesitating a bit about whether I should continue committing tests I haven't checked myself locally.

P.S. It would be great if there's any suggestion on how to install qsimcirq on Mac OS, but I understand this is not an installation related to PennyLane library.

@josh146
Copy link
Member

josh146 commented Jun 1, 2021

Thanks @wongwsvincent!

as I have trouble setting up qsimcirq on my Mac, so I can't run make test locally and I'm hesitating a bit about whether I should continue committing tests I haven't checked myself locally.

This is perfectly fine 🙂 If you want to run the test suite locally, you can explicitly ignore the qsim tests, either by only running the test file you have modified,

pytest tests/test_expval.py -x --tb=short

or by using pytest's test selector command line argument:

pytest tests -x --tb=short -k "not (test_qsim or test_qsimh)"

P.S. It would be great if there's any suggestion on how to install qsimcirq on Mac OS, but I understand this is not an installation related to PennyLane library.

Unfortunately I am not sure - I know that qsim is quite tricky to install, even on linux! qsim might provide a dockerfile to use it with Docker, but apart from that, I am unsure. Note that it is perfectly fine to not run the test locally, and instead rely on CI within the PR :)

@wongwsvincent
Copy link
Contributor Author

Awesome! Thanks @josh146 , something like pytest tests/test_expval.py -x --tb=short is exactly what I need.
I ran that command and it passed the tests successfully. The same tests as the ones I added in pennylane/devices/tests/test_measurements.py are now included in pennylane-cirq/tests/test_expval.py, pennylane-cirq/tests/test_sample.py and pennylane-cirq/tests/test_var.py.
Hopefully all the tests on CI will be fine, and the PR will be ready to merge.

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 @wongwsvincent for the extra push with the tests!

The integration tests are still failing, but this is not the fault of your PR, rather, it looks like another bug in the Cirq plugin has been uncovered. Since that is out of scope here, I may override that failing CI check.

@@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
python-version: [3.7, 3.8]
Copy link
Member

Choose a reason for hiding this comment

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

I removed 3.6, since PL no longer supports it!

@@ -1,3 +1,3 @@
pennylane>=0.15
git+https://github.com/PennyLaneAI/pennylane.git
Copy link
Member

Choose a reason for hiding this comment

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

I also updated this to point to PL master, since qml.Projector is not present in the stable v0.15 release

@wongwsvincent
Copy link
Contributor Author

Thanks @josh146 for fixing some of the test errors!
There are six remaining errors all complaining about the use of numpy.complex64 vs complex128, but they don't look like they are caused by this PR as you have pointed out.
Please let me know if there's anything I am missing or I can help with this PR.

@josh146
Copy link
Member

josh146 commented Jun 4, 2021

There are six remaining errors all complaining about the use of numpy.complex64 vs complex128, but they don't look like they are caused by this PR as you have pointed out. Please let me know if there's anything I am missing or I can help with this PR.

Yep, they are orthogonal :) I will merge this PR now @wongwsvincent, which allows us to fix these bugs in a separate PR. I have to admit, off the top of my head I'm unsure what the bug is, it will require some investigation.

@josh146 josh146 merged commit d4d8a15 into PennyLaneAI:master Jun 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants