# Qiskit - How to get statevector for each shot?

I have a simple circuit which I run for 10 shots:

from qiskit.quantum_info import Statevector

from qiskit import Aer, execute, QuantumCircuit
from qiskit.quantum_info import Statevector

backend = Aer.get_backend("statevector_simulator")
qc2 = QuantumCircuit(2, 1)
qc2.h(0)
qc2.measure([0], [0])
print(qc2)
result = execute(qc2, backend=backend, shots=10).result()


Now, when I print the state vector with:

print('State after measurement:', result.get_statevector())


The output is:

State after measurement: Statevector([1.+0.j, 0.+0.j, 0.+0.j, 0.+0.j], dims=(2, 2))

The question is that to which of the 10 shots does this state vector belong to? Depending on the measurement, the state vector should be different - when q0 is measured as 0 and when q0 is 1.

And how do I get the statevector for each shot?

You can use save_statevector simulator instruction.

To save the statevector for each shot, set pershot value to True:

from qiskit import Aer, execute, QuantumCircuit
from qiskit.providers.aer.library import save_statevector

backend = Aer.get_backend("statevector_simulator")
qc2 = QuantumCircuit(2, 1)
qc2.h(0)
qc2.measure([0], [0])

qc2.save_statevector(label = 'test', pershot = True)
result = execute(qc2, backend = backend, shots = 10).result()

print(result.data(0)['test'])


To your first question, you see the statevector of the last shot performed. The answer by Egretta Thula will get you the statevecor for each shot. Just to make sure we are on the same page, it is crucial if you save your statevector before or after the measurement. After the measurement the superposition collapses and your staevector is either $$|0\rangle$$ or $$|1\rangle$$.

If you place save_statevecor() before the measurement, it will be the same for each shot, since H-Gate brings your system into state $$\frac{1}{\sqrt(2)}(|0\rangle + |1\rangle)$$.

You can also get the readouts for each shot with get_memory() method of the result. For that, you need to set the option memory=True.

result = backend.run(qc2, shots=10, memory=True).result()
memory = result.get_memory(qc2)
print(memory)