0
$\begingroup$

"""

from qiskit.providers import aer
from qiskit.circuit import QuantumCircuit,reset

def run_circuit(circuit:QuantumCircuit)
  print(circuit)
  simulator = aer.Aer.get_backend("statevector_simulator")
  result1 = simulator.run(circuit).result()
  statevector1 = result1.get_statevector(circuit)
  prob_vector1 = Statevector(statevector1).probabilities()
  print(prob_vector1)
  result2=simulator.run(circuit).result()
  statevector2 = result2.get_statevector(circuit)
  prob_vector2 = Statevector(statevector2).probabilities()
  print(prob_vector2)

""" The code above is what I am using to run some simple circuit. See image of the circuit below. Image of Circuit I am running.

As you can see from the print line after the circuit, the probability vector is mixed up for the same circuit when run twice. Does anyone know why this is happening? I am assuming it has something to do with the reset operation, as without it it works fine everytime. But is there a way to do the reset operation and not get this bug?

Thanks and Best Regards

AP

Edit with New Information:

So it seems that when you use the reset operation, rather than give you the new state vector, it causes the collapse of the state vector and gives full probability to a specific state. I have these images from the IBMQ lab that show what I am taking about. Does anyone know how to make it so that it gives the correct state vector and not the collapsed state?

enter image description here

enter image description here

$\endgroup$

2 Answers 2

0
$\begingroup$

Reset instruction is composed of a mid-circuit measurement followed by an X-gate conditioned on the outcome of the measurement[1]. So, the collapse is inevitable due to this implicit measurement.

In your case, you will always get two state vectors, one for the case where the state after reset is $|00\rangle$, and the other for the case where the state is $|10\rangle$. Unless, of course, you prepared the state without non-unitary operations.

$\endgroup$
0
$\begingroup$

In run_circuit function you are printing probabilities 2 times may be i.e it is happening you can refactor your code as follow:

def run_circuit(circuit:QuantumCircuit)
  print(circuit)
  simulator = aer.Aer.get_backend("statevector_simulator")
  result1 = simulator.run(circuit).result()
  statevector1 = result1.get_statevector(circuit)
  prob_vector1 = Statevector(statevector1).probabilities()
  return prob_vector1
$\endgroup$
1
  • $\begingroup$ Hey Raghav, my question was more so with regards to why, when the circuit is run twice do I get different state vectors for the same circuit. Should the state-vector not be the same, as none of the operators are changing? and does this change have something to do with non-unitary nature of the reset qubit that I am not understanding or is it the specific implementation of the statevector_simulator that is causing this issue. $\endgroup$
    – AP110
    Commented Aug 25, 2023 at 13:45

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.