I am not able to undo an operation. For example, I want a single Hadamard gate on a single qubit but by mistake two Hadamard gate added. Now I want to remove one of them without interrupting kernel. Is there any easy way. Please help me. Thank you.
-
$\begingroup$ Could you elaborate a bit? Inside a jupyter notebook, you could easily remove a gate from your code by removing a line such as circuit.h(0). $\endgroup$– FrancoisJul 29, 2020 at 10:16
-
$\begingroup$ Yes! That is exactly what I wanted to say. Thank you $\endgroup$– Satish Kumar DubeyJul 29, 2020 at 14:11
1 Answer
To remove the last gate you can do qc.data.pop()
.
Example:
qc = QuantumCircuit(1)
qc.h(0)
qc.draw('text')
output:
┌───┐
q_0: ┤ H ├
└───┘
Then:
qc.data.pop()
qc.draw('text')
output:
q_0:
-
$\begingroup$ Thank you very much @Frank. It helps a lot for beginners like me. $\endgroup$ Jul 29, 2020 at 14:18