Closed kdk closed 1 year ago
We've run into this issue as well:
import qiskit
import qiskit_experiments.library.quantum_volume as qv
from qiskit.compiler import transpile
rand_circs = qv.QuantumVolume(qubits=[0,1,2]).circuits()
t_rand_circ = transpile(rand_circs[0], basis_gates=['u1','u2','u3','cx'])
print(t_rand_circ.qasm())
# prints
# OPENQASM 2.0;
# include "qelib1.inc";
# qreg q[2];
# creg measure[2];
# u3(0.95275496,-0.40048302,2.3396091) q[0];
# u3(1.4710132,1.4238801,-0.9022253) q[1];
# cx q[0],q[1];
# u3(0.7076726,-pi/2,-pi/2) q[0];
# u3(2.1567055,2.5482935,0.68681294) q[1];
# cx q[0],q[1];
# u3(0.28381753,-pi,pi/2) q[0];
# u3(1.0477967,0.64780817,-2.5581967) q[1];
# cx q[0],q[1];
# u3(1.4541338,-0.35391366,-1.7202243) q[0];
# u3(1.9771718,0.44431931,-0.27642371) q[1];
# barrier q[0],q[1];
# measure q[0] -> measure[0];
# measure q[1] -> measure[1];
qiskit.QuantumCircuit.from_qasm_str(t_rand_circ.qasm()) #raises qiskit.qasm.exceptions.QasmError: "Expected an ID, received 'measure'"
Thanks for bringing this up again. This one particular case should hopefully be able to be handled by a simple "escape name" type of function in the exporter, as opposed to the OpenQASM 3.0 exporter's symbol-table version. I'm happy to accept/help with PRs to fix this, though.
"escape name" type of function in the exporter
What's an "escape name"? Is it basically a way to tell the exporter to write _measure
(with underscore) instead of the existing measure
?
Yeah, essentially. We already do some of this, if a gate claims its name is something like BLAH!£%&
- that's not a valid OQ 2 identifier because of the leading capital letter and the symbols, so we "escape" it to gate_BLAH____
. That same function just needs a bit more logic to ensure it recognises that the OQ 2 reserved keywords are also invalid identifiers, and we need to apply it to registers as well as gates.
Fixed by #9100
Environment
What is happening?
https://github.com/Qiskit/qiskit-terra/issues/4023 found an issue that
QuantumCircuit.measure_all
creates aClassicalRegister
calledmeasure
, which is a reserved keyword in OpenQASM2+3. This was changed tomeas
formeasure_active
in #4079 , and addressed somewhat more generally for OpenQASM3 export in #7744 .How can we reproduce the issue?
raises
What should happen?
It would be good to:
measure_all
andmeasure_active
,ClassicalRegister
to be added,Any suggestions?
No response