Skip to content

LangException: Unrecognized Delay Gate from Qiskit #307

@MattePalte

Description

@MattePalte

System Information

RUN pip install --no-cache-dir qiskit==1.2.1
RUN pip install bqskit==1.2.0

Expected behavior

The circuit constructed with Qiskit should be successfully exported to a QASM file and then imported into Bqskit without any issues. The import process should recognize the delay gate and create a corresponding Bqskit circuit.

Actual behavior

The circuit constructed with Qiskit is successfully exported to a QASM file, but when trying to import it into Bqskit, a LangException is raised, indicating that the delay gate is not recognized.

Additional information

This issue is reproducible every time the code is run. The error occurs because Bqskit does not recognize the delay gate used in the Qiskit circuit. The QASM file generated by Qiskit contains the delay gate, which is not a standard gate in QASM.

Source code

Here a minimal example to reproduce the issue:

from qiskit import QuantumCircuit
from qiskit import qasm2
from bqskit import Circuit
from pathlib import Path

# Section: Circuit
circ = QuantumCircuit(6, 6)
circ.delay(1, 4, 's')

# Export to QASM with Qiskit
file_path_qiskit = 'example_qiskit.qasm'
qasm2.dump(circ, file_path_qiskit)
print(f'Saved the Qiskit circuit to {file_path_qiskit}')

# print file content
print('File content:')
print(Path(file_path_qiskit).read_text())

# Import from QASM with Bqskit
bqskit_circuit = Circuit.from_file(file_path_qiskit)
print(f'Circuit (bqskit) imported correctly: {file_path_qiskit}')
# Output:
# Saved the Qiskit circuit to example_qiskit.qasm
# File content:
# OPENQASM 2.0;
# include "qelib1.inc";
# opaque delay(param0) q0;
# qreg q[6];
# creg c[6];
# delay(1.0) q[4];

Tracebacks

Please include the error tracebacks related to the issue here. This will be automatically formatted into code, so no need for backticks.

---------------------------------------------------------------------------
LangException                             Traceback (most recent call last)
Cell In[2], line 20
     17 print(Path(file_path_qiskit).read_text())
     19 # Import from QASM with Bqskit
---> 20 bqskit_circuit = Circuit.from_file(file_path_qiskit)
     21 print(f'Circuit (bqskit) imported correctly: {file_path_qiskit}')

File ~//python3.10/site-packages/bqskit/ir/circuit.py:3258, in Circuit.from_file(filename)
   3255 language = get_language(filename.split('.')[-1])
   3257 with open(filename) as f:
-> 3258     return language.decode(f.read())

File ~//python3.10/site-packages/bqskit/ir/lang/qasm2/qasm2.py:37, in OPENQASM2Language.decode(self, source)
     35 tree = parse(source)
     36 visitor = OPENQASMVisitor()
---> 37 visitor.visit_topdown(tree)
     38 return visitor.get_circuit()

File ~//python3.10/site-packages/lark/visitors.py:375, in Visitor.visit_topdown(self, tree)
    373 "Visit the tree, starting at the root, and ending at the leaves (top-down)"
    374 for subtree in tree.iter_subtrees_topdown():
--> 375     self._call_userfunc(subtree)
    376 return tree

File ~//python3.10/site-packages/lark/visitors.py:347, in VisitorBase._call_userfunc(self, tree)
    346 def _call_userfunc(self, tree):
--> 347     return getattr(self, tree.data, self.__default__)(tree)

File ~//python3.10/site-packages/bqskit/ir/lang/qasm2/visitor.py:303, in OPENQASMVisitor.gate(self, tree)
    301     gate_def = self.custom_gate_defs[gate_name]
    302 else:
--> 303     raise LangException('Unrecognized gate: %s.' % gate_name

Thanks in advance. Let me know if you need more information.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions