{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"tags": [
"remove_cell"
]
},
"source": [
"# Quantum Circuits"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Contents\n",
"\n",
"1. [Introduction](#intro)\n",
"2. [What is a Quantum Circuit?](#whatis)\n",
"3. [Example: Quantum Teleportation](#teleportation)\n",
"4. [Example: Variational Quantum Eigensolvers](#vqe)\n",
"5. [Why the Classical Parts?](#why-classical)\n",
"\n",
"## 1. Introduction \n",
"\n",
"So far, we have seen various [single-qubit](https://qiskit.org/textbook/ch-states/single-qubit-gates.html) and [multi-qubit](https://qiskit.org/textbook/ch-gates/introduction.html) gates. We have also seen how to use these gates in concert with other components to build quantum circuits. \n",
"\n",
"Before implementing quantum algorithms on real quantum computers, it is important to highlight the definition of a quantum circuit concretely, as we will be building quantum circuits to implement these algorithms.\n",
"\n",
"\n",
"## 2. What is a Quantum Circuit? \n",
"\n",
"A quantum circuit is a computational routine consisting of _coherent quantum operations on quantum data, such as qubits, and concurrent real-time classical computation_. It is an ordered sequence of _quantum gates,_ _measurements and resets,_ all of which may be conditioned on and use data from the real-time classical computation. \n",
"\n",
"A set of quantum gates is said to be [universal](https://qiskit.org/textbook/ch-gates/proving-universality.html) if any unitary transformation of the quantum data can be efficiently approximated arbitrarily well as a sequence of gates in the set. Any quantum program can be represented by a sequence of quantum circuits and non-concurrent classical computation.\n",
"\n",
"## 3. Example: Quantum Teleportation \n",
"\n",
"Take a look at the quantum circuit below. You will learn later in this chapter that it implements [the quantum teleportation algorithm](https://qiskit.org/textbook/ch-algorithms/teleportation.html). For now, it suffices to look at the components of the quantum circuit.\n",
"\n",
"![Quantum Teleportation Labeled](images/teleportation_labelled.svg)\n",
"\n",
"The quantum circuit uses three qubits and two classical bits. There are four main components in this quantum circuit. \n",
"\n",
"### Initialization and reset\n",
"First, we need to start our quantum computation with a well-defined quantum state. This is achieved using the initialization and reset operations. The resets can be performed by a combination of single-qubit gates and concurrent real-time classical computation that monitors whether we have successfully created the desired state through measurements. The initialization of $q_0$ into a desired state $\\vert\\psi\\rangle$ can then follow by applying single-qubit gates.\n",
"\n",
"### Quantum gates\n",
"Second, we apply a sequence of quantum gates that manipulate the three qubits as required by the teleportation algorithm. In this case, we only need to apply single-qubit Hadamard ($H$) and two-qubit Controlled-X ($\\oplus$) gates. \n",
"\n",
"### Measurements\n",
"Third, we measure two of the three qubits. A classical computer interprets the measurements of each qubit as classical outcomes (0 and 1) and stores them in the two classical bits.\n",
"\n",
"### Classically conditioned quantum gates\n",
"Fourth, we apply single-qubit $Z$ and $X$ quantum gates on the third qubit. These gates are conditioned on the results of the measurements that are stored in the two classical bits. In this case, we are using the results of the classical computation concurrently in real-time within the same quantum circuit."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 4. Example: Variational Quantum Eigensolvers \n",
"\n",
"Here is an example of a quantum program. You will learn in following chapters that it implements a [variational quantum eigensolver](https://qiskit.org/textbook/ch-applications/vqe-molecules.html). In this program, a classical computer works _non-concurrently_ in concert with a quantum computer.\n",
"\n",
"![Variational Quantum Eigensolver Labeled](images/vqe-labeled.png)\n",
"\n",
"### The quantum block\n",
"As with the quantum teleportation example above, a quantum state $\\vert\\Psi(\\theta)\\rangle$ is prepared by a combination of resets with single- and multi-qubit quantum gates. Here, the parameters of the state are parametrized using the quantity $\\theta$. Once prepared, the quantum state is then manipulated using quantum gates and measured. All of the operations within the quantum block consist of quantum circuits.\n",
"\n",
"### The classical block\n",
"Once the quantum state has been measured, a classical computer interprets those measurement outcomes and computes their cost using a cost function that has been chosen for the intended application. Based on this cost, the classical computer determines another value for the parameter $\\theta$.\n",
"\n",
"### Combined operation\n",
"Once the classical computer determines the next parameter for $\\theta$, a sequence of resets, single- and multi-qubit quantum gates are used in a quantum circuit to prepare $\\vert\\Psi(\\theta)\\rangle$, and this process continues until the cost of the measured quantum states stabilizes, or until another pre-determined outcome is met."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 5. Why the Classical Parts? \n",
"\n",
"While a universal quantum computer can do anything any classical computer can, we often add classical parts to our quantum circuits because quantum states are fragile.\n",
"\n",
"When we measure the qubit, we collapse its state and destroy a lot of the information. Since all measurement does is destroy information, we can in theory always measure last and lose no computational advantage. In reality, measuring early offers many practical advantages.\n",
"\n",
"For example, in the teleportation circuit, we measure the qubits so we can send the information over classical channels instead of quantum channels. The advantage is that classical channels are very stable, while we donâ€™t really have a way of sending quantum information to other people since the channels are so difficult to create.\n",
"\n",
"In the variational quantum eigensolver example, splitting the computation up into smaller quantum computations actually loses us some computational advantage, but makes up for this on noisy hardware by reducing the time our qubits are in superposition. This means there is less chance interference will introduce inaccuracies in our results.\n",
"\n",
"Finally, to use the results of our quantum computation in our classical, everyday world, we need to measure and interpret these states at the end of our computation.\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}