7  Quantum Circuits

In the previous chapters, we learned the basics on how to construct a quantum computer. We will now start constructing quantum circuits from these. Note that we will no longer look into probabilistic system.

The quantum systems which we consider in the following sections consist of qubits, unless specified otherwise. A qubit is a quantum state \(\psi\) with \(\psi \in \mathbb{C}^2\).

7.1 Visual language

So far we have only seen the elements of quantum computers in a mathematical form. When constructing quantum circuits, this can get very unreadable very fast. Therefore we can draw quantum circuits as a picture, which also helps us to get a better intuition for these circuits. You can see a very simple example here:

A basic quantum circuit

In this circuit we have two qubits, which are drawn as separate wires. We first apply the unitary \(X\) on the top wire and at the same time we apply the unitary \(H\) at the bottom wire. Mathematically this can be written as \(X\otimes H\). Next we apply the unitary \(U\), which operates on both qubits. After this, we apply a unitary \(H\) on the bottom wire. Since we do not apply anything on the top wire, we can write this mathematically as \(I\otimes H\). Finally we measure the top qubit. This means a complete measurement in the computational basis of the qubit as described in Section 4.2.

7.2 Important gates

When working with quantum computers, we encounter some of the same unitaries very often. We distinguish between single qubit gates (unitary transformations \(\in \mathbb{C}^{2\times 2}\)) and gates on multiple qubits.

7.2.1 Single qubit gates

The following gates are relevant single qubit gates:

Definition 7.1 (Pauli matrices) The Pauli matrices \(X,Y\) and \(Z\) are defined as \[ \begin{aligned} X=\begin{pmatrix} 0 & 1 \\ 1 & 0\end{pmatrix} && Y=\begin{pmatrix} 0 & -i \\ i & 0\end{pmatrix} && Z=\begin{pmatrix} 1 & 0 \\ 0 & -1\end{pmatrix} \end{aligned} \]

Note that \(X\) is also called bit-flip.

Definition 7.2 (Hadamard gate) The Hadamard gate \(H\) is defined as \[ \begin{aligned} H=\frac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1\end{pmatrix} \end{aligned} \]

The Hadamard gate is useful for introducing superpositions as it takes a classical bit \(\begin{pmatrix} 1 \\ 0 \end{pmatrix}\) and transforms it into a superposition \(\begin{pmatrix} \frac{1}{\sqrt{2}} \\ \frac{1}{\sqrt{2}} \end{pmatrix}\).

7.2.2 Controlled-NOT gate

The gates introduced above only operate on a single qubit. To connect two different qubits, we need gates which operate on multiple qubits. For this we introduce the controlled-not:

Definition 7.3 (Controlled-NOT gate) The controlled-NOT gate \(\operatorname{CNOT} \in \mathbb{C}^{4\times 4}\) is defined as \[ \begin{aligned} \operatorname{CNOT}=\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0\end{pmatrix} \end{aligned} \] The \(\operatorname{CNOT}\) gate flips the qubit of the second qubit if the first qubit is \(1\). We call the first wire the controlling wire and the second wire the target wire. It can be drawn in a quantum circuit as follows:

Controlled-NOT in a quantum circuit

If the second qubit should be the controlling wire and the first qubit the target wire, we can use \(\operatorname{CNOT}'\) denoted as \[ \begin{aligned} \operatorname{CNOT}'=\begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1 \\ 0 & 0 & 1 & 0 \\ 0 & 1 & 0 & 0\end{pmatrix} \end{aligned} \]

7.3 Ket Notation

So far we have only seen vectors as a way to mathematically describe a quantum state. This can get quite inconvenient if the vector get bigger and also often contains not that much useful information (e.g. a lot of \(0\) entries). We therefore introduce a new form of writing quantum states called the ket notation.

The idea works as follows: We can rewrite a quantum state \(\psi\) in the following way \[ \psi = \begin{pmatrix} \psi_1 \\ \psi_2 \\ \vdots \\ \psi_N \end{pmatrix} = \psi_1 \begin{pmatrix} 1 \\ 0 \\ \vdots \\ 0 \end{pmatrix} + \psi_2 \begin{pmatrix} 0 \\ 1 \\ \vdots \\ 0 \end{pmatrix} + \dots + \psi_N \begin{pmatrix} 0 \\ 0 \\ \vdots \\ 1 \end{pmatrix} = \sum_{i=1}^{N} \psi_i \cdot e_i \] The vector \(e_i\) denotes the vector with 0 entries at every position except the \(i\)-th position, where the entry is \(1\).

From this notation we already get an advantage, since we can drop out all \(0\) entries. But we still have no intuitive mapping from the vector \(e_i\) to the classical possibility represented by \(e_i\). For this we use a \(\ket{}\) symbol. More precise this means for a classical possibility \(x\), which is the \(i\)-th possibility and is represented by \(e_i\), we write \[ \ket{x}:= e_i = \begin{pmatrix} 0 \\ \vdots \\ 0 \\ 1 \\ 0 \\ \vdots \\ 0 \end{pmatrix} \leftarrow \text{1 at the $i$-th position} \]

Example: Ket notation

Given a quantum system with the classical possibilities \(00\), \(01\), \(10\) and \(11\), the quantum state \(\psi = \begin{pmatrix} \frac{1}{\sqrt{2}} & 0 & 0 & \frac{1}{\sqrt{2}} \end{pmatrix}^T\) can be written as \[ \psi = \begin{pmatrix} \frac{1}{\sqrt{2}} \\ 0 \\ 0 \\ \frac{1}{\sqrt{2}} \end{pmatrix} = \frac{1}{\sqrt{2}} \ket{00} + \frac{1}{\sqrt{2}} \ket{11} \]

Written like this, we can see at first glance that this is a superposition of the classical possibilities \(00\) and \(11\).

Note that the ket notation can also be used in a few other ways. We can use it as described above to describe the classical possibility \(x\) as \(\ket{x}\), but we also use it to emphasize that \(\psi\) is a quantum state by writing \(\ket{\psi}\) (here \(\psi\) is not a classical possibility). We also have two special cases \(\ket{+}\) and \(\ket{-}\) which are defined as follows: \[ \begin{aligned} \ket{+} &:= \frac{1}{\sqrt{2}} \ket{0} + \frac{1}{\sqrt{2}} \ket{1}\\ \ket{-} &:= \frac{1}{\sqrt{2}} \ket{0} - \frac{1}{\sqrt{2}} \ket{1} \end{aligned} \] Which of the meanings of the symbol \(\ket{}\) is meant has to be deduced from the context.