TransWikia.com

How to undo an operation in qiskit on jupyter notebook?

Quantum Computing Asked by Satish Kumar Dubey on October 1, 2021

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.

One 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: 

Correct answer by Frank on October 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP