-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Reject other QASM versions in QASM 2 parser #7456
Conversation
Other numerical will now result in error from parser.
Its effectively blocked by #7457 |
c844ac5
to
950c148
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.
Thanks for looking at this!
If we're making more programmes fail, we should make sure that our error messages are particularly clear - in this case, it'd be good if we can ensure that the error tells us that only parsing of QASM 2 is currently supported, if we encounter a bad OPENQASM
statement. At the moment, the error is:
QasmError: 'Unable to match any token rule, got -->O<-- Check your OPENQASM source and any include statements.'
which isn't super helpful.
Makes sense, thanks! Will try to look late today or early tomorrow |
Lexer accepts any structurally proper version string, parser fails if it is other than 2.0. Added tests and updated docs.
…akuya/fix-openqasm-319
…akuya/fix-openqasm-319
…akuya/fix-openqasm-319
@jakelishman any chance for some quick eyes 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.
Sorry this took so long for me to look at again. The errors look much better now, in most of the situations, I just had one little tweak for a new situation that OpenQASM 3 allows, but OpenQASM 2 doesn't, that'll improve them a little more too.
We're good to go on this after that.
Pull Request Test Coverage Report for Build 1714209317
💛 - Coveralls |
Co-authored-by: Jake Lishman <jake@binhbar.com>
Version 2; should succeed, as the lexer will accept single-digit versions. Parser adds default version 0. OPENQASM 2; or OPENQASM 2.0; both succeed, else fail.
@@ -0,0 +1,11 @@ | |||
OPENQASM 2; |
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.
The fact that OPENQASM 2;
works now is kind of a side-effect - it'd be best for the good test file to use 2.0
.
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.
For this one we have a few tests that run with 2.0 and I wanted to keep at least one that shows that indeed a single-digit version will work
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.
That's a good idea, let's leave it as it is.
@@ -0,0 +1,11 @@ | |||
OPENQASM 5.0; |
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.
You already test OPENQASM 3;
so this isn't testing anything new; a good other test would be that minor versions of 2
are also detected, such as OPENQASM 2.1;
- this would have caught the error with has_minor_version
above, because the file would have parsed successfully when it should have thrown an error.
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.
Eh you got more work than help with my contribution here, sorry for rookie mistakes! Working on it
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.
Don't worry about it - it's not really true anyway. Before you made the PR, I didn't know how hard or easy it would be to fix. After you'd made it, all I had to do was check that what you'd done was sensible, not actually go through and do it myself, and you did this well.
Finding extra special test cases, catching weirdnesses with re
and things like that is just more experience, and it's why we have review anyway.
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.
Well I appreciate the encouragement and would continue to work on this anyways :D
Tests now fail with incorrect minor version. Tests of qasmparser cleaned up a bit.
f1da822
to
6696124
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.
I pushed up a couple of commits just to simplify the creation of some strings, and fix a typo in the test case (which was probably my fault anyway). This is good to merge now, and it's stable for backport, so we'll put it out in Terra 0.19.2 whenever we get around to releasing that 🎉
* Explicitly specifying QASM version 2.0 in lexer. Other numerical will now result in error from parser. * adding release note. * Moving QASM version check to parser. Lexer accepts any structurally proper version string, parser fails if it is other than 2.0. Added tests and updated docs. * Fixing qasm version checking. * Fixing tab in docs * Update releasenotes/notes/qasm-lexer-bugfix-1779525b3738902c.yaml Co-authored-by: Jake Lishman <jake@binhbar.com> * Improved error message for invalid QASM version. * Adding ability to parse OPENQASM single-digit ver Version 2; should succeed, as the lexer will accept single-digit versions. Parser adds default version 0. OPENQASM 2; or OPENQASM 2.0; both succeed, else fail. * Linting and adding docstrings * Fixing QASM minor-version parsing & testing Tests now fail with incorrect minor version. Tests of qasmparser cleaned up a bit. * Convert string expressions to format strings * Remove unused test assertion * Fix typo in test case Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 2d8bb5c)
* Explicitly specifying QASM version 2.0 in lexer. Other numerical will now result in error from parser. * adding release note. * Moving QASM version check to parser. Lexer accepts any structurally proper version string, parser fails if it is other than 2.0. Added tests and updated docs. * Fixing qasm version checking. * Fixing tab in docs * Update releasenotes/notes/qasm-lexer-bugfix-1779525b3738902c.yaml Co-authored-by: Jake Lishman <jake@binhbar.com> * Improved error message for invalid QASM version. * Adding ability to parse OPENQASM single-digit ver Version 2; should succeed, as the lexer will accept single-digit versions. Parser adds default version 0. OPENQASM 2; or OPENQASM 2.0; both succeed, else fail. * Linting and adding docstrings * Fixing QASM minor-version parsing & testing Tests now fail with incorrect minor version. Tests of qasmparser cleaned up a bit. * Convert string expressions to format strings * Remove unused test assertion * Fix typo in test case Co-authored-by: Jake Lishman <jake@binhbar.com> Co-authored-by: Jake Lishman <jake.lishman@ibm.com> (cherry picked from commit 2d8bb5c) Co-authored-by: Kuba Pilch <6464505+3yakuya@users.noreply.github.com>
Summary
Fixing QASM-319, qasm parser will fail with appropriate error if invalid OPENQASM version is specified. Reno release note is added.
Details and comments
Small change in qasm lexer to only accept 2.0 as a version, rather than any digit.digit. The latter caused a bug where user could provide any version, like
3.0
and believe it works while in reality their code was still parsed as2.0
.Should not break any workflows, unless they rely on broken openqasm strings. Added reno release note. Did not see any place in the documentation per se that would require updating.