I need to use and plot the state of the first qubit in my multiqubit circuit, but the issue is that I need to use post selection - I want only the results of which the other qubits in the circuit are 0. for example, for this circuit:

enter image description here

I need to run it a few times, and see the statevector of qubit 0 for the case where qubit 1 is measured 0.

Is there a way to do it? Thanks!


1 Answer 1


You can use save_statevector with conditional = True, like that:

from qiskit import QuantumCircuit
from qiskit.providers.aer import AerSimulator
import numpy as np

circ = QuantumCircuit(2, 2)

𝜓 = [np.sqrt(0.8), np.sqrt(0.2)]
circ.initialize(𝜓, 0)
circ.initialize(𝜓, 1)
circ.measure(1, 1)
circ.save_statevector(conditional = True)

simulator = AerSimulator(method = 'statevector')

tr_circ = transpile(circ, simulator)
result = simulator.run(tr_circ).result()
data = result.data(0)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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