qiskit-qasm3-import icon indicating copy to clipboard operation
qiskit-qasm3-import copied to clipboard

Some cases of wrong QASM code return empty exception

Open matrixik opened this issue 7 months ago • 4 comments

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:

from qiskit.qasm3 import loads

test_cases = [
    ('OPENQASM 3.0; include "stdgates.inc";'),
    ('OPENQASM 3.0;include "stdgates.inc";qubit[2] q;h q[0];cx q[0], q[1];'),
    ("INVALID QASM STRING"),
    ("kjkasdhgfjkgh"),
    ("const int size = 4;"),
    ("int size = 4;"),
    ("float[64] ang = pi/2;"),
    # Add more test cases here...
]

for test in test_cases:
    try:
        print(f"\nSuccessful case: {test}\nOutput:\n{loads(test)}\n")
    except Exception as e:
        print(f"Failed case: {test}, Exception: {e}")

Output:

 % python short_qiskit_tests.py

Successful case: OPENQASM 3.0; include "stdgates.inc";
Output:



Successful case: OPENQASM 3.0;include "stdgates.inc";qubit[2] q;h q[0];cx q[0], q[1];
Output:
     ┌───┐
q_0: ┤ H ├──■──
     └───┘┌─┴─┐
q_1: ─────┤ X ├
          └───┘

Failed case: INVALID QASM STRING, Exception:
line 1:13 no viable alternative at input 'kjkasdhgfjkgh'
Failed case: kjkasdhgfjkgh, Exception:
Failed case: const int size = 4;, Exception: '1,0: node of type ConstantDeclaration is not supported'
Failed case: int size = 4;, Exception: "1,0: declarations of type 'int' are not supported"
Failed case: float[64] ang = pi/2;, Exception: "1,0: declarations of type 'float' are not supported"
  • In case of INVALID QASM STRING exception is empty
  • In case of random string (like kjkasdhgfjkgh) exception is empty but additionally there is line printed that is not included in exception: line 1:13 no viable alternative at input 'kjkasdhgfjkgh'

matrixik avatar Nov 16 '23 16:11 matrixik