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

Pytket QASM Importer Bug: Unsupported ISwap Gate Gate has an invalid number of parameters #1605

Open
MattePalte opened this issue Oct 4, 2024 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@MattePalte
Copy link

Expected behavior

When using Pytket to import a QASM file containing an ISwap gate generated by Qiskit, we expect the import to succeed without any errors. The Pytket importer should be able to correctly parse the ISwap gate and its parameters.

Actual behavior

The Pytket importer crashes when trying to import the QASM file, throwing a "Gate has an invalid number of parameters" error. This error occurs because the Pytket importer does not support the ISwap gate with two parameters.

Additional information

This issue is 100% reproducible. We have verified that the Qiskit-generated QASM file is correct and can be imported by other tools. The issue seems to be specific to the Pytket importer.

Source code

from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
from qiskit.qasm import qasm_data
from pytket.qasm import circuit_from_qasm_str

# Create a Qiskit circuit with an ISwap gate
qr = QuantumRegister(3, 'qr')
cr = ClassicalRegister(3, 'cr')
qc = QuantumCircuit(qr, cr, name='qc')
qc.iswap(qr[1], qr[2])

# Export the Qiskit circuit to a QASM file
qasm_content = qc.qasm()

# Try to import the QASM file using Pytket
try:
    circuit = circuit_from_qasm_str(qasm_content)
    print(f'Circuit (Pytket) imported correctly: ')
except Exception as e:
    print(e)  # Gate has an invalid number of parameters

print(qasm_content)
# Output:
# OPENQASM 2.0;
# include "qelib1.inc";
# gate iswap q0,q1 { s q0; s q1; h q0; cx q0,q1; cx q1,q0; h q1; }
# qreg qr[3];
# creg cr[3];
# iswap qr[1],qr[2];

Tracebacks

Gate has an invalid number of parameters

System

import qiskit
import pytket
print(f"Qiskit version: {qiskit.__version__}")
print(f"Pytket version: {pytket.__version__}")

Output:

Qiskit version: 1.2.0
Pytket version: 1.31.1
@cqc-alec cqc-alec added the bug Something isn't working label Oct 7, 2024
@cqc-alec cqc-alec self-assigned this Oct 7, 2024
@cqc-alec
Copy link
Collaborator

cqc-alec commented Oct 7, 2024

I think this bug was introduced by #612 . The idea there was that pytket would add necessary gate definitions for conversion of certain known pytket gates to QASM, including OpType.ISWAP (which in TKET is a one-parameter gate). Somehow when converting in the other direction when we encounter such a gate (in this case iswap) it is assumed that it corresponds to this definition, so pytket tries to convert it to its own OpType.ISWAP and fails.

@cqc-alec cqc-alec removed their assignment Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants