qiskit icon indicating copy to clipboard operation
qiskit copied to clipboard

qc.delay() crashes qc.qasm()

Open balewski opened this issue 2 years ago • 2 comments

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 print(circ.qasm() ) File "/home/balewski/.local/lib/python3.9/site-packages/qiskit/circuit/quantumcircuit.py", line 1666, in qasm _add_sub_instruction_to_existing_composite_circuits( File "/home/balewski/.local/lib/python3.9/site-packages/qiskit/circuit/quantumcircuit.py", line 4698, in _add_sub_instruction_to_existing_composite_circuits for sub_instruction, _, _ in instruction.definition: TypeError: 'NoneType' object is not iterable

What is the expected behavior?

I should see qasm output

Suggested solutions

balewski avatar Jun 19 '22 04:06 balewski

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.

jakelishman avatar Jun 20 '22 19:06 jakelishman

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?

pat-phattharaporn avatar Aug 11 '22 22:08 pat-phattharaporn

We don't have an importer for Qiskit from OpenQASM 3 yet, but it is on our radar as a feature to add.

jakelishman avatar Aug 17 '22 13:08 jakelishman

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.

jakelishman avatar Jan 02 '24 12:01 jakelishman