Skip to content

xslow (via XSlowGate) can't be exported to QASM3 and is lost when exported as QPY #3311

Description

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:

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions