Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QASM export: custom gate definition ryy missing from generated QASM file #299

Open
MattePalte opened this issue Oct 29, 2024 · 0 comments
Open

Comments

@MattePalte
Copy link

Environment

  • pytket version: 1.33.1
  • qiskit version: 1.2.4
  • bqskit version: 1.2.0

Expected behavior
When creating a circuit with the ryy gate in Qiskit and exporting it to QASM with BQSKit, the generated QASM file should include a definition of the ryy gate.

Actual behavior
The generated QASM file does not include a definition of the ryy gate. When trying to read the generated QASM file with Qiskit or Pytket, an error is raised because the ryy gate is not defined.

Additional information
The ryy gate is not a standard gate and is not present in the qelib1.inc file. Thus, I would expect that the ryy gate is defined in the QASM file.

Source code

from bqskit.ext import qiskit_to_bqskit
from qiskit.qasm2 import dumps, loads
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister

qc = QuantumCircuit(2)
qc.ryy(0.1, 0, 1)

# Export with Qiskit
qasm = dumps(qc)
print("-"*4)
print("Exported by Qiskit")
print(qasm)

# Export with BQSKit
bqskit_circ = qiskit_to_bqskit(qc)
bqskit_circ.save("bqskit.qasm")
with open("bqskit.qasm", "r") as f:
    qasm_str_from_bqskit = f.read()
print("-"*4)
print("Exported by BQSKit")
print(qasm_str_from_bqskit)
# ----
# Exported by Qiskit
# OPENQASM 2.0;
# include "qelib1.inc";
# gate ryy(param0) q0,q1 { rx(pi/2) q0; rx(pi/2) q1; cx q0,q1; rz(param0) q1; cx q0,q1; rx(-pi/2) q0; rx(-pi/2) q1; }
# qreg q[2];
# ryy(0.1) q[0],q[1];
# ----
# Exported by BQSKit
# OPENQASM 2.0;
# include "qelib1.inc";
# qreg q[2];
# ryy(0.1) q[0], q[1];

Tracebacks

When reading the generated QASM file with Qiskit:

from qiskit import qasm2
qiskit_read_back = loads(qasm_str_from_bqskit)
# QASM2ParseError: "<input>:4,0: 'ryy' is not defined in this scope"

When reading the generated QASM file with Pytket:

from pytket.qasm import circuit_from_qasm_str
tket_circuit = circuit_from_qasm_str(qasm_str_from_bqskit)
# QASMParseError: Cannot parse gate of type: ryy Line:4.

Let me know if you need any additional information, thanks in advance

@MattePalte MattePalte changed the title Bug: QASM export: custom gate definition ryy missing from generated QASM file QASM export: custom gate definition ryy missing from generated QASM file Oct 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant