Open weucode opened 2 years ago
Sorry for the slow reply! This is very related to #7351 and the reasons in https://github.com/Qiskit/qiskit-terra/issues/7750#issuecomment-1062405591. The gist is that initialize
is a non-unitary instruction (it includes a reset
), and so we can't actually write it as a valid OpenQASM 2 gate
. It's a bug that the exporter here puts a reset
instruction within a gate - it should probably just fail at that point.
There won't be a way to round-trip a circuit with initialize
in it from QASM 2 even if we do some tricks in the export, because the language just can't represent that instruction without it being inlined into the circuit, sorry. We could do some tricks with the (unitary) StatePreparation
class, but extending the OpenQASM 2 support is a low priority for us right now, sorry.
Hey, @jakelishman, I too am facing the same issue while converting a pennylane circuit to qasm. What do you think, in the circuit, is causing this error to prop up? And what is the probable timeline for this bug to be resolved?
Environment
What is happening?
After got the OpenQASM code about
initialize
operator, it will fail to usefrom_qasm_file/from_qasm_str
to translate it back into qiskit code. Part of error message is shown below:How can we reproduce the issue?
from qiskit import QuantumCircuit
circuit = QuantumCircuit(1) circuit.initialize('0', circuit.qubits) qasm_str = circuit.qasm() print(qasm_str) same_circuit = QuantumCircuit(1) same_circuit = same_circuit.from_qasm_str(qasm_str) print(same_circuit)
What should happen?
Run successfully.
Any suggestions?
No response