Skip to content

qasm2 exporter allows for custom instruction, resulting in invalid qasm2 code #7351

@1ucian0

Description

@1ucian0

Environment

  • Qiskit Terra version: master

What is happening?

@omarcostahamido noticed that it is possible to create a custom instruction in a circuit and then export it as QASM2 code. The result is non-valid QASM2.

How can we reproduce the issue?

This is the example provided by @omarcostahamido in Slack:

qc = QuantumCircuit(2,2, name='bell')
qc.h(0)
qc.cx(0, 1)
qc.measure_all()
custom_gate = qc.to_instruction()

new_circ = QuantumCircuit(2,2)

new_circ.append(custom_gate, [0, 1],[0, 1])

print(new_circ)
print(new_circ.qasm())
     ┌───────┐
q_0: ┤0      ├
     │       │
q_1: ┤1      ├
     │  bell │
c_0: ╡0      ╞
     │       │
c_1: ╡1      ╞
     └───────┘
OPENQASM 2.0;
include "qelib1.inc";
gate bell q0,q1 { h q0; cx q0,q1; barrier q0,q1; measure q0; measure q1; }
qreg q[2];
creg c[2];
bell q[0],q[1],c[0],c[1];

What should happen?

When a custom instruction is part of a circuit, exporting that circuit as QASM2 code should raise an error.

Any suggestions?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmod: qasm2Relating to OpenQASM 2 import or export

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions