Qiskit / qiskit-qasm3-import

Importer from OpenQASM 3 to Qiskit's QuantumCircuit
https://qiskit.github.io/qiskit-qasm3-import
Apache License 2.0
15 stars 7 forks source link

'type error' when using QASM3 converter #6

Closed ArfatSalman closed 1 year ago

ArfatSalman commented 1 year ago

Environment

What is happening?

Exporting and importing the same circuit in QASM3 throws '6,7: type error'.

How can we reproduce the issue?

from qiskit import transpile
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister
from qiskit.circuit.library.standard_gates import *

qr = QuantumRegister(3, name="qr")
cr = ClassicalRegister(3, name="cr")

qc = QuantumCircuit(qr, cr, name="qc")
qc.append(XGate(), qargs=[qr[2]], cargs=[])
qc.append(SGate(), qargs=[qr[2]], cargs=[])

qc.measure(qr, cr)

qc = transpile(qc) # if this line is commented out, there's no error then

from qiskit.qasm3 import loads, dumps

qc = loads(dumps(qc))
# qiskit_qasm3_import.exceptions.ConversionError: 6,7: type error
# qiskit.qasm3.exceptions.QASM3ImporterError: '6,7: type error'

What should happen?

Using QASM2 round-trip (qc.from_qasm_str(qc.qasm())) works for the above circuit. I was expecting the QASM3 roundtrip to work as well.

Any suggestions?

No response

jakelishman commented 1 year ago

Thanks - this is a bug in the implicit-cast typing resolution of the importer; it's missing a rule to unify int * float, which is what's needed here.