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

fix: iterative variable assignments in AutoQASM #930

Merged
merged 3 commits into from
Apr 2, 2024

Conversation

rmshaffer
Copy link
Contributor

@rmshaffer rmshaffer commented Mar 29, 2024

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

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have checked that my tests are not configured for a specific region or account (if appropriate)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@rmshaffer rmshaffer linked an issue Mar 29, 2024 that may be closed by this pull request
@rmshaffer rmshaffer self-assigned this Mar 29, 2024
Copy link

codecov bot commented Mar 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (61ae9dd) to head (8fb3359).

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.
📢 Have feedback on the report? Share it here.

@rmshaffer rmshaffer marked this pull request as ready for review April 2, 2024 18:33
@rmshaffer rmshaffer requested a review from a team as a code owner April 2, 2024 18:33
@@ -25,6 +25,7 @@

import oqpy.base
import pygments
from openpulse import ast
Copy link
Contributor

Choose a reason for hiding this comment

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

Why openpulse?

Copy link
Contributor Author

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.

@rmshaffer rmshaffer merged commit 790ede5 into feature/autoqasm Apr 2, 2024
23 checks passed
@rmshaffer rmshaffer deleted the rmshaffer/autoqasm-iterative-assignment branch April 2, 2024 20:39
target.init_expression = value.init_expression
oqpy_program.declare(target)
target.init_expression = value_init_expression
oqpy_program._add_var(target)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants