Skip to content

Commit 271c58e

Browse files
t-imamichimergify[bot]
authored andcommitted
fix qasm with reset (#9819)
(cherry picked from commit 8ceb57d)
1 parent a70a195 commit 271c58e

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
@@ -598,6 +598,18 @@ def test_circuit_qasm_with_permutations(self):
598598
permutation__2_1_0_ q[0],q[1],q[2];\n"""
599599
self.assertEqual(qc.qasm(), expected_qasm)
600600

601+
def test_circuit_qasm_with_reset(self):
602+
"""Test circuit qasm() method with Reset."""
603+
qc = QuantumCircuit(2)
604+
qc.reset([0, 1])
605+
606+
expected_qasm = """OPENQASM 2.0;
607+
include "qelib1.inc";
608+
qreg q[2];
609+
reset q[0];
610+
reset q[1];\n"""
611+
self.assertEqual(qc.qasm(), expected_qasm)
612+
601613

602614
if __name__ == "__main__":
603615
unittest.main()

0 commit comments

Comments
 (0)