# Find local state and compute Bloch coordinates, like Quirk

In a multi-qubit system I can find the amplitudes of a state and compute probabilities, $$\theta$$, and $$\varphi$$. This falls out from simulation with simple numpy arrays. For example, after application of a variety of states, I get the amplitudes for all multi-qubit state $$|\psi\rangle$$, eg., $$|00\rangle$$, $$|01\rangle$$, $$|10\rangle$$, $$|11\rangle$$ as 4x1 complex numpy array, representing the tensor product of my 2 qubits.

These amplitudes and phases corresponds to this display in Quirk:

However, Quirk also shows the "local state" - per qubit - as a bloch wireframe.

How do I compute the Bloch coordinates for this local state, eg., out of my state vector? I believe I can get $$\theta$$ as the $$arccos$$ of the measurement probability for $$|0\rangle$$, which I compute via projection of $$|0\rangle \langle 0|$$ and $$|1\rangle \langle 1|$$ onto the density operator of the state? But how do I get the phase?

Thanks for any pointers!

1. Trace out everything except the qubit you are interested in. Do this by computing the outer product of the state of the target qubit, for each possible value of the other qubits, and summing up all those outer products. This will produce the 2x2 density matrix of the target qubit.

2. Get the x, y, z coordinates of the Bloch vector from the 2x2 density matrix $$D$$.

$$D = \begin{bmatrix} a& b^\ast\\b & 1-a \end{bmatrix}$$

$$x = 2 \cdot \text{RealPart}(b)$$

$$y = 2 \cdot \text{ImaginaryPart}(b)$$

$$z = 2 \cdot a - 1$$

• Thank you so much. I had to figure out how to trace out qubits, but once I got that working the resulting D -> coordinates appears to be working! Wonderful. I don't understand yet how and why the cartesian are computed from the remaining D this way. Next thing to focus on and learn... – rhundt Apr 24 at 6:02