Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix QuantumCircuit.qasm with reset #9819

Merged
merged 1 commit into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()