1
$\begingroup$

I am trying to get my first openqasm3.0 program and I am getting error messages that I cannot interpret.

Here is my program:

cloner1 = """
OPENQASM 3.0;
//include "qelib1.inc";
qubit[5] q;
bit[1] c;
x q[2];
x q[4];

x q[0]; //Set up input
measure q[0] -> c[0];
if (c[0]==1) {
    CX q[1],q[2];
    CX q[2],q[1];
    CX q[1],q[2];
    CX q[3],q[4];
    CX q[4],q[3];
    CX q[3],q[4];
    }
measure q[1]->c[0];
measure q[3]->c[0];
"""

qc= QuantumCircuit.from_qasm_str(cloner1)
result = execute(qc, backend=qiskit.BasicAer.get_backend('qasm_simulator'),shots=1024).result()
counts = result.get_counts()
plot_histogram(counts)

THe error message I get is Error near line 4 Column 7 Expected an ID, received '['"

Apparently it doesn't like bit[1] c. But this is just like the code in the arxiv.org article

So I don't know what is wrong. It doesn't seem to be interpreting it as ASM3.0 code.

$\endgroup$
0
$\begingroup$

OpenQASM 3.0 is still in pre-release: https://github.com/Qiskit/openqasm/releases

I believe your observation is correct - your code is not interpreted as OpenQASM 3.0. Another test: the first example from Github starts with OPENQASM 3; (not 3.0.) Even trying this now I get

QasmError: Unable to match any token rule, got -->O<-- Check your OPENQASM source and any include statements.

hence I am confident Qiskit tries to run it as 2.0 when it does not recognize version. I have opened this issue on GitHub requesting that QASM throws an error if an unavailable version is requested.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.