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

AutoQASM program transpilation should mangle OpenQASM reserved keywords (if they're not Python keywords) #12

Closed
rmshaffer opened this issue May 8, 2024 · 6 comments · Fixed by #28
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@rmshaffer
Copy link
Contributor

rmshaffer commented May 8, 2024

Summary

In AutoQASM programs, Python symbol names which are reserved words in OpenQASM result in syntax errors in the serialized OpenQASM program. For example, a variable named input could be transpiled to input_ to avoid this problem.

Repro Steps

To reproduce the bug:

@aq.subroutine
def make_input_state(input: int, theta: float):
    rx(input, theta)

@aq.main(num_qubits=3)
def teleportation(theta):
    input, alice, bob = 0, 1, 2
    make_input_state(input, theta)
    c = measure(bob)

sim = LocalSimulator()
task = sim.run(teleportation, inputs={"theta": math.pi/2}, shots=100)

Expected Result

This should build and run the program successfully.

Actual Result

This fails because input is a reserved OpenQASM keyword, and so the generated OpenQASM program results in a syntax error.

@rmshaffer rmshaffer converted this from a draft issue May 8, 2024
@rmshaffer rmshaffer added the bug Something isn't working label May 8, 2024
@rmshaffer rmshaffer changed the title Bug: Mangle OpenQASM reserved keywords (if they're not Python keywords) Transpilation should mangle OpenQASM reserved keywords (if they're not Python keywords) May 8, 2024
@rmshaffer rmshaffer changed the title Transpilation should mangle OpenQASM reserved keywords (if they're not Python keywords) AutoQASM program transpilation should mangle OpenQASM reserved keywords (if they're not Python keywords) May 9, 2024
@rmshaffer rmshaffer added the good first issue Good for newcomers label May 14, 2024
@atharva-satpute
Copy link
Contributor

atharva-satpute commented Jun 7, 2024

I would like work on this issue as part of unitary hack.

With my local changes, test test_multi_bind_parameters (and few others) are failing. But usually this test works fine. qubit variable declared in this function is not causing any problems. Or is this issue valid only when using simulators?

@rmshaffer
Copy link
Contributor Author

@atharva-satpute can you share your local changes, for example, by pushing them to a branch or opening a draft PR? A draft PR would be best, since then we can trigger GitHub to run the unit tests and see the error messages.

The simulator is used in the issue description because currently the OpenQASM syntax is only validated by the simulator - there is not currently any syntax validation during the AutoQASM serialization process itself.

@atharva-satpute
Copy link
Contributor

@rmshaffer, I have opened a draft PR

@atharva-satpute
Copy link
Contributor

@rmshaffer, could you take a look at the comments

@rmshaffer
Copy link
Contributor Author

Sure - replied to your comment in the PR #28. Feel free to push a new revision to that PR whenever you're ready!

@atharva-satpute
Copy link
Contributor

I have added the changes. Let me know if any keywords are missing or if the list needs to be somewhere else. Thanks!

@rmshaffer rmshaffer linked a pull request Jun 12, 2024 that will close this issue
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

2 participants