-
Notifications
You must be signed in to change notification settings - Fork 121
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
fix: iterative variable assignments in AutoQASM #930
fix: iterative variable assignments in AutoQASM #930
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## feature/autoqasm #930 +/- ##
==================================================
Coverage 100.00% 100.00%
==================================================
Files 170 170
Lines 10495 10502 +7
Branches 2248 2249 +1
==================================================
+ Hits 10495 10502 +7 ☔ View full report in Codecov by Sentry. |
@@ -25,6 +25,7 @@ | |||
|
|||
import oqpy.base | |||
import pygments | |||
from openpulse import ast |
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.
Why openpulse?
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 a superset of openqasm3 ast - openpulse just imports and re-exports the entire openqasm3 ast.
https://github.com/openqasm/openpulse-python/blob/b3a4ae3faf855527936130245ea2d7620d199f2a/source/openpulse/openpulse/ast.py#L17-L19
In our codebase we just tend to import openpulse ast everywhere. Probably not strictly needed here.
target.init_expression = value.init_expression | ||
oqpy_program.declare(target) | ||
target.init_expression = value_init_expression | ||
oqpy_program._add_var(target) |
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 think this breaks some use cases. For example:
@aq.main(num_qubits=2)
def bell_state():
a = aq.IntVar(5) # noqa: F841
b = a
a = aq.IntVar(1) # noqa: F841
c = a # noqa: F841
builds
OPENQASM 3.0;
int[32] a = 1;
int[32] b;
int[32] c;
qubit[2] __qubits__;
b = a;
c = a;
but b
should be 5 not 1.
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 catch! Thanks, I'll follow up on this and get it fixed.
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 being addressed in #938
Issue #, if available:
#929, #933
Description of changes:
Ensure that AutoQASM variables which are updated after declaration, including iteratively in a loop, are initialized properly.
Testing done:
Added tests for new cases. Updated existing tests where variable declaration order changed.
tox
passes.Note:
If a variable is initialized with a Python variable and then updated iteratively in a loop, this scenario still does not work with the changes in this PR. A new issue has been added to the backlog for this: https://github.com/orgs/amazon-braket/projects/2/views/1?pane=issue&itemId=58435320.
Merge Checklist
Put an
x
in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your pull request.General
Tests
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.