2

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!

glS
  • 27,510
  • 7
  • 37
  • 125
Shiran
  • 21
  • 1

1 Answers1

2

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) print(data['statevector'])

Egretta.Thula
  • 11,986
  • 1
  • 13
  • 34