# How do we discard or delete or resuse a qubit at the end, on Qiskit? After I have finished computing and operating a specific circuit on a set of (say) 4 qubits, my final interest only is to deal with (say) two of the four qubits. Then, how do I recycle or delete the other two qubit? Or rather how do I plot state vectors of only the two qubits of interest on Qiskit?

In the above figure I want to delete q0_0 and q0_1. I want state vectors of only q1_0 and q1_1.

• you can write a function to build a circuit, and have an input of that function be the output of your first circuit. Remember, your quantum register can be indexed like a list – Mohammad Athar Feb 7 at 20:39
• for more details, can you provide a MCVE? – Mohammad Athar Feb 7 at 20:39
• hi, thanks for your response. To be more precise, I want to now deal with only the first two qubits and discard the other two. At least can I plot state vectors of only the first two, since the last two bits are just junk for me. – Sachin S Bharadwaj Feb 7 at 20:43

You can use Qiskit's partial_trace functionality on the final Statevector. Here's code that builds up the final statevector for your circuit, then traces over the first 2 qubits to yield the reduced density matrix (works on the latest version of Qiskit):

from qiskit import QuantumCircuit, QuantumRegister
from qiskit.quantum_info.states import Statevector, partial_trace
from qiskit.visualization import plot_state_city

q0 = QuantumRegister(2, 'q0')
q1 = QuantumRegister(2, 'q1')

circuit = QuantumCircuit(q0, q1)
circuit.h(q1)
circuit.cswap(q1, q1, q0)
circuit.cx(q1, q0)
circuit.cx(q0, q0)
circuit.ccx(q0, q1, q0)

zero_state = Statevector.from_label('0000')
final_state = zero_state.evolve(circuit)

reduced_state = partial_trace(final_state, [0, 1])

plot_state_city(reduced_state.data) • Thank you very much! This was what I was exactly looking for! – Sachin S Bharadwaj Feb 7 at 21:52