Describe the bug
- Using the qasm3 exporter fails if the circuit contains a
XSlowGate.
- QPY doesn't preserve the
XSlowGate subclass. A circuit saved with XSlowGate comes back with a plain Gate named "xslow" after qpy.load.
Steps to reproduce
from qiskit import QuantumCircuit, qasm3
from qiskit_ibm_runtime.circuit.library import XSlowGate
qc = QuantumCircuit(1, 1)
qc.append(XSlowGate(), [0])
qc.measure(0, 0)
qasm3.dumps(qc)
Fails with:
qiskit.qasm3.exceptions.QASM3ExporterError: "failed to export gate 'xslow' that has no definition"
Also this shows the XSlowGate class is lost at QPY serialization:
import io
from qiskit import QuantumCircuit, qasm3, qpy
from qiskit_ibm_runtime.circuit.library import XSlowGate
qc = QuantumCircuit(1, 1)
qc.append(XSlowGate(), [0])
qc.measure(0, 0)
buf = io.BytesIO()
qpy.dump(qc, buf)
buf.seek(0)
qc2 = qpy.load(buf)[0]
op = qc2.data[0].operation
print(type(op).__name__, op.definition) # -> Gate None
Expected behavior
QASM3 export works.
Suggested solutions
- Add a placeholder body in
XSlowGate.__init__:
class XSlowGate(Gate):
def __init__(self) -> None:
super().__init__("xslow", 1, [])
self.definition = QuantumCircuit(1) # empty placeholder body
- I believe QPY has no registration mechanism for third-party Gate subclasses; so maybe just documentation/caveat note in XSlowGate's docstring
Additional Information
- qiskit-ibm-runtime version:
- Python version:
- Operating system:
Describe the bug
XSlowGate.XSlowGatesubclass. A circuit saved withXSlowGatecomes back with a plainGatenamed "xslow" afterqpy.load.Steps to reproduce
Fails with:
Also this shows the XSlowGate class is lost at QPY serialization:
Expected behavior
QASM3 export works.
Suggested solutions
XSlowGate.__init__:Additional Information