-
Notifications
You must be signed in to change notification settings - Fork 9
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: mangle OpenQASM keywords #28
fix: mangle OpenQASM keywords #28
Conversation
@atharva-satpute The unit test failures you're seeing (failures here) are actually a great thing - these were tests that were using variable names like |
1dd7e86
to
fd2b8bd
Compare
d39dcd3
to
30e1290
Compare
1. Fixed few existing test cases that got affected due to this change 2. Added reserved keyword list
30e1290
to
54ff709
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #28 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 46 47 +1
Lines 2043 2057 +14
Branches 342 343 +1
=========================================
+ Hits 2043 2057 +14 ☔ View full report in Codecov by Sentry. |
src/autoqasm/api.py
Outdated
@@ -35,6 +35,63 @@ | |||
from autoqasm.program.gate_calibrations import GateCalibration | |||
from autoqasm.types import QubitIdentifierType as Qubit | |||
|
|||
reserved_keywords = [ |
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.
Do you have a reference/link to the source of this list?
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.
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.
Could you please include a permalink reference as a comment in the code here? Perhaps you can use this URL: https://github.com/openqasm/openqasm/blob/909379e450f5e1b6cdd67b8a96683caca7b13e4d/source/grammar/qasm3Lexer.g4
Also, it would be ideal to move this list (and the function is_reserved_keyword
) to a separate file (e.g. reserved_keywords.py) and then just import the function is_reserved_keyword
here.
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.
Thanks, I think in long term, it would be better that this list is not hard-coded. Rather, the list depends on the qasm3lexer from the lexer file. But I think it does not necessary need to be implement in this PR. Could you add the reference link as an inline comment?
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.
Thanks, I think in long term, it would be better that this list is not hard-coded. Rather, the list depends on the qasm3lexer from the lexer file. But I think it does not necessary need to be implement in this PR. Could you add the reference link as an inline comment?
Yes, initially, I had done it that way.
src/autoqasm/api.py
Outdated
@@ -35,6 +35,63 @@ | |||
from autoqasm.program.gate_calibrations import GateCalibration | |||
from autoqasm.types import QubitIdentifierType as Qubit | |||
|
|||
reserved_keywords = [ |
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.
Could you please include a permalink reference as a comment in the code here? Perhaps you can use this URL: https://github.com/openqasm/openqasm/blob/909379e450f5e1b6cdd67b8a96683caca7b13e4d/source/grammar/qasm3Lexer.g4
Also, it would be ideal to move this list (and the function is_reserved_keyword
) to a separate file (e.g. reserved_keywords.py) and then just import the function is_reserved_keyword
here.
1. Created a new file for the reserved keywords
e9debfc
to
3d477b0
Compare
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.
A few very minor suggestions, but otherwise this looks good to me! Thank you for sticking with this!
19c69f8
to
7cdc39d
Compare
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.
🥳
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.
LGTM. Just wondering if we can improve one error message to avoid confusion since we modify variable name in the background.
269ddc9
to
beb4801
Compare
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.
LGTM, thanks a lot for your contribution.
Co-authored-by: Lauren Capelluto <[email protected]>
|
Thank you for all the work on this! 🥳 |
Issue #12
Description of changes:
OpenQASM reserved keywords names will be mangled to
<keyword>_
Testing done: Yes
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.