-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingmod: qasm2Relating to OpenQASM 2 import or exportRelating to OpenQASM 2 import or export
Description
Environment
- Qiskit Terra version: qiskit==0.43.1
- Python version: 3.10
- Operating system: Ubuntu 18.04
What is happening?
The QASM2 exporter creates an invalid qasm when an empty circuit is appended.
How can we reproduce the issue?
Running this simple snippet, where a circuit is appended to another generates an invalid QASM2:
from qiskit import QuantumCircuit
q_1 = QuantumCircuit(5, name='legit_circuit')
q_2 = QuantumCircuit(name='empty_circuit')
q_1.append(q_2)
q_1.qasm(filename="c1.qasm")
Output:
OPENQASM 2.0;
include "qelib1.inc";
gate empty_circuit { }
qreg q[5];
empty_circuit ;
Where we have an empty instruction.
It is incorrect because if cannot be re-imported:
from qiskit import QuantumCircuit
QuantumCircuit().from_qasm_file("c1.qasm")
Failing with error:
qasm/qasmparser.py", line 397, in p_id_e
raise QasmError("Expected an ID, received '" + str(program[1].value) + "'")
qiskit.qasm.exceptions.QasmError: "Expected an ID, received '{'"
What should happen?
I would have expected a valid qasm
file or an error while exporting.
Any suggestions?
Probably this corner case should be checked when creating custom gates at the QASM level exporter. Either an error should be thrown when exporting, or ideally all empty instructions should be removed before exporting.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingmod: qasm2Relating to OpenQASM 2 import or exportRelating to OpenQASM 2 import or export