Qiskit / qiskit

Qiskit is an open-source SDK for working with quantum computers at the level of extended quantum circuits, operators, and primitives.
https://www.ibm.com/quantum/qiskit
Apache License 2.0
5.05k stars 2.33k forks source link

Qasm3 loader fails on feed-forward circuit #11474

Open balewski opened 8 months ago

balewski commented 8 months ago

Environment

Python 3.10.12 openqasm3 0.5.0 qiskit-qasm3-import 0.4.1 pytket-qiskit 0.46.0 qiskit 0.45.1 qiskit-aer 0.13.1 qiskit-algorithms 0.2.1 qiskit-dynamics 0.4.2 qiskit-experiments 0.5.4 qiskit-ibm-experiment 0.3.5 qiskit-ibm-provider 0.7.2 qiskit-ibm-runtime 0.17.0 qiskit-terra 0.45.1

What is happening?

The exporting and importing of Qasm3 uses different Qasm3 version/convention:

qasmInst=qiskit.qasm3.dumps(qcT)
 qc3=qiskit.qasm3.loads( qasmInst)

This is the Qasm3 circuit I want to parse with qiskit.qasm3.loads(.)

OPENQASM 3;
include "stdgates.inc";
bit[5] c0;
rz(pi/2) $13;
sx $13;
rz(pi/2) $13;
cx $13, $14;
cx $13, $12;
barrier $13, $14, $12, $0;
c0[0] = measure $13;
c0[1] = measure $14;
c0[2] = measure $12;
barrier $13, $14, $12, $0;
if (c0[0] & c0[1] | c0[0] & c0[2] | c0[1] & c0[2]) {
  x $0;
}
c0[3] = measure $0;

The error is:

File "/usr/local/lib/python3.10/dist-packages/qiskit_qasm3_import/exceptions.py", line 20, in raise_from_node
    raise ConversionError(message, node)
qiskit_qasm3_import.exceptions.ConversionError: 14,4: unhandled binary operator '|'

How can we reproduce the issue?

Attached code demonstrates I can save a transpiled circuit with feed-forward operations as Qasm3, but I can't read it back. https://bitbucket.org/balewski/quantummind/src/master/Qiskit/issues/issue27_qasm3_IO.py

What should happen?

I should get back the original circuit

Any suggestions?

jakelishman commented 8 months ago

The extended binary-operation conditions aren't currently supported in the OpenQASM 3 import; we just haven't added that capability to the converter yet, because we're in the process of completely rewriting it to switch to a more performant and easier to extend parser. This feature is very much on our roadmap, it's just likely a few months away, since it's taking a backseat right now in favour of changing the foundations of OQ3 import.

For the second issue: it's hard to know exactly what you mean without a reproducible example. If you would like to open a second issue about that, please do.

balewski commented 8 months ago

thanks for the explanation. How should I export a feed-forward circuit constructed in Qiskit to other frameworks, like TKet or cuQuantum? Until this issue using QASM allowed the convenient conversion of circuit.

I have filed new ticket #11480 with regard of lost qubit IDs

jakelishman commented 8 months ago

Well, the export still works, it's just our import that doesn't at the moment. I wasn't aware that tket had any support for the dynamic-circuits features of OpenQASM 3 yet (the circuit-runtime operations on classical data in your condition), so I'm not sure if they'd be able to import OpenQASM 3 themselves, but if they've added it recently, then the import should work. I'm not very familiar with cuQuantum's offerings, but I believe they have a functional OpenQASM 3 converter to other formats, which I assume contains themselves.