-
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
Pr swap based transpiler #2118
Pr swap based transpiler #2118
Conversation
Thanks @mauriceweber --- I skimmed through quickly, very thorough documentation! I'll leave a review shortly :) |
Codecov Report
@@ Coverage Diff @@
## master #2118 +/- ##
=======================================
Coverage 99.42% 99.42%
=======================================
Files 243 244 +1
Lines 18338 18399 +61
=======================================
+ Hits 18232 18293 +61
Misses 106 106
Continue to review full report at Codecov.
|
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.
@mauriceweber thank you, this is a great implementation! I went through and left some comments, mostly relating to documentation and testing :)
For the testing, Codecov raised some places where parts of the logic is not being tested, so it might be good to add some additional unit tests, checking that this works for various circuit edge cases (e.g., for circuits that return qml.probs()
).
A final test that could be very nice to have: a test that ensures that after a circuit is transpiled, it remains differentiable. This is a good 'sanity check' test, since it can be very easy to accidentally break the differentiability when manipulating operations!
Hey @mauriceweber, I just wanted to check in here and see on the status of this PR :) Was this something you might have time to complete? |
Hi @josh146, yep I am planning to finish this still! The main thing left to do I think is to improve the functionality of the |
Great to hear @mauriceweber!
This is completely up to you, I might suggest not including this in the first version of this functionality, as the Tensor class and the Hamiltonian class are likely going to be 'merged' into the main Operator class going forward! If it is a quick and easy change, though, that would be fine. Otherwise, the following is also okay:
|
I couldn't find an easy fix for that, so let us not include it in the first version.
This is already included: pennylane/pennylane/transforms/transpile.py Lines 21 to 24 in 2746d6d
This is also implemented already (both in the pennylane/pennylane/transforms/transpile.py Lines 172 to 176 in aab82fa
pennylane/pennylane/transforms/transpile.py Lines 92 to 95 in aab82fa
|
My mistake @mauriceweber, apologies! I'll give it a final review, I just noticed that the tests aren't currently running due to the following issue:
I think you can remove this import, and simply write the test as follows: err_msg = "Measuring expectation values of tensor products or Hamiltonians is not yet supported"
with pytest.raises(NotImplementedError, match=err_msg):
transpiled_qnode() |
cool, thanks @josh146 !:)
Ah I see, I removed all the regex dependencies now, so that the tests should go through (had to remove some special characters from one error message) |
Hi @josh146 , I can see that some changes were requested but can't find what these are. Can you point me to the place where I can see the requested changes? And also, it seems that the tests stalled. Do we need to retrigger them? |
Hey @mauriceweber, I think this is from my old review - let me clear that for you :) I will find some time in the next two days or so to go through and give it a fresh review!
That is very odd 🤔 I'm not sure why that has happened, I will need to investigate that. |
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.
@mauriceweber fantastic work! This looks almost ready for merging now 🙂
Once the __main__
block is removed, and the other suggestions addressed, let me know and I can merge this in 💯
pennylane/transforms/transpile.py
Outdated
if isinstance(_m.obs, (Hamiltonian, Tensor)): | ||
# tensor products of observables | ||
raise NotImplementedError( | ||
"Measuring expectation values of tensor products or Hamiltonians is not yet supported" | ||
) |
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.
@mauriceweber I don't think this error can ever be raised, since such cases should be caught by the exception on line 94? In which case, this can be removed :)
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.
oh yep, that won't be raised -- I removed it:)
pennylane/transforms/transpile.py
Outdated
if __name__ == "__main__": | ||
import pennylane as qml |
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.
While convenient for testing and prototyping, this section should be removed prior to merging!
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.
oh totally, I forgot to remove it after testing!
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Co-authored-by: Josh Izaac <josh146@gmail.com>
Thanks for this awesome feature @mauriceweber! |
thanks for the support and the code reviews @josh146 !:) |
Before submitting
Please complete the following checklist when submitting a PR:
All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to the
test directory!
All new functions and code must be clearly commented and documented.
If you do make documentation changes, make sure that the docs build and
render correctly by running
make docs
.Ensure that the test suite passes, by running
make test
.Add a new entry to the
doc/releases/changelog-dev.md
file, summarizing thechange, and including a link back to the PR.
The PennyLane source code conforms to
PEP8 standards.
We check all of our code against Pylint.
To lint modified files, simply
pip install pylint
, and thenrun
pylint pennylane/path/to/file.py
.When all the above are checked, delete everything above the dashed
line and fill in the pull request template.
Context:
Add a swap-based router transform
Description of the Change:
new module transpile.py in pennylane.transforms; the transpile function takes as input a tape and hardware connectivity graph, and compiles the tape to ensure that it can be executed on the corresponding hardware.
Related GitHub Issues:
#2115