2
$\begingroup$

I would like to know how to know in which state a qubit is (I am talking about single-qubit errors), because in order to apply a non unitary gate in the simulator I have to renormalize the state or the corresponding non unitary Kraus operator (the non unitary gate in my circuit). Therefore I need to know in which state the circuit it. I am of course talking about the simulator, which in fact is classical and therefore it must be a way to know the state at each point of the circuit.

$\endgroup$

1 Answer 1

3
$\begingroup$

You can take snapshots of the statevector of the circuit when you use the 'qasm_simulator'. You simply append snapshot instructions into your circuit where you would like to see the statevector, and then can see the values in the result object that is returned. You add a snapshot instruction using

from qiskit.extensions.simulator import snapshot
qc.snapshot('my_label')
$\endgroup$
3
  • 1
    $\begingroup$ Thank you so much, that was exactly was I was looking for! I obtain <qiskit.circuit.instructionset.InstructionSet object at 0x00000258770767F0> for a circuit where I have applied a X gate to a qubit in the zero state, so this corresponds to a 1. How do I recover the state from this? $\endgroup$
    – Paula G
    Mar 3, 2020 at 8:05
  • $\begingroup$ You have to run the circuit, and the snapshots will be contained in the results object. I believe the command to retrieve them is something like result.get_snapshot('my_label') $\endgroup$
    – met927
    Mar 3, 2020 at 8:27
  • 1
    $\begingroup$ Thank you! It has been really useful. $\endgroup$
    – Paula G
    Mar 3, 2020 at 8:45

Your Answer

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

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