-
Notifications
You must be signed in to change notification settings - Fork 21
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
AttributeError: 'ArrayLiteral' object has no attribute 'value'. #240
Comments
Hi, thanks for raising! As per the OpenQASM spec here, the qubit register size must be a compile-time constant (an integer literal or I notice in your example the qubit register size is specified with a string literal, which is not defined syntax. An action item here would be to improve our error handling here to make the problem more clear to users. |
I agree that this is an unusual (perhaps unrealistic) use case, but interestingly the grammar defines a Anyway, just thought I'd mention it as the error message was not as helpful as they were in other places. |
Good point. This bug can be fixed by casting the node size into an integer with before accessing
|
I have a bunch of other ones that are invalid according to the spec, but produce similar error messages that could be improved by handling the exception and outputting more context such as the line number or token. For example:
produces this:
Are these useful to you? Perhaps I could drop them into another issue and mark it as an enhancement. |
It looks like that example is the same failure mode of a BitString not having a |
True, once you have a PR I can retest them and let you know if that gets them all. |
Hi @ajberdy! I would like to fix this issue. Could you please assign me? |
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
@DanBlackwell There is now a proposed PR #258 to fix this issue. If you have any feedback on that, it would be very welcome. |
@rmshaffer thanks for informing me, I've dropped a comment on the PR. It looks like it fixes the errors that were mentioned in this issue. I believe I have some others that it might not fix, so I'll drop minimal QASM examples down below (note that I don't think these are valid programs according to the QASM spec, just that the error message could be improved): 1
gives:
2
gives (I believe due to the $17):
3
gives:
4
gives:
5
gives:
|
I believe that #258 does fix this particular issue though; the above |
Thanks @DanBlackwell! This is very helpful feedback and I agree with your assessment. |
fwiw, I did make a start at producing error messages with line number and position (instead of just |
Also, I did try tagging a question onto the end of another issue with the Qiskit team here to clarify this Qiskit/qiskit#12167 (comment); but I guess no one saw it. From that thread it seemed like levbishop was the most knowledgable about casting. |
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
…ibute 'value'. Fixes bug [amazon-braket#240] by casting node.size into IntegerLiteral
Fixes bug [#240] by casting node.size into IntegerLiteral
@EuGig, thank you for your contribution in #258! I have merged this PR into a feature branch, and we will be close this issue for now (to ensure that you get credit for this in unitaryHACK). I have opened #263 to track getting the changes merged to @EuGig, would you please reply to this comment confirming that you would like this issue to be assigned to you? (GitHub requires that you comment on an issue before it can be assigned to you.) |
@rmshaffer I confirm I would like this issue to be assigned to me! |
Describe the bug
In general the openQASM parsing errors are well handled in Braket. There are some cases where it is assumed that an object will have a
.value
and the exception is not caught. These are from auto-generated programs, so might not be an issue in practice; but perhaps the error message could be improved to include context if the exception was caught.I'm not sure that this is really a bug, so please let me know if not and I will delete the issue. The example I include here is for
ArrayLiteral
s, but there are a whole family of related errors I have triggered.To reproduce
Expected behavior
Either return an error message indicating that bitstrings are not allowed for declaring register sizes, or parse the bitstring into a numeric constant (2) and create an array with that size.
Screenshots or logs
System information
A description of your system. Please provide:
Additional context
N/A
The text was updated successfully, but these errors were encountered: