Skip to content

Commit 05eff46

Browse files
t-imamichiking-p3nguin
authored andcommitted
fix qasm with reset (Qiskit#9819)
1 parent b161909 commit 05eff46

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

qiskit/circuit/quantumcircuit.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1683,7 +1683,7 @@ def qasm(
16831683
bit_labels[clbit],
16841684
)
16851685
elif operation.name == "reset":
1686-
string_temp += f"reset {bit_labels[instruction.qubits[0]]}\n"
1686+
string_temp += f"reset {bit_labels[instruction.qubits[0]]};\n"
16871687
elif operation.name == "barrier":
16881688
qargs = ",".join(bit_labels[q] for q in instruction.qubits)
16891689
string_temp += "barrier;\n" if not qargs else f"barrier {qargs};\n"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixed :meth:`~.QuantumCircuit.qasm` so that it appends ``;`` after ``reset`` instruction.

test/python/circuit/test_circuit_qasm.py

+12
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,18 @@ def test_circuit_qasm_with_permutations(self):
616616
permutation__2_1_0_ q[0],q[1],q[2];\n"""
617617
self.assertEqual(qc.qasm(), expected_qasm)
618618

619+
def test_circuit_qasm_with_reset(self):
620+
"""Test circuit qasm() method with Reset."""
621+
qc = QuantumCircuit(2)
622+
qc.reset([0, 1])
623+
624+
expected_qasm = """OPENQASM 2.0;
625+
include "qelib1.inc";
626+
qreg q[2];
627+
reset q[0];
628+
reset q[1];\n"""
629+
self.assertEqual(qc.qasm(), expected_qasm)
630+
619631

620632
if __name__ == "__main__":
621633
unittest.main()

0 commit comments

Comments
 (0)