Skip to content

Commit

Permalink
fix qasm with reset (Qiskit#9819)
Browse files Browse the repository at this point in the history
  • Loading branch information
t-imamichi authored Mar 20, 2023
1 parent e2f6606 commit 8ceb57d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion qiskit/circuit/quantumcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1683,7 +1683,7 @@ def qasm(
bit_labels[clbit],
)
elif operation.name == "reset":
string_temp += f"reset {bit_labels[instruction.qubits[0]]}\n"
string_temp += f"reset {bit_labels[instruction.qubits[0]]};\n"
elif operation.name == "barrier":
qargs = ",".join(bit_labels[q] for q in instruction.qubits)
string_temp += "barrier;\n" if not qargs else f"barrier {qargs};\n"
Expand Down
4 changes: 4 additions & 0 deletions releasenotes/notes/fix-qasm-reset-ef7b07bf55875be7.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
fixes:
- |
Fixed :meth:`~.QuantumCircuit.qasm` so that it appends ``;`` after ``reset`` instruction.
12 changes: 12 additions & 0 deletions test/python/circuit/test_circuit_qasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,18 @@ def test_circuit_qasm_with_permutations(self):
permutation__2_1_0_ q[0],q[1],q[2];\n"""
self.assertEqual(qc.qasm(), expected_qasm)

def test_circuit_qasm_with_reset(self):
"""Test circuit qasm() method with Reset."""
qc = QuantumCircuit(2)
qc.reset([0, 1])

expected_qasm = """OPENQASM 2.0;
include "qelib1.inc";
qreg q[2];
reset q[0];
reset q[1];\n"""
self.assertEqual(qc.qasm(), expected_qasm)


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

0 comments on commit 8ceb57d

Please sign in to comment.