Skip to content

qasm3.Exporter raises an obscure error on invalid basis-gate name #12886

Closed
@t-imamichi

Description

Environment

  • Qiskit version: 1.2.0 rc1
  • Python version: 3.12.4
  • Operating system: macOS 14.6

What is happening?

qasm3.Exporter raises an error with a simple case with 1.2.0 rc1 while 1.1.1 works fine.

How can we reproduce the issue?

from qiskit import QuantumCircuit, qasm3
from qiskit.providers.fake_provider import GenericBackendV2

circuit = QuantumCircuit(2)
backend = GenericBackendV2(2)
exporter = qasm3.Exporter(basis_gates=backend.operation_names)
result = exporter.dumps(circuit)
print(result)

qiskit 1.2.0 rc1

Traceback (most recent call last):
  File "/Users/ima/tasks/4_2024/qiskit/qasm3-import/tmp/test_min.py", line 7, in <module>
    result = exporter.dumps(circuit)
             ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit312/lib/python3.12/site-packages/qiskit/qasm3/exporter.py", line 182, in dumps
    self.dump(circuit, stream)
  File "/Users/ima/envs/qiskit312/lib/python3.12/site-packages/qiskit/qasm3/exporter.py", line 196, in dump
    builder.build_program()
  File "/Users/ima/envs/qiskit312/lib/python3.12/site-packages/qiskit/qasm3/exporter.py", line 629, in build_program
    self.symbols.register_gate_without_definition(builtin, None)
  File "/Users/ima/envs/qiskit312/lib/python3.12/site-packages/qiskit/qasm3/exporter.py", line 435, in register_gate_without_definition
    name = self.escaped_declarable_name(name, allow_rename=False, unique=False)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ima/envs/qiskit312/lib/python3.12/site-packages/qiskit/qasm3/exporter.py", line 352, in escaped_declarable_name
    raise QASM3ExporterError(f"cannot use the keyword '{name}' as a variable name")
qiskit.qasm3.exceptions.QASM3ExporterError: "cannot use the keyword 'reset' as a variable name"

qiskit 1.1.1

OPENQASM 3.0;
include "stdgates.inc";
qubit[1] q;

What should happen?

It would be nice to run without error or show a warning instead of the error.

Any suggestions?

No response

Activity

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

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions