2
$\begingroup$

Suppose we start from 2 wires (q0 and q1) and through some quantum gates, suppose we measure q1 wire only.

As we measure the q1 wire, the state vector of this quantum state would be determined immediately. How can I print out this state vector?

In addition, I would like to print out the state vector of q0 wire only. Does anyone know how to do this task via qiskit or cirq or pyquil? (Any other package language is also fine!)

$\endgroup$
1
  • 1
    $\begingroup$ Do you mean the state before or after measurement? Note that, in general, before measurement this is not possible, because the two qubits can be entangled, which is exactly saying that the state of one of the qubits cannot be described without also describing the other qubit. Furthermore, after measurement the state is just the particular state associated with the measurement outcome. $\endgroup$
    – JSdJ
    Jun 24, 2020 at 7:30

4 Answers 4

1
$\begingroup$

Cirq has a function cirq.sub_state_vector which can extract a single qubit's state from a full state vector.

It doesn't just do the single qubit case, it can do arbitrary subsets of qubits. It will raise an exception if the subset you pick is entangled with other stuff. It's unfortunately a bit picky about error tolerances and input shape.

$\endgroup$
0
$\begingroup$

This task can be done using Microsoft Q#

If you have two qubits which after quantum operations are in the state $|\psi\rangle$, and you wish to find the state of the qubit q0 before/without measurement, You can use Q#'s DumpRegister function which will print to the console the state of your qubits.

The output would look something like this

# wave function for qubits with ids (least to most significant): 0
∣0❭:     1.000000 +  0.000000 i  ==     ******************** [ 1.000000 ]     --- [  0.00000 rad ]
∣1❭:     0.000000 +  0.000000 i  ==                          [ 0.000000 ]    

If you choose to Measure the qubit q0 then its state collapses to the result of your measurement.

$\endgroup$
0
$\begingroup$

If you are looking solely at simulation tasks (which is not entirely clear to me as you want to find the statevector but mention measurement), using Qiskit's StatevectorSimulator and the partial_trace function should be enough. An example is the following:

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

qc = QuantumCircuit(2)
# Whatever gates you want to use

sim    = Aer.get_backend("statevector_simulator")
state  = execute(qc, sim).result().get_statevector()

state_q1 = partial_trace(state, [0])

You will end up with the density matrix of qubit one in state_q1.

$\endgroup$
0
$\begingroup$

In Quirk, you look at state vectors of qubits using the amplitude display. You can get conditional state vectors, such as the state vector implied by a particular measurement result, by combining the amplitude display with a control on the measurement bit.

Here is an example:

Example

And another example:

Example 2

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy