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 systems.

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 (i.e., as formulas). 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 \(\ket{0}\) and \(\ket{+}\), which are drawn as separate wires. Note that the symbol \(\ket{}\) is introduced in the next chapter, so just understand it as a name for some state at this point. We first apply the unitary \(X\) on the top wire to \(\ket{0}\) and at the same time we apply the unitary \(H\) at the bottom wire to \(\ket{+}\). Mathematically this can be written as \((X \otimes H)(\ket{0} \otimes \ket{+})\). 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. The meaning of the unitaries used is explained in the next section. A wire can contain multiple qubits, depending on the context.

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 (Identity matrix) The identity matrix \(I\) is defined as \[ \begin{aligned} I= \begin{pmatrix} 1 & 0 \\ 0 & 1\end{pmatrix}. \end{aligned} \]

This matrix is for example useful if a qubit/wire is to remain unchanged. The identity matrix also exists in other sizes.

Definition 7.2 (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.3 (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.4 (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} \] Accordingly, the quantum circuit is drawn the other way round.

Controlled-NOT’ in a quantum circuit

7.3 Teleportation

We are now looking at an example quantum circuit.

Example: Teleportation

Assumed: Alice has a qubit \(\psi\) and wants to send it to Bob. But only classic communication is possible, no quantum communication. However, they can share a state \(\beta_{00}\) beforehand.

Circuit for qubit teleportation
  1. Alice has the state \(\psi = \begin{pmatrix} \alpha \\ \beta \end{pmatrix}\) and the shared state is \(\beta_{00} = \begin{pmatrix} 1/\sqrt{2} \\ 0 \\ 0 \\ 1/\sqrt{2} \end{pmatrix}\). This means that the entire state is \[ \phi_1 = \psi \otimes \beta_{00} = \begin{pmatrix} \alpha \\ \beta \end{pmatrix} \otimes \begin{pmatrix} 1 \\ 0 \\ 0 \\ 1 \end{pmatrix}/\sqrt{2} = \begin{pmatrix} \alpha \\ 0 \\ 0 \\ \alpha \\ \beta \\ 0 \\ 0 \\ \beta \end{pmatrix}/\sqrt{2}. \]

  2. The CNOT can be extended to \(\operatorname{CNOT} \otimes \operatorname{I}_2\) using the identity matrix: \[ \phi_2 = (\operatorname{CNOT} \otimes \operatorname{I}_2) \phi_1 = \begin{pmatrix} 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} \end{pmatrix} \begin{pmatrix} \alpha \\ 0 \\ 0 \\ \alpha \\ \beta \\ 0 \\ 0 \\ \beta \end{pmatrix}/\sqrt{2} = \begin{pmatrix} \alpha \\ 0 \\ 0 \\ \alpha \\ 0 \\ \beta \\ \beta \\ 0 \end{pmatrix}/\sqrt{2}. \]

  3. Identical to step 2, the Hadamard gate can be extended with the identity matrix: \[ \phi_3 = (\operatorname{H} \otimes \operatorname{I}_4) \phi_2 = \begin{pmatrix} 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 \\ 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & -1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & -1 & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & -1 & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & -1 \end{pmatrix} /\sqrt{2} \begin{pmatrix} \alpha \\ 0 \\ 0 \\ \alpha \\ 0 \\ \beta \\ \beta \\ 0 \end{pmatrix}/\sqrt{2} = \begin{pmatrix} \alpha \\ \beta \\ \beta \\ \alpha \\ \alpha \\ -\beta \\ -\beta \\ \alpha \end{pmatrix}/2. \]

  4. Here we assume that \(a=0\) and \(b=1\). It applies \(|\alpha|^2 + |\beta|^2 = 1\) because \(\psi\) is a quantum state. Therefore the probability for this is \[ \left|\frac{\beta}{2}\right|^2 + \left|\frac{\alpha}{2}\right|^2 = \frac{|\alpha|^2 + |\beta|^2}{4} = \frac{1}{4} \] and the post-measurement-state \[ \phi_4 = \begin{pmatrix} 0 \\ 0 \\ \beta \\ \alpha \\ 0 \\ 0 \\ 0 \\ 0 \end{pmatrix}/2 / \sqrt{\tfrac{1}{4}} = \begin{pmatrix} 0 \\ 0 \\ \beta \\ \alpha \\ 0 \\ 0 \\ 0 \\ 0 \end{pmatrix}. \]

  5. Since \(b = 1\), the Pauli-matrix \(\operatorname{X}\) is used: \[ \phi_5 = (\operatorname{I}_4 \otimes \operatorname{X}) \phi_4 = \begin{pmatrix} \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 \\ \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & \textcolor{gray}{0} & 1 & \textcolor{gray}{0} \end{pmatrix} \begin{pmatrix} 0 \\ 0 \\ \beta \\ \alpha \\ 0 \\ 0 \\ 0 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \\ \alpha \\ \beta \\ 0 \\ 0 \\ 0 \\ 0 \end{pmatrix}. \]

  6. Since \(a = 0\), nothing happens in this step: \[ \phi_6 = \phi_5 = \begin{pmatrix} 0 \\ 0 \\ \alpha \\ \beta \\ 0 \\ 0 \\ 0 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} \otimes \begin{pmatrix} \alpha \\ \beta \end{pmatrix} = \begin{pmatrix} 0 \\ 1 \\ 0 \\ 0 \end{pmatrix} \otimes \psi. \]

So now Bob is aware of \(\psi\) and Alice has the now useless state \(\begin{pmatrix} 0 & 1 & 0 & 0 \end{pmatrix}^T\). Note that Bob would also have \(\psi\) for all other results of \(a\) and \(b\).