0
$\begingroup$

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.

$\endgroup$
  • $\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$ – Francois Jul 29 at 10:16
  • $\begingroup$ Yes! That is exactly what I wanted to say. Thank you $\endgroup$ – Satish Kumar Dubey Jul 29 at 14:11
2
$\begingroup$

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: 
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much @Frank. It helps a lot for beginners like me. $\endgroup$ – Satish Kumar Dubey Jul 29 at 14:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.