-
Notifications
You must be signed in to change notification settings - Fork 155
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
Inverse QFT - Implementation and Test #15
Conversation
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 @vontell thanks for this. The inverse QFT looks great. Something we're excited to add in the roadmap are some general features in pyQuil that will allow you to take the dagger-adjoint of programs directly, though having this directly written out in the meantime works for me.
A general comment on the testing setup is that on client libraries like grove and pyquil our modus operandi is to avoid directly running against the forest API in testing. Instead would suggest to either:
- mock out the qvm connection (an example using patch is in
test_param_prog_p1_barbell
of the file/grove/pyqaoa/tests/test_maxcut.py
, or - test your inverse function against the program that is generated to ensure correctness there
Unfortunately it does mean that there isn't any easy way to test the invariant that this and the qft are actually inverses of each other, but right now we want to keep the tests modular so that people without keys can still run tests successfully.
Other suggestions for the testing welcome @tarballs-are-good @ncrubin
Hey Aaron, Thanks for the contribution. We can further modularize to reduce the repeated New methods would be:
To simplify the inverse operation you could have As an example:
|
Another way this could be cleaned up is with a modification to the |
I like this suggestion that .pop() return the instruction and have added it as an issue to the pyquil repo |
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.
Looks good @vontell Just a final few very minor changes and then LGTM!
############################################################################## | ||
|
||
from pyquil.gates import X | ||
from grove.qft.fourier import * |
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.
This * is saving you a little bit as you need to import more than just the X gate. I'd recommend the following change to make it clear where the imports are coming from:
from pyquil.gates import *
from grove.qft.fourier import inverse_qft
import pyquil.quil as pq
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.
Its really nitpicky to list out all the gates, but you could do that too if you prefer
H(1), CPHASE(-1.5707963267948966, 1, 2), | ||
H(2)]) | ||
print(trial_prog) | ||
print(result_prog) |
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.
couple leftover print statements to remove
@@ -0,0 +1,50 @@ | |||
############################################################################## | |||
# | |||
# A collection of tests for the inverse quantum Fourier transform. |
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.
you can count this as a start of a test_qft.py
so that we can add more tests to it rather than needing its own module for testing the inverse qft function
# | ||
# A collection of tests for the inverse quantum Fourier transform. | ||
# | ||
# Written by Aaron Vontell on January 28th, 2017 |
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.
Our policy is to just copy the standard header that is all of the other files. This means that we don't track authorship in source, but you will get to live in infamy here! https://github.com/rigetticomputing/grove/graphs/contributors
Nice! |
I was looking to easily add the inverse QFT to an instruction set, but saw that it was not implemented. Since (I believe, there is surprisingly little literature on the inverse implementation) it is simply the QFT in reverse (with negative angles), I have added it as another method in the
fourier.py
file. I also added a simple test which takes a bit string, applies the QFT followed by the inverse QFT, and verifies that the final result equals the initial result, but note that this relies on the correctness of the QFT (which does not have tests yet as far as I can see).