qiskit
qiskit copied to clipboard
qc.delay() crashes qc.qasm()
Informations
-
Qiskit version:
-
$ pip list | grep qiskit qiskit 0.36.2 qiskit-aer 0.10.4 qiskit-aqua 0.9.2 qiskit-experiments 0.3.1 qiskit-ibmq-provider 0.19.1 qiskit-ignis 0.7.1 qiskit-terra 0.20.2
-
Python version:
-
Python 3.9.2
-
Operating system: Ubuntu
What is the current behavior?
Adding qc.delay() to a circuit crashes qc.qasm() with the error: TypeError: 'NoneType' object is not iterable
Steps to reproduce the problem
execute this program: import qiskit as qk circ = qk.QuantumCircuit(3,3) circ.h(0) circ.cx(0, 1) circ.delay(400) circ.cx(0, 2) circ.barrier() circ.measure(0,0) print(circ) print(circ.qasm() )
The output is:
Traceback (most recent call last):
File "/home/balewski/quantumMind/Qiskit/issues/./isseu4_delay.py", line 17, in
What is the expected behavior?
I should see qasm output
Suggested solutions
The error message is unfortunately not very useful here, sorry, but the cause is that the delay
instruction isn't directly representable in OpenQASM 2 - there's no way to attach the timing information in the output.
Depending on what you're aiming for, you may be able to use the OpenQASM 3 exporter (do import qiskit.qasm3
, and then replace the last line with print(qiskit.qasm3.dumps(circ))
). OpenQASM 3 as a language is still in development, but it can represent these instructions natively.
After exporting qasm3 using qiskit.qasm3.dumps(circ)
, I'm wondering how to creating a quantum circuit from that qasm3 back into QuantumCircuit object? Or if it is possible?
We don't have an importer for Qiskit from OpenQASM 3 yet, but it is on our radar as a feature to add.
I'm going to close this issue now - #9953 made it so the given codeblock exports a delay
instruction as opaque
(which is imo a slightly controversial choice, but has long been Qiskit's position), and we do now have an OpenQASM 3 importer. Feel free to re-open if there's more to discuss.