0020

Posted at 17:50 on 4 May 2021, and revised at 10:39 on 5 May 2021

The Bloch sphere is a highly convenient geometric representation of qubit states and operations on them: for states, pure ones are points on the sphere and mixed ones are points inside the sphere; for operations, unitaries are rotations and measurements are projections to an axis. Although the Bloch sphere is useful when working with individual qubits, one defining characteristic of quantum systems is that composite systems cannot be understood in terms of the component systems, and in particular, a system of multiple qubits cannot be visualised as multiple Bloch spheres, so I’m still not sure how useful the Bloch sphere actually is for general quantum programming. But it seems to be the best thing we’ve got for the moment, and I suppose it doesn’t hurt to get familiar with it as long as I don’t commit to it too hastily.

Borrowing the picture of the Bloch sphere on Wikipedia,

every pure state $|\psi\rangle$ modulo the global phase (which is useless information for quantum systems) can be written (uniquely in most cases) as

$$ |\psi\rangle = \cos\frac{\theta}{2} \, |0\rangle + \sin\frac{\theta}{2} \, e^{i\phi} \, |1\rangle $$

where $0 \leq \theta \leq \pi$ and $0 \leq \phi < 2\pi$, and corresponds uniquely to a point on the sphere.
A standard exercise is giving $\theta$ and $\phi$ for particular states and thus identifying them on the sphere — for example, set $\theta \defeq \pi/2$ and $\phi \defeq 0$ and we get $|+\rangle = (|0\rangle + |1\rangle) /\sqrt 2$, the first element of the X-basis (visualised as the X-axis).
One can do the exercise by trigonometric calculations, of course, but it’s best to be able to do it intuitively on the sphere, especially for those working in ZX-calculus, where *phase*, rather than linear combination, is the primitive notion.
More precisely, the exercise relevant to ZX-calculus is a similar but different one:
To express an arbitrary state in ZX-calculus, we start from a phase state, which is a point lying on the equator with respect to, for example, the X-axis and carrying an X-phase, and then add a Z-phase to rotate it with respect to the Z-axis to where we want it to be.
The state can thus be determined by the two phases, and the first exercise I set for myself is to find the two phases given $\theta$ and $\phi$.

The exercise is not entirely trivial because the two phases do not correspond exactly to $\theta$ and $\phi$. I don’t know whether this in general is a feature or a bug of ZX-calculus, although for the common basis states it’s definitely a feature, because they are all Z- or X-phase states and readily expressible. For example, the X-basis states lie on the equator with respect to the Z-axis and carry the phases $0$ and $\pi$ respectively (directly corresponding to the $\phi$ angles of the two states), so $|+\rangle$ is just $1/\sqrt 2 \cdot Z(0)—$, which is the Z-spider with one output (multiplied by $1/\sqrt 2$), and the other X-basis state $|-\rangle$ is $1/\sqrt 2 \cdot Z(\pi)—$. (I won’t need spiders that have more than one input or output, so will just use the crappy notation, which goes from left to right, instead of full string diagrams.) Likewise, the Z-basis states are $|0\rangle = 1/\sqrt 2 \cdot X(0)—$ and $|1\rangle = 1/\sqrt{2} \cdot X(\pi)—$.

So how do we represent $|\psi\rangle$ in ZX-calculus? If we start from an X-phase state, the natural phase to use is $\theta$ — that is, we start from $1/\sqrt 2 \cdot X(\theta)—$. This is the state obtained by rotating $|0\rangle$ counter-clockwise by $\theta$. (In general, the direction of rotation can be remembered with the help of the right-hand rule — point your right thumb towards the direction of the axis with respect to which the rotation is performed (the X-axis in this case), and the rest of the fingers will give you the right direction of rotation.) $X(\theta)—$ carries a Z-phase of $-\pi/2$ however (which should be clear on the Bloch sphere), so we should add a Z-phase of $\pi/2 + \phi$ to bring the state to the right place. That is, we end up with $1/\sqrt 2 \cdot X(\theta)—Z(\pi/2 + \phi)—$.

To be absolutely sure about what we’re doing, let’s expand the ‘diagram’ to its ‘matrix’ form (relative to the computational Z-basis) and verify that it matches the ‘matrix’ form of $|\psi\rangle$. Start with $1/\sqrt 2 \cdot X(\theta)—$, which by definition is $1/\sqrt 2 \cdot \left(|+\rangle + e^{i\theta} |-\rangle\right)$. Expand this with respect to the Z-basis:

\begin{align*} & \frac{1}{\sqrt 2} \left(|+\rangle + e^{i\theta} |-\rangle\right) \\ ={}& \frac{1}{\sqrt 2} \left(\frac{1}{\sqrt 2}\left(|0\rangle + |1\rangle\right) + \frac{e^{i\theta}}{\sqrt 2} \left(|0\rangle - |1\rangle\right)\right) \\ ={}& \frac{1 + e^{i\theta}}{2} |0\rangle + \frac{1 - e^{i\theta}}{2} |1\rangle \\ ={}& \frac{1 + \cos \theta + i \sin \theta}{2} |0\rangle + \frac{1 - \cos \theta - i \sin \theta}{2} |1\rangle \end{align*}

Hmm, this looks scary. But since we’re expecting something like $\cos (\theta/2)$, let’s look up the Wikipedia page of trigonometric identities. This particular formula

$$ \cos 2\theta = 2 \cos^2 \theta - 1 $$

looks promising since the $-1$ will help us get rid of the $1$ in the amplitude of $|0\rangle$. This one

$$ \sin 2\theta = 2 \sin \theta \cos \theta $$

looks promising too because the $2$ will probably cancel out the denominator. So we calculate:

\begin{align*} & \frac{1 + \cos \theta + i \sin \theta}{2} \\ ={}& \frac{1}{2} \left( 1 + (2 \cos^2 \frac{\theta}{2} - 1) + i \cdot 2 \sin \frac{\theta}{2} \cos \frac{\theta}{2} \right) \\ ={}& \cos \frac{\theta}{2} \left( \cos \frac{\theta}{2} + i \sin \frac{\theta}{2} \right) \\ ={}& \cos \frac{\theta}{2} \, e^{i\theta/2} \end{align*}

Not bad! An $e^{i\theta/2}$ emerges, but it may just be a global phase, so if this also appears in the result of simplifying the amplitude of $|1\rangle$ then it can be ignored. This time we should probably use another $\cos 2\theta$ formula

$$ \cos 2\theta = 1 - 2 \sin^2 \theta $$

in the hope of getting rid of the $1$:

\begin{align*} & \frac{1 - \cos \theta - i \sin \theta}{2} \\ ={}& \frac{1}{2} \left( 1 - (1 - 2 \sin^2 \frac{\theta}{2}) - i \cdot 2 \sin \frac{\theta}{2} \cos \frac{\theta}{2} \right) \\ ={}& \sin \frac{\theta}{2} \left( \sin \frac{\theta}{2} - i \cos \frac{\theta}{2} \right) \end{align*}

The part in parentheses doesn’t seem to match $e^{i\theta/2}$ at first, but this is easily fixable by taking out $-i$, which is $e^{-i\pi/2}$:

\begin{align*} & \sin \frac{\theta}{2} \left( \sin \frac{\theta}{2} - i \cos \frac{\theta}{2} \right) \\ ={}& \sin \frac{\theta}{2} \cdot (-i) \cdot \left( i \sin \frac{\theta}{2} + \cos \frac{\theta}{2} \right) \\ ={}& \sin \frac{\theta}{2} \, e^{-i\pi/2} e^{i\theta/2} \end{align*}

So we get

$$ \frac{1}{\sqrt 2} \cdot X(\theta)— ~=~ e^{i\theta/2} \left( \cos \frac{\theta}{2} \, |0\rangle + \sin \frac{\theta}{2} \, e^{-i\pi/2} \, |1\rangle \right) $$

where $e^{i\theta/2}$ is a global phase and can be ignored. It remains to check what the Z-phase gate $—Z(\pi/2 + \phi)—$ does, but this one is easier, especially if we verify the general case: a Z-phase gate $—Z(\alpha)—$ expands to $|0\rangle\langle 0| + e^{i\alpha} \, |1\rangle\langle 1|$; given a state $x \, |0\rangle + y \, |1\rangle$, applying the gate to the state yields

$$ \left( |0\rangle\langle 0| + e^{i\alpha} \, |1\rangle\langle 1| \right) \left( x \, |0\rangle + y \, |1\rangle \right) = x \, |0\rangle + e^{i\alpha} y \, |1\rangle $$

Therefore what the gate does is simply multiplying the amplitude of $|1\rangle$ by $e^{i\alpha}$ (that is, adding a Z-phase of $\alpha$). So we arrive at

$$ \frac{1}{\sqrt 2} \cdot X(\theta)—Z(\pi/2 + \phi)— ~=~ e^{i\theta/2} \left( \cos \frac{\theta}{2} \, |0\rangle + \sin \frac{\theta}{2} \, e^{i\phi} \, |1\rangle \right) $$

as required.

How to express $|\psi\rangle$ by applying an X-phase gate to a Z-phase state is less obvious, and the ZX-calculus doesn’t seem to shed a lot of light on this either — it’s not obvious to me how to rewrite $X(\theta)—Z(\pi/2 + \phi)—$ into $Z(\alpha)—X(\beta)—$ for some $\alpha$ and $\beta$ in ZX-calculus. This is perhaps related to the problems about making ZX-calculus complete, discussed for example by van de Wetering in Section 9.5 of his ZX-calculus survey, where it is commented that in addition to the simpler (Clifford) ZX-calculus rules, we also need to somehow capture ‘the rotational structure of the Bloch sphere [to] retriev[e] a complete language for reasoning about qubit quantum computing’. I don’t really care about completeness though — it’s more important to be able to reason about interesting quantum algorithms with a reasonable amount of effort and bring out as much intuition as possible. If occasionally I need an equation that cannot be derived in ZX-calculus, I’d probably be happy to treat the equation as an axiom and revert/resort to matrix calculations to verify it. All these discussions are probably still premature though — I’ll have to work with some concrete quantum algorithms to see how things actually unfold, but it’ll take (quite some) time for me to get to that stage.