1
$\begingroup$

Circuit1

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.

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Mohammad Athar Feb 7 at 20:39
  • $\begingroup$ for more details, can you provide a MCVE? $\endgroup$ – Mohammad Athar Feb 7 at 20:39
  • $\begingroup$ 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. $\endgroup$ – Sachin S Bharadwaj Feb 7 at 20:43
1
$\begingroup$

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[1])
circuit.cswap(q1[1], q1[0], q0[1])
circuit.cx(q1[0], q0[0])
circuit.cx(q0[1], q0[0])
circuit.ccx(q0[0], q1[1], q0[1])

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)

enter image description here

|improve this answer|||||
$\endgroup$
  • $\begingroup$ Thank you very much! This was what I was exactly looking for! $\endgroup$ – Sachin S Bharadwaj Feb 7 at 21:52

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.