|
8 | 8 | }
|
9 | 9 | },
|
10 | 10 | "source": [
|
11 |
| - "[<img src=\"images/quantum_algorithms_tutorials.png\" alt=\"drawing\" width=\"100\" align=\"left\"/>][5]\n", |
| 11 | + "[<img src=\"images/quantum_algorithms_tutorials.png\" alt=\"drawing\" width=\"100\" align=\"left\" />][5]\n", |
12 | 12 | "\n",
|
13 | 13 | "<h2 align=\"center\">\n",
|
14 | 14 | "Quantum parallelism and Deutsch–Jozsa algorithm\n",
|
15 | 15 | "</h2>\n",
|
16 | 16 | "\n",
|
17 |
| - "**[[Homepage][5]]**\\\n", |
18 |
| - "**[[Open with the nbviewer.][6]]**\n", |
| 17 | + "**[[Homepage][5]]**\n", |
| 18 | + "**[[Open with the nbviewer][6]]**\n", |
19 | 19 | "\n",
|
20 | 20 | "<h3 align=\"left\">\n",
|
21 | 21 | "1. Quantum parallelism\n",
|
22 | 22 | "</h3>\n",
|
23 | 23 | "\n",
|
24 |
| - "In this tutorial, we are going to introduce 3 separate problems and we will mainly follow the [[1]] book's approach of describing them. After giving descriptions we will implement them with Qiskit. So, let's start with quantum parallelism, which is one of the powerful tools/properties that is used in the quantum computers. Quantum parallelism enables us to simultaneously compute the outputs of a function for given different inputs. Let's say we have two registers one for input the other one for output. The initial state is given by $\\left| x \\right\\rangle \\left| 0 \\right\\rangle$ wavefunction, where $\\left| x \\right\\rangle$ is the register that takes $x$ input and $\\left| 0 \\right\\rangle$ is the output register where the value of the $f(x)$ function will be stored. After applying the circuit that corresponds to the given function the wavefunction becomes $\\left| x \\right\\rangle \\left| f(x) \\right\\rangle$. Here is the circuit:\n", |
| 24 | + "In this tutorial, we are going to introduce 3 separate problems and we will mainly follow the [[1]] book's approach of describing them. After giving descriptions we will implement them with Qiskit. So, let's start with quantum parallelism, which is one of the powerful tools/properties that are used in the quantum computation. Quantum parallelism enables us to simultaneously compute (with some caveats) the outputs of a function for given different inputs. \n", |
| 25 | + "\n", |
| 26 | + "Suppose we have two registers one for the input the other one for the output. The initial state is given by $\\left| x \\right\\rangle \\left| 0 \\right\\rangle$ combined state of the two quantum registers, where $\\left| x \\right\\rangle$ is the register that takes $x$ input and $\\left| 0 \\right\\rangle$ is the output register where the value of the $f(x)$ function will be stored. After applying the circuit that corresponds to the given function the combined state is equal to $\\left| x \\right\\rangle \\left| f(x) \\right\\rangle$. Here is the circuit:\n", |
25 | 27 | "\n",
|
26 | 28 | "<img src=\"images/qparallel.png\" alt=\"drawing\" width=\"300\"/>\n",
|
27 | 29 | "\n",
|
28 |
| - "The $U_{f(x)}$ is the unitary operator that acts on both registers and corresponds to the given $f(x)$ function. Let's see what happens when instead of one $\\left| x \\right\\rangle$ bit string, we have a superposition state of all possible bit strings:\n", |
| 30 | + "The $U_{f(x)}$ is the unitary operator that acts on both registers and does the described transformation. Let's see what happens when instead of one $\\left| x \\right\\rangle$ bit string, we have a superposition state of all possible bit strings:\n", |
29 | 31 | "\n",
|
30 | 32 | "$$\\frac{1}{2}\\sum_{x} \\left| x \\right\\rangle = \\frac{1}{2} \\left[ \\left| 00 \\right\\rangle + \\left| 01 \\right\\rangle + \\left| 10 \\right\\rangle + \\left| 11 \\right\\rangle \\right]$$\n",
|
31 | 33 | "\n",
|
32 |
| - "The coefficient in front of the state is for normalization (sum of all bit string probabilities in the superposition state must be unity). This superposition state will let us witness the quantum parallelism in action. Now let's write down the combined state of two registers:\n", |
| 34 | + "The coefficient $\\frac{1}{2}$ is for the normalization of the state (sum of all bit string probabilities in the superposition state must be unity). This superposition state will let us witness the quantum parallelism in action. Now let's write down the initial state of the two registers:\n", |
33 | 35 | "\n",
|
34 | 36 | "$$\\left| \\psi_{initial} \\right\\rangle = \\frac{1}{2} \\left| 0 \\right\\rangle \\sum_{x} = \\frac{1}{2} \\left[ \\left| 0 \\right\\rangle \\left| 00 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 01 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 10 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 11 \\right\\rangle \\right]$$\n",
|
35 | 37 | "\n",
|
36 |
| - "After $U_{f(x)}$ unitary operator the state will look like this:\n", |
| 38 | + "After $U_{f(x)}$ unitary operator:\n", |
37 | 39 | "\n",
|
38 | 40 | "$$\\left| \\psi_{final} \\right\\rangle = \\frac{1}{2} \\left[ \\left| f(00) \\right\\rangle \\left| 00 \\right\\rangle + \\left| f(01) \\right\\rangle \\left| 01 \\right\\rangle + \\left| f(10) \\right\\rangle \\left| 10 \\right\\rangle + \\left| f(11) \\right\\rangle \\left| 11 \\right\\rangle \\right]$$\n",
|
39 | 41 | "\n",
|
40 |
| - "We are already there. So, we have applied one $U_{f(x)}$ unitary operator, but, in fact, the $f(x)$ function was evaluated 4 times for each term from the superposition state. This effect is called quantum parallelism, and this quantum computing \"tool\" is widely used in lots of quantum algorithms. Let see how it works for some specific function. Suppose we have a function that for those $\\left| x \\right\\rangle$ bit strings that have even number of $1$s the function $f(x) = 0$ and when the number of $1$s is odd the function $f(x) = 1$. To make things more interesting we will use $3$ qubits for the input register. Here is the circuit:\n", |
| 42 | + "We are already there. So, we have applied one $U_{f(x)}$ unitary operator, but, in fact, the $f(x)$ function was evaluated 4 times for each term from the superposition state. This effect is called quantum parallelism, and this quantum computing \"tool\" is widely used in lots of quantum algorithms. Let see how it works for some specific function. Suppose we have a function that for those $\\left| x \\right\\rangle$ bit strings that have even number of $1$s the function $f(x) = 0$ and when the number of $1$s is odd the function $f(x) = 1$ (parity function). To make things more interesting we will use 3 qubits for the input register. Here is the circuit:\n", |
41 | 43 | "\n",
|
42 | 44 | "<img src=\"images/qparallel_example.png\" alt=\"drawing\" width=\"400\"/>\n",
|
43 | 45 | "\n",
|
44 |
| - "where $i$ indices denote the input qubits and $o$ denotes the output qubit. Here the first 3 Hadamard gates are for preparing a $3$ qubit superposition state. The CNOT gates represent our given function $f(x)$ that has an output $0$ if there are even number of $1$s in the input register and $1$ otherwise. Now let's go step by step and see how the quantum state changes. The initial $\\left| \\psi_{0} \\right\\rangle$ quantum state:\n", |
| 46 | + "where $i$ indices denote the input qubits and $o$ denotes the output qubit. Here the first 3 Hadamard gates are for preparing a 3 qubit superposition state with equal probabilities. The CNOT gates combined represent our given function $f(x)$ (unitary $U_{f(x)}$) that has an output $0$ if there are even number of $1$s in the input register and $1$ otherwise. Now let's go step by step and see how the quantum state changes and check if the given circuit implements the desired transformation. The initial $\\left| \\psi_{0} \\right\\rangle$ quantum state:\n", |
45 | 47 | "\n",
|
46 | 48 | "$$\\left| \\psi_{0} \\right\\rangle = \\left| 0 \\right\\rangle_o \\left| 000 \\right\\rangle_i$$\n",
|
47 | 49 | "\n",
|
48 |
| - "After 3 Hadamard gates the $\\left| \\psi_{1} \\right\\rangle$ quantum state looks like this (omitting the qubit indices):\n", |
| 50 | + "After 3 Hadamard gates we will have the $\\left| \\psi_{1} \\right\\rangle$ quantum state (omitting the qubit indices):\n", |
49 | 51 | "\n",
|
50 |
| - "$$\\left| \\psi_{1} \\right\\rangle = \\frac{1}{\\sqrt{2^3}}\\left| 0 \\right\\rangle \\left[ \\left| 000 \\right\\rangle + \\left| 001 \\right\\rangle + \\left| 010 \\right\\rangle + \\left| 011 \\right\\rangle + \\left| 100 \\right\\rangle + \\left| 101 \\right\\rangle + \\left| 110 \\right\\rangle + \\left| 111 \\right\\rangle \\right]$$\n", |
| 52 | + "\\begin{align*}\n", |
| 53 | + "\\left| \\psi_{1} \\right\\rangle = \\frac{1}{\\sqrt{2^3}}\\left| 0 \\right\\rangle &\\big[ \\left| 000 \\right\\rangle + \\left| 001 \\right\\rangle + \\left| 010 \\right\\rangle + \\left| 011 \\right\\rangle +\n", |
| 54 | + "\\\\\n", |
| 55 | + "&+ \\left| 100 \\right\\rangle + \\left| 101 \\right\\rangle + \\left| 110 \\right\\rangle + \\left| 111 \\right\\rangle \\big]\n", |
| 56 | + "\\end{align*}\n", |
51 | 57 | "\n",
|
52 |
| - "Or in more compact form:\n", |
| 58 | + "Or in a more compact form:\n", |
53 | 59 | "\n",
|
54 | 60 | "$$\\left| \\psi_{1} \\right\\rangle = \\frac{1}{\\sqrt{2^3}}\\left| 0 \\right\\rangle \\sum_x \\left| x \\right\\rangle,$$\n",
|
55 | 61 | "\n",
|
|
95 | 101 | "\n",
|
96 | 102 | "Or in a more explicit form:\n",
|
97 | 103 | "\n",
|
98 |
| - "$$\\left| \\psi_2 \\right\\rangle = \\frac{1}{\\sqrt{2^3}} \\left[ \\left| 0 \\right\\rangle \\left| 000 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 001 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 010 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 011 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 100 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 101 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 110 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 111 \\right\\rangle \\right]$$\n", |
| 104 | + "\\begin{align*}\n", |
| 105 | + "\\left| \\psi_2 \\right\\rangle = \\frac{1}{\\sqrt{2^3}} \\big[ \\left| 0 \\right\\rangle \\left| 000 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 001 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 010 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 011 \\right\\rangle +\n", |
| 106 | + "\\\\\n", |
| 107 | + "+ \\left| 1 \\right\\rangle \\left| 100 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 101 \\right\\rangle + \\left| 0 \\right\\rangle \\left| 110 \\right\\rangle + \\left| 1 \\right\\rangle \\left| 111 \\right\\rangle \\big]\n", |
| 108 | + "\\end{align*}\n", |
99 | 109 | "\n",
|
100 |
| - "To check this calculation one should know the action of CNOT gate. For example, if CNOT is acting on an arbitrary two-qubit state $a \\left| 00 \\right\\rangle + b \\left| 01 \\right\\rangle + c \\left| 10 \\right\\rangle + d \\left| 11 \\right\\rangle$, where $a$, $b$, $c$ and $d$ are some arbitrary complex numbers that satisfy $\\left| a \\right|^2 + \\left| b \\right|^2 + \\left| c \\right|^2 + \\left| d \\right|^2 = 1$ (normalization). After acting CNOT gate, that is controlled from the first qubit, we will obtain the following state $\\left| 00 \\right\\rangle + b \\left| 01 \\right\\rangle + c \\left| 11 \\right\\rangle + d \\left| 10 \\right\\rangle$, where we changed the second qubit state when the first qubit was in $\\left|1\\right\\rangle$ state.\n", |
| 110 | + "So, it is easy to check that the circuit implements the described $f(x)$ parity function. To check this calculation one should know the action of CNOT gate. For example, if CNOT is acting on an arbitrary two-qubit state $a \\left| 00 \\right\\rangle + b \\left| 01 \\right\\rangle + c \\left| 10 \\right\\rangle + d \\left| 11 \\right\\rangle$, where $a$, $b$, $c$ and $d$ are some arbitrary complex numbers that satisfy $\\left| a \\right|^2 + \\left| b \\right|^2 + \\left| c \\right|^2 + \\left| d \\right|^2 = 1$ (normalization). After applying CNOT gate controlled from the first qubit, we will obtain the following state $\\left| 00 \\right\\rangle + b \\left| 01 \\right\\rangle + c \\left| 11 \\right\\rangle + d \\left| 10 \\right\\rangle$, where we changed the second qubit state when the first qubit was in $\\left|1\\right\\rangle$ state.\n", |
101 | 111 | "\n",
|
102 | 112 | "Now let's write a code for this circuit:\n",
|
103 | 113 | "\n",
|
|
0 commit comments