# How to get the Bloch sphere angles given an arbitrary qubit?

I understand that given a pure state $$|\psi\rangle$$, we can express it in terms of two angles $$\theta$$ and $$\varphi$$ such that $$|\psi\rangle = \cos(\theta/2)|0\rangle + \mathrm{e}^{i\varphi}\sin(\theta/2)|1\rangle$$, and this is derived by converting from $$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$$ into their representations in terms of $$r\mathrm{e}^{i\theta}$$, and then factoring and rearranging that.

But how do I convert between the two representations given arbitrary states? I know that $$|0\rangle = (\theta,\varphi) = (0,0), |1\rangle = (\pi,0), |+\rangle = (\pi/2, 0)$$ etc, but how do I get it for an arbitrary state $$|\psi\rangle$$?

So far, I have:

1. If $$\alpha$$ is complex, shift the entire state by phase $$\bar{\alpha}$$, where $$\bar\alpha$$ is the complex conjugate of $$\alpha$$, to end up with $$\alpha\bar\alpha |0\rangle + \bar\alpha\beta|1\rangle$$
2. Use the formulas:

$$\theta = 2 \arccos(\alpha\bar\alpha) \\ \varphi = ???$$

As in if given $$|\psi\rangle=\alpha |0\rangle+\beta |1\rangle$$, and you want it in the form $$\cos(\theta/2) |0\rangle+e^{i\phi}\sin(\theta/2) |1\rangle$$?

Assume the state is normalised $$|\alpha|^2+|\beta|^2=1$$.

I'd first start by multiplying by $$\frac{\alpha^*}{|\alpha|}$$ which is a phase (complex number unit length), and use $$\alpha \alpha^*=|\alpha|^2$$.

$$\frac{\alpha^*}{|\alpha|}|\psi\rangle=|\alpha| |0\rangle+\frac{\beta\alpha^*}{|\alpha|}|1\rangle =\cos(\theta/2) |0\rangle+e^{i\phi}\sin(\theta/2) |1\rangle$$

So $$\theta=2\arccos(|\alpha|)$$ or $$\theta=2\arcsin(|\beta|)$$.

Then $$\frac{\beta\alpha^*}{|\alpha|}=e^{i\phi}|\beta|$$ or $$\frac{\beta\alpha^*}{|\alpha||\beta|}=e^{i\phi}$$,

so that $$\phi=\arg\left(\frac{\beta\alpha^*}{|\alpha||\beta|}\right)$$ and it depends on how you want to calculate that, which branch of the loagarithm to take/where to measure angles from.

You could do something like $$\phi=-i\ln\left(\frac{\beta\alpha^*}{|\alpha||\beta|}\right)$$ etc.

In summary try

$$\theta = 2 \arccos(|\alpha|) \\ \varphi = \arg\left(\frac{\beta\alpha^*}{|\alpha||\beta|}\right)$$

• Why does $e^{i\varphi}|\beta| = \frac{\beta\alpha*}{|\alpha|}$? Where did the $|\beta|$ come from, or am I missing something? Commented Mar 8, 2020 at 18:00
• @IsaacKhor I could've written it a bit clearer, if $\theta=2\arcsin(|\beta|)$ which you get from equating the $|1\rangle$ coefficients, then $|\beta|=\sin(\theta/2)$. So again comparing the $|1\rangle$ coefficients you get that $\frac{\beta \alpha^*}{|\alpha|}=e^{i\phi}\sin(\theta/2)=e^{i\phi}|\beta|$ Commented Mar 8, 2020 at 18:43

I found that the accepted answer does not allow $$|\alpha|$$ or $$|\beta|$$ to be zero. To allow this, I first find the phase/argument of $$\alpha$$ and then rotate $$\beta$$ with a factor $$\exp(-i\arg(\alpha))$$.

Apologies for the Python, but then I get:

import cmath
import math

alpha = 0.5 + 0.5j
beta = 0.5 - 0.5j

magn = math.sqrt(abs(alpha)**2 + abs(beta)**2)
alpha /= magn
beta /= magn

theta = cmath.acos(abs(alpha)) * 2
if theta:
phi = cmath.log(beta * cmath.exp(-1j*cmath.phase(alpha)) / cmath.sin(theta / 2)) / 1j
else:
phi = 0

theta = round(theta.real, 2)
phi = round(phi.real, 2)

print(f"{theta=}, {phi=}")