-
Notifications
You must be signed in to change notification settings - Fork 7
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
Some cases of wrong QASM code return empty exception #24
Comments
pytest format: import pytest
from qiskit.qasm3 import loads
test_cases = [
('OPENQASM 3.0; include "stdgates.inc";', False),
('OPENQASM 3.0;include "stdgates.inc";qubit[2] q;h q[0];cx q[0], q[1];', False),
("INVALID QASM STRING", True),
("kjkasdhgfjkgh", True),
("const int size = 4;", True),
("int size = 4;", True),
("float[64] ang = pi/2;", True),
# Add more test cases here...
]
@pytest.mark.parametrize("input_string,should_error", test_cases)
def test_loads(input_string, should_error):
if should_error:
with pytest.raises(Exception):
loads(input_string)
else:
try:
loads(input_string)
except Exception:
pytest.fail(
f"loads() raised Exception unexpectedly for input: {input_string}"
) |
The times you're seeing an empty message are when the underlying ANTLR parser is failing, and the cases that have messages are when the conversion to Qiskit that is actually part of this package is throwing the exception. We can potentially put a generic message in the case that ANTLR fails, but largely this package is a fairly thin wrapper around the reference parser at github.com/openqasm/openqasm, so there's a limited amount we can do from here. |
Thank you for your reply. From my perspective exception should always contain information what happen, even if it's only something generic that hint us where to search for exception source. |
I agree with you - this is actually one of the reasons we're moving away from this thin wrapper package to replace it with a more in-house OpenQASM 3 parser: so we can provide better error messages (see #13). The ANTLR-based parser isn't entirely within our control, and even if it were, ANTLR's Python runtime doesn't offer the best developer tooling for writing good diagnostics and improving the failure paths. |
In some cases when providing wrong QASM code exceptions are empty
python --version
Python 3.10.12
[tool.poetry.dependencies]
qiskit-qasm3-import = "^0.4.1"
Tests example:
Output:
INVALID QASM STRING
exception is emptykjkasdhgfjkgh
) exception is empty but additionally there is line printed that is not included in exception:line 1:13 no viable alternative at input 'kjkasdhgfjkgh'
The text was updated successfully, but these errors were encountered: