-
Notifications
You must be signed in to change notification settings - Fork 340
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 rewrite_arithmetic handler #1210
Conversation
7cbaf9d
to
94662cf
Compare
bb13f39
to
cd4a332
Compare
@@ -8,6 +8,9 @@ Changelog | |||
|
|||
### Improvements and Changes | |||
|
|||
- Added a PyQuil only `rewrite_arithmetic` handler, deprecating the previous |
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.
don't h8, hyphenate
pyquil-only
pyquil/tests/test_api.py
Outdated
assert ( | ||
response.quil | ||
== Program( | ||
"DECLARE __P2 REAL[2]", | ||
"DECLARE theta REAL[1]", | ||
"DECLARE beta REAL[1]", | ||
"RZ(__P2[0]) 0", | ||
"RZ(__P2[1]) 0", | ||
).out() | ||
) |
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.
lol
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 don't make the rules!
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! On a longer horizon (for the general SDK) we may want this to live in libquil
, but for the time being it's good to reduce complexity by replacing this call to quilc
.
pyquil/tests/test_api.py
Outdated
@@ -343,3 +350,62 @@ def test_local_conjugate_request(benchmarker): | |||
def test_apply_clifford_to_pauli(benchmarker): | |||
response = benchmarker.apply_clifford_to_pauli(Program("H 0"), PauliTerm("I", 0, 0.34)) | |||
assert response == PauliTerm("I", 0, 0.34) | |||
|
|||
|
|||
def test_rewrite_arithmetic_no_params(): |
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.
Do you think these could live in api/test_rewrite_arithmetic.py
?
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.
Good call.
Description
When compiling native quil programs, the first step is to do "arithmetic rewriting", which turns compound gate parameters into simple memory references. The motivation for this is that the underlying hardware can do a certain amount of arithmetic, but not everything (multiplication and division are done via arithmetic shifts, and so are restricted to powers of two, also real arithmetic is done with fixed point numbers which results in a loss of precision, and so on).
This arithmetic rewriting is actually quite simple, but presently requires a call to the quilc client. This is a bit annoying, as
native_quil_to_executable
does not otherwise need quilc, and in my personal experience this dependency can be a bit burdensome when developing/testingnative_quil_to_executable
functionality. This PR deprecates this call with a simple and explicitrewrite_arithmetic
function.In the long term we will need to reconsider entirely this approach (if we are to allow for run-time updates to parameter values), but for now this is how things are.
Checklist
flake8
conventions.