I have written the following toy .qasm file, which has some adaptive measurements:
OPENQASM 2.0;
include "qelib1.inc";
qreg q_1[2];
qreg q_aux[2];
creg c_1[2];
creg c_aux[2];
h q_1[0];
cx q_1[0],q_aux[0];
measure q_aux[0] -> c_aux[0];
if(c_aux[0]==1) s q_1[0];
h q_1[0];
cx q_1[0],q_1[1];
cx q_1[1],q_aux[1];
measure q_aux[1] -> c_aux[1];
if(c_aux[1]==1) s q_1[1];
measure q_1[0] -> c_1[1];
The if
statement is using the formatting that you can find in page 20 of https://arxiv.org/abs/2104.14722 :
The problem is that when I try importing this into Qiskit, I get an error:
So it looks like Qiskit is not liking the notation with the square brackets.
I have done some tests and have noticed that if I replace the if statements by something of the sort of:
if(c_aux0==1) s q_1[0];
...
if(c_aux1==1) s q_1[1];
then I wouldn't have an error. However, in general, this requires that I replace a single n-bit classical register, by n single-bit classical registers which I don't particularly like.
Does anyone know why the QasmError
is happening? (Recall that my original code appears to be valid, according to https://arxiv.org/abs/2104.14722 .)
Thank you in advance!
sorry everyone this is my first experience with StackExchange and I think I've messed up and made the question as an unregistered user and so I can't seem to be able to change it properly. So I am using this answer to try to add some info (I know this is not how it is supposed to go, I apologize).
@luciano: thank you for your answer, but while the arxiv document is for OpenQASM 3 as you point out, the little snippet of code I took is (in theory) for OpenQASM 2. At least the top of page 20 (right before the code) states:
"As an example, consider an inverse quantum Fourier transform circuit as written in OpenQASM 2". So I think that this should work even for OpenQASM 2.0. But when I do:
qc1 = QuantumCircuit.from_qasm_file(f'{file_loc}{file_name}.qasm')
I get the error that I mentioned. That's what has me confused.
[Edit made by karatechop, copy pasted from answer that was meant to be edit to the question.]