Search⌘ K
AI Features

Single Qubit Gates

Learn how single qubit gates function as reversible unitary transformations on quantum states represented on the Bloch Sphere. Understand key gates such as Pauli X, Y, Z, and Hadamard, and see how they manipulate superposition and phase in qubits to enable quantum algorithms.

Quantum gates

So far, we’ve only talked about quantum gates in an abstract sense, that they are operations that manipulate the quantum state of a qubit. Let’s take a look at how this works formally.

A vector represents a quantum state. The only way we can manipulate this vector is by rotating it in the state space. We cannot change its length because of the normalization constraint.

Matrices play a key role in transformations. We can think of a vector rotation as a transformation in the state space. A matrix transformation can represent each rotation. We can apply this transformation to a vector by performing a matrix multiplication with the matrix.

We want our quantum gates to be reversible. We can achieve this by representing quantum gates as unitary matrices.

A complex-valued square matrix is unitary if its conjugate transpose is also its inverse.

In other words, applying such a transformation twice will revert the state vector to its original position. Think of it as a clockwise rotation followed by an equal anti-clockwise rotation. We would land at the same place in the state space. The Bloch Sphere will play a vital role here to visualize these rotations.

The Pauli gates

These quantum gates are based on the Pauli spin matrices. We need not go into the details of why they’re called Pauli spin. Let’s just look at the effect of these gates on a qubit.

The X gate

This is the quantum equivalent of the NOT gate. It is defined as follows:

X=[0110]X=\begin{bmatrix}0&1\\1&0\end{bmatrix}

We know that it will convert the 0|0\rangle state to 1|1\rangle and vice versa. Let’s have a look at this operation mathematically:

X0=[0110].[10]=[01]=1X|0\rangle=\begin{bmatrix}0&1\\1&0\end{bmatrix}.\begin{bmatrix}1 \\0\end{bmatrix} = \begin{bmatrix}0 \\1\end{bmatrix} = |1\rangle

X1=[0110].[01]=[10]=0X|1\rangle=\begin{bmatrix}0&1\\1&0\end{bmatrix}.\begin{bmatrix}0 \\1\end{bmatrix} = \begin{bmatrix}1 \\0\end{bmatrix} = |0\rangle

This was straightforward. However, we must also look at the effect of these gates on superposition states. Let’s take an arbitrary superposition state ϕ\phi and apply the XX gate on it:

ϕ=α0+β1|\phi\rangle=\alpha|0\rangle+\beta|1\rangle

Xϕ=[0110].[αβ]=[βα]=β0+α1X|\phi\rangle=\begin{bmatrix}0&1\\1&0\end{bmatrix}.\begin{bmatrix}\alpha \\\beta\end{bmatrix} = \begin{bmatrix}\beta \\\alpha\end{bmatrix} = \beta|0\rangle+\alpha|1\rangle

We can think of this as swapping the amplitudes of components in the superposition state.

Visually, we can think of an XX-gate operation as a rotation of π\pi radians around the X-axis of the Bloch sphere.

Applying X-gate on |0> to get |1> [Image via Qiskit]
Applying X-gate on |0> to get |1> [Image via Qiskit]

The Y gate

The Pauli-YY gate is defined as follows:

Y=[0ii0]Y=\begin{bmatrix}0&-i\\i&0\end{bmatrix}

The easiest way to understand this gate is by thinking of it as a rotation of π\pi radians across the Y-axis of the Bloch Sphere.

If you visualize this rotation in the 3-D space you’ll notice this gate also converts the 0|0\rangle state to 1|1\rangle and vice versa but there’s a slight difference. It applies a global phase to these states as well. Let’s have a look:

Y0=[0ii0].[10]=[0i]=i1Y|0\rangle=\begin{bmatrix}0&-i\\i&0\end{bmatrix}.\begin{bmatrix}1 \\0\end{bmatrix} = \begin{bmatrix}0 \\i\end{bmatrix} = i|1\rangle

Y1=[0ii0].[01]=[i0]=i0Y|1\rangle=\begin{bmatrix}0&-i\\i&0\end{bmatrix}.\begin{bmatrix}0 \\1\end{bmatrix} = \begin{bmatrix}-i \\0\end{bmatrix} = -i|0\rangle

Remember when we said we don’t really care about the global phase because it doesn’t matter during the measurement. The square of such a value like ii or i-i just turns out to be 1, which doesn’t affect the measurement properties at all. So, we can ignore the global phase. This gate can come in handy while dealing with superposition states, though.

Applying the Y-gate on |0> to get |1> [Image via Qiskit]
Applying the Y-gate on |0> to get |1> [Image via Qiskit]

The Z gate

It is also known as the phase-flip gate. It is defined as follows:

Z=[1001]Z=\begin{bmatrix}1&0\\0&-1\end{bmatrix}

Similar to the other two, this gate can be thought of as a rotation of π\pi radians across the ZZ-axis of the Bloch Sphere. It changes the phase of the 1|1\rangle state from +1+1 to 1-1 and vice versa. Let’s see how:

Z0=[1001].[10]=[10]=0Z|0\rangle=\begin{bmatrix}1&0\\0&-1\end{bmatrix}.\begin{bmatrix}1 \\0\end{bmatrix} = \begin{bmatrix}1 \\0\end{bmatrix} = |0\rangle

Z1=[0110].[01]=[01]=1Z|1\rangle=\begin{bmatrix}0&1\\1&0\end{bmatrix}.\begin{bmatrix}0 \\1\end{bmatrix} = \begin{bmatrix}0 \\-1\end{bmatrix} = -|1\rangle

Again, you might notice that the 1-1 is the global phase for the resultant state, so we don’t really care about it. In terms of the Bloch sphere rotations, these states already lie on the ZZ-axis, so they remain unchanged as we saw above mathematically.

The key concept here lies when this gate is applied to a superposition state. Let’s take the example of the +|+\rangle state.

+=120+121|+\rangle = \frac{1}{\sqrt{2}}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle

Z+=[1001].[1212]Z|+\rangle=\begin{bmatrix}1&0\\0&-1\end{bmatrix}.\begin{bmatrix}\frac{1}{\sqrt{2}} \\\frac{1}{\sqrt{2}}\end{bmatrix}

Z+=[1212]Z|+\rangle = \begin{bmatrix}\frac{1}{\sqrt{2}} \\-\frac{1}{\sqrt{2}}\end{bmatrix}

Z+=120121Z|+\rangle = \frac{1}{\sqrt{2}}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle

The phase flip on the 1|1\rangle component resulted in a relative phase of -1. This converted the +|+\rangle into the |-\rangle. We can verify this by looking at the rotation on the Bloch Sphere as well.

Applying Z-gate on |+> to get |-> [Image via Qiskit]
Applying Z-gate on |+> to get |-> [Image via Qiskit]

The Hadamard gate

You’ve been waiting a long time for this. We’ve been looking at superposition states since the start. Now the time has come when we finally see how to create a superposition state in the first place.

The Hadamard gate HH creates an equal superposition state when applied to the 0|0\rangle or 1|1\rangle state. Let’s see it in action. It is defined as follows:

H=12[1111]H=\frac{1}{\sqrt{2}}\begin{bmatrix}1&1\\1&-1\end{bmatrix}

Applying it to the states 0|0\rangle and 1|1\rangle gives us the following:

H0=12[1111].[10]=[1212]=+H|0\rangle=\frac{1}{\sqrt{2}}\begin{bmatrix}1&1\\1&-1\end{bmatrix}.\begin{bmatrix}1 \\0\end{bmatrix} = \begin{bmatrix}\frac{1}{\sqrt{2}} \\\frac{1}{\sqrt{2}}\end{bmatrix} = |+\rangle

H1=12[1111].[01]=[1212]=H|1\rangle=\frac{1}{\sqrt{2}}\begin{bmatrix}1&1\\1&-1\end{bmatrix}.\begin{bmatrix}0 \\1\end{bmatrix} = \begin{bmatrix}\frac{1}{\sqrt{2}} \\-\frac{1}{\sqrt{2}}\end{bmatrix} = |-\rangle

This was straightforward, now let’s look at something even more interesting. We’ll have our first look at destructive interference in play. We know that these gates are reversible, so if we apply the Hadamard again to the results above, we should get back to 0|0\rangle and 1|1\rangle.

This really becomes clear when we look at this in bra-ket notation. The matrix multiplication method was pretty simple to follow. Let’s start by applying the first Hadamard in bra-ket notation.

H0=+=120+121H|0\rangle=|+\rangle=\frac{1}{\sqrt{2}}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle

Now let’s apply the second Hadamard to the resultant state. It’ll simply act on individual components of the superposition state.

H+=12 H0+12 H1H|+\rangle=\frac{1}{\sqrt{2}}\space H|0\rangle + \frac{1}{\sqrt{2}}\space H|1\rangle

H+=12[120+121]+12 [120121]H|+\rangle=\frac{1}{\sqrt{2}}\begin{bmatrix}\frac{1}{\sqrt{2}}|0\rangle + \frac{1}{\sqrt{2}}|1\rangle\end{bmatrix} + \frac{1}{\sqrt{2}}\space \begin{bmatrix}\frac{1}{\sqrt{2}}|0\rangle - \frac{1}{\sqrt{2}}|1\rangle\end{bmatrix}

H+=120+121+120121H|+\rangle=\frac{1}{{2}}|0\rangle + \frac{1}{{2}}|1\rangle +\frac{1}{{2}}|0\rangle - \frac{1}{{2}}|1\rangle

H+=120+120H|+\rangle=\frac{1}{{2}}|0\rangle + \frac{1}{{2}}|0\rangle

H+=0H|+\rangle=|0\rangle

What you just witnessed here was the maths behind interference in quantum mechanics. The 1|1\rangle components had an opposite relative phase, +1+1 and 1-1, so they canceled each other out, and only the 0|0\rangle component was left. It’s beautiful how this simple mathematical expression can explain the complex nature of the interference phenomenon.

We can also visualize the Hadamard operation on the Bloch Sphere. It is equivalent to a rotation of π\pi radian about the ZZ-axis followed by a rotation of π2\frac{\pi}{{2}} about the YY-axis.

Applying H-gate on |0> to get |+> [Image via Qiskit]
Applying H-gate on |0> to get |+> [Image via Qiskit]