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

LangException: Unrecognized Delay Gate from Qiskit #307

Open
MattePalte opened this issue Jan 2, 2025 · 1 comment
Open

LangException: Unrecognized Delay Gate from Qiskit #307

MattePalte opened this issue Jan 2, 2025 · 1 comment
Labels
feature request New feature or request

Comments

@MattePalte
Copy link

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.

@edyounis
Copy link
Member

Thank you for the bug report! We should look to support the delay gate in compilation and qasm reading and writing. However, I don't know exactly how that support would look. If anyone has potential use cases involving them and BQSKit, I would love to hear them.

@edyounis edyounis added the feature request New feature or request label Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants