-
Notifications
You must be signed in to change notification settings - Fork 118
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
Error when FreeParameters are named QASM types #603
Comments
For context, here is the OpenQASM generated when an input is named
|
The other variable names listed conflict with OpenQASM naming standards and we will update documentation to reflect this. |
Reopening this issue, as PR #675 was reverted by PR #701. Additionally, I think there is still a need to document the fact that OpenQASM language-reserved words (such as |
I don't see on #701 the reason for reverting. Anyone know what the issue was? |
I believe there was an issue with a particular OpenQASM parser not properly handling variable names beginning with |
Any progress on this issue? @kshitijc |
Hi @rmshaffer and @mbeach-aws , I would like to tackle this issue as part of unitary hack. |
Hi @rmshaffer and @mbeach-aws, I came up with two solutions, please let me know which I should proceed with. Solution 1
Solution 2
|
@Tarun-Kumar07 I believe we should do something more like your Solution 1, but only when FreeParameter matches one of the OpenQASM reserved words, or one of the SDK predefined variables like |
@rmshaffer, is it guaranteed that SDK would only have predefined variables |
I don't believe there would be any reason for the SDK to introduce new predefined variables beyond |
@rmshaffer , I will go with the solution where we are prefixing predefined variables and OpenQASM reserved words |
Hi @rmshaffer, I decided to output useful error messages instead of prefixing inputs because when specifying inputs in I made a list of reserved keywords from the OpenQASM grammar. I only included words like Currently, I expect the following code snippet to pass, but it unexpectedly breaks for four reserved keywords: QASM_RESERVED_WORDS = [
"OPENQASM", "include", "defcalgrammar", "def", "cal", "defcal", "gate", "extern",
"box", "let", "break", "continue", "if", "else", "end", "return", "for", "while",
"in", "pragma", "input", "output", "const", "readonly", "mutable", "qreg", "qubit",
"creg", "bool", "bit", "int", "uint", "float", "angle", "complex", "array", "void",
"duration", "stretch", "gphase", "inv", "pow", "ctrl", "negctrl", "dim", "durationof",
"delay", "reset", "measure", "barrier", "true", "false"
]
@pytest.mark.parametrize("param", QASM_RESERVED_WORDS)
def test_bug(param):
from braket.circuits import Circuit, FreeParameter
from braket.devices import LocalSimulator
b = FreeParameter(param)
circ = Circuit().rx(0, b)
print(circ)
with pytest.raises(Exception):
device = LocalSimulator()
task = device.run(circ, shots=1_000, inputs={param: 0})
task.result().measurement_counts Could you please help me understand why this is happening? |
Hi @Tarun-Kumar07 - could you please open a draft PR with your code so that we could more easily review your changes? I don't know what would cause those four keywords to be different than the others. When you say "it unexpectedly breaks", what does that mean? Do you get an error message of some kind? Once you open a PR, if you could please comment in the PR with those details, that would be the easiest way for us to help you out. Thank you for your investigation into this issue! |
Hi @rmshaffer, I've submitted PR #999 to address the issue. I would appreciate your feedback. |
Hi, can this issue be assigned to me after merging #999. |
@Tarun-Kumar07 PR #999 has been merged. Thank you for your contribution! |
Describe the bug
When a user defined a FreeParameter("str") where the "str" is a OpenQASM keyword. For example, it fails for
b
,q
,bit
,qubit
,input
,OPENQASM
,3.0
.1
,2
.To reproduce
gives the error
Expected behavior
Expected the circuit to run correctly. For example, using FreeParameter("a") works correctly.
The text was updated successfully, but these errors were encountered: