Quantum Computing For Programmers Part Ib: Bloch Sphere

If you read anything on quantum computing you are extremely likely to see the Bloch sphere, so it’s probably important to explain what it is and how it works.

Image from wikipedia: Wikipedia: Qubit

The Bloch sphere is a way of visually representing a qubit.

The north pole is the |0\rangle state, and the south pole is the |1\rangle state. The Z axis is vertical and runs from the |0\rangle to the |1\rangle state. A qubit’s state is represented by a point on the sphere.

If you read the last post, you might remember that there was a Pauli-Z gate which changed the phase of a qubit without changing it’s probability, as well as a more generalized version of the phase changing gate which also just rotated around the Z axis. Looking at the bloch sphere, you can see why that is true! Rotating a point around the Z axis moves it around the sphere horizontally, but it doesn’t make it any closer or farther to either the north or south pole. Since the distance to the poles is preserved, the probability of being one or the other stays the same, even though the phase changes.

The not gate, aka the Pauli-X gate, rotated a point around the X axis 180 degrees. Looking at the sphere, you could see how that would change a |1\rangle to a |0\rangle, or otherwise flip the probabilities & amplitudes of the states.

The Pauli-Y gate is a little more complex though (pun intended!) as it mapped |0\rangle to i|1\rangle and |1\rangle to -i|0\rangle by rotating 180 degrees around the Y axis. You may wonder how |1\rangle and i|1\rangle can both refer to the south pole, but the situation there is that every point EXCEPT the poles have a unique representation. So, they really do both refer to the south pole.

To find where a qubit sits on the sphere, the first step is to figure out the spherical coordinates theta (\theta) and phi (\phi) values, which you can then convert to a 3d point.

Start with whatever qubit you have in this form, where you know what the values for alpha (\alpha) and beta (\beta) are:
|\psi\rangle = \alpha|0\rangle + \beta|1\rangle

You can also write a qubit as:
|\psi\rangle = \cos\left(\tfrac{\theta}{2}\right) |0 \rangle \, + \, e^{i \phi}  \sin\left(\tfrac{\theta}{2}\right) |1 \rangle

Or like this, with less euler, and more trig:
|\psi\rangle = \cos\left(\tfrac{\theta}{2}\right) |0 \rangle \, +  \, ( \cos \phi + i \sin \phi) \, \sin\left(\tfrac{\theta}{2}\right) |1 \rangle

You can then set your known alpha and beta values to the trig (or euler) based equations:
\alpha = \cos\left(\tfrac{\theta}{2}\right)
\beta = \, ( \cos \phi + i \sin \phi) \, \sin\left(\tfrac{\theta}{2}\right)

and then solve for theta and phi (I wave my hands a bit here).

Once you have the theta and phi values figured out, you can convert that to a unit distance 3d point representing a point on the sphere by using the below, which describes the X,Y,Z components of the point:
(\sin \theta \cos \phi, \; \sin \theta  \sin \phi, \; \cos \theta)

Hopefully this explanation makes enough sense that if you encounter the bloch sphere, or things talking about rotations on the bloch sphere, you won’t be too lost 😛

Ok… time to move on to multiple qubit quantum circuits so we can do more interesting things and perhaps analyze the most well known quantum algorithms!