|
14 | 14 | "Quantum parallelism and Deutsch–Jozsa algorithm\n",
|
15 | 15 | "</h2>\n",
|
16 | 16 | "\n",
|
17 | | - "[**Open with the *nbviewer*.**](https://nbviewer.jupyter.org/github/DavitKhach/quantum-algorithms-tutorials/blob/master/quantum_parallelism_Deutsch_Jozsa.ipynb)\n", |
| 17 | + "[Open with the nbviewer.](https://nbviewer.jupyter.org/github/DavitKhach/quantum-algorithms-tutorials/blob/master/quantum_parallelism_Deutsch_Jozsa.ipynb)\n", |
18 | 18 | "\n",
|
19 | 19 | "<h3 align=\"left\">\n",
|
20 | 20 | "Quantum parallelism\n",
|
21 | 21 | "</h3>\n",
|
22 | 22 | "\n",
|
23 | | - "In this tutorial, we are going to introduce 3 separate problems and we will mainly follow the [[1](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)] 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", |
| 23 | + "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 | 24 | "\n",
|
25 | 25 | "<img src=\"images/qparallel.png\" alt=\"drawing\" width=\"300\"/>\n",
|
26 | 26 | "\n",
|
|
98 | 98 | "\n",
|
99 | 99 | "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",
|
100 | 100 | "\n",
|
101 | | - "Now let's write a code for this circuit:" |
| 101 | + "Now let's write a code for this circuit:\n", |
| 102 | + "\n", |
| 103 | + " [1]: https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB\n", |
| 104 | + " [2]: https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie\n", |
| 105 | + " [3]: https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s\n", |
| 106 | + " [4]: https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/" |
102 | 107 | ]
|
103 | 108 | },
|
104 | 109 | {
|
|
210 | 215 | "Deutsch's algorithm\n",
|
211 | 216 | "</h3>\n",
|
212 | 217 | "\n",
|
213 | | - "In the Deutsch algorithm, we are solving a problem with two qubits. The problem can be described this way [[1](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)]: Alice and Bob live in different cities and they are playing a \"funny\" game. Alice prepares her qubits and sends them to Bob. Bob applies a function on Alice's qubits and sends them back to Alice. Bob is allowed to choose only one of the 4 possible functions, that are either constant ($f(0) = f(1)$) or balanced ($f(0) \\ne f(1)$), and input and output of the function is one bit (0ドル$ or 1ドル$). Alice should find out from the measurment result was the chosen function balanced or constant. In the course of this algorithm, we will use the concept of quantum parallelism. Here is the circuit for the algorithm (a modified version of the Fig. 1.19 from [[1](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)]):\n", |
| 218 | + "In the Deutsch algorithm, we are solving a problem with two qubits. The problem can be described this way [[1]]: Alice and Bob live in different cities and they are playing a \"funny\" game. Alice prepares her qubits and sends them to Bob. Bob applies a function on Alice's qubits and sends them back to Alice. Bob is allowed to choose only one of the 4 possible functions, that are either constant ($f(0) = f(1)$) or balanced ($f(0) \\ne f(1)$), and input and output of the function is one bit (0ドル$ or 1ドル$). Alice should find out from the measurment result was the chosen function balanced or constant. In the course of this algorithm, we will use the concept of quantum parallelism. Here is the circuit for the algorithm (a modified version of the Fig. 1.19 from [[1]]):\n", |
214 | 219 | "\n",
|
215 | 220 | "<img src=\"images/Deutsch.png\" alt=\"drawing\" width=\"500\"/>\n",
|
216 | 221 | "\n",
|
|
301 | 306 | "\n",
|
302 | 307 | "One can see that if the function is constant (the first two cases) the qubit in the input register is in the $\\left| 0 \\right\\rangle$ state and if the function is balanced (the last two cases) the qubit is in the $\\left| 1 \\right\\rangle$ state. Here we encounter one more useful property of quantum computation called quantum interference. It arises from the fact that probability amplitudes are complex numbers and they can be subtracted from (added to) each other (in our example: destructive interference $ \\left| 0 \\right\\rangle - \\left| 0 \\right\\rangle = (1 - 1) \\left| 0 \\right\\rangle = 0$; constructive interference $ \\left| 0 \\right\\rangle + \\left| 0 \\right\\rangle = (1 + 1) \\left| 0 \\right\\rangle = 2 \\left| 0 \\right\\rangle$). Like the quantum parallelism, quantum interference also is a tool that exists in the arsenal of quantum computers that has no equivalent in classical computation.\n",
|
303 | 308 | "\n",
|
304 | | - "Now we are ready to code. In the code, we will implement all 4 possible functions and let Bob choose what he likes (actually we will choose one of the circuits randomly in order to simulate free will of the imaginary person Bob XD). But, before that Alice should prepare the qubits:" |
| 309 | + "Now we are ready to code. In the code, we will implement all 4 possible functions and let Bob choose what he likes (actually we will choose one of the circuits randomly in order to simulate free will of the imaginary person Bob XD). But, before that Alice should prepare the qubits:\n", |
| 310 | + "\n", |
| 311 | + " [1]: https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB\n", |
| 312 | + " [2]: https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie\n", |
| 313 | + " [3]: https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s\n", |
| 314 | + " [4]: https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/" |
305 | 315 | ]
|
306 | 316 | },
|
307 | 317 | {
|
|
518 | 528 | "cell_type": "markdown",
|
519 | 529 | "metadata": {},
|
520 | 530 | "source": [
|
521 | | - "Note that if Alice and Bob will choose to play their \"game\" not with a quantum computer, but with a classical computer, Alice will need to send two different sets of bits to figure out is Bob's function balanced or not. Moreover, Bob should do execution of the $f(x)$ function for both cases separately. With the quantum computer as we already have seen one execution of $f(x)$ is enough. This seems not a big deal, but suppose that the cost of running the $f(x)$ function is 1ドルm$ dollars [[3](https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s)] (Bob rents some computation time from some company that has quantum computers and classical computers). If they are using quantum computer Bob will spend only 1ドルm$ dollars, and if they use the classical computer they will spend 2ドルm$ dollars. In this sense, the quantum computer is preferable than the classical one for playing this \"game\". So, in this way, the Deutsch algorithm shows us the possible advantages that we can obtain from using quantum computers. The demonstration of the advantage described here comes from two main sources: quantum parallelism and quantum interference." |
| 531 | + "Note that if Alice and Bob will choose to play their \"game\" not with a quantum computer, but with a classical computer, Alice will need to send two different sets of bits to figure out is Bob's function balanced or not. Moreover, Bob should do execution of the $f(x)$ function for both cases separately. With the quantum computer as we already have seen one execution of $f(x)$ is enough. This seems not a big deal, but suppose that the cost of running the $f(x)$ function is 1ドルm$ dollars [[3]] (Bob rents some computation time from some company that has quantum computers and classical computers). If they are using quantum computer Bob will spend only 1ドルm$ dollars, and if they use the classical computer they will spend 2ドルm$ dollars. In this sense, the quantum computer is preferable than the classical one for playing this \"game\". So, in this way, the Deutsch algorithm shows us the possible advantages that we can obtain from using quantum computers. The demonstration of the advantage described here comes from two main sources: quantum parallelism and quantum interference.\n", |
| 532 | + "\n", |
| 533 | + " [1]: https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB\n", |
| 534 | + " [2]: https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie\n", |
| 535 | + " [3]: https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s\n", |
| 536 | + " [4]: https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/" |
522 | 537 | ]
|
523 | 538 | },
|
524 | 539 | {
|
|
529 | 544 | "The Deutsch-Jozsa algorithm\n",
|
530 | 545 | "</h3>\n",
|
531 | 546 | "\n",
|
532 | | - "Deutsch-Jozsa algorithm is the $n$ qubit version of the Deutsch algorithm. The functions now take $n$ bit strings (e.g. \"0101011\") as an input and return one bit output (0ドル$ or 1ドル$). Bob still is allowed only to use either balanced or constant functions and Alice should find out the property of that function (is it constant or balanced). Bob has two options for constant functions (for all imput bit strings $x$ the $f(x) = 0$ or $f(x) = 1$) and $\\begin{pmatrix} 2^n \\\\ 2^{n - 1} \\end{pmatrix}$ options to choose a balanced function. The main steps of the algorithm are presented in the following circuit (a modified version of the Fig.1.20 from the [[1](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)]):\n", |
| 547 | + "Deutsch-Jozsa algorithm is the $n$ qubit version of the Deutsch algorithm. The functions now take $n$ bit strings (e.g. \"0101011\") as an input and return one bit output (0ドル$ or 1ドル$). Bob still is allowed only to use either balanced or constant functions and Alice should find out the property of that function (is it constant or balanced). Bob has two options for constant functions (for all imput bit strings $x$ the $f(x) = 0$ or $f(x) = 1$) and $\\begin{pmatrix} 2^n \\\\ 2^{n - 1} \\end{pmatrix}$ options to choose a balanced function. The main steps of the algorithm are presented in the following circuit (a modified version of the Fig.1.20 from the [[1]]):\n", |
533 | 548 | "\n",
|
534 | 549 | "<img src=\"images/Deutsch_Jozsa.png\" alt=\"drawing\" width=\"600\"/>\n",
|
535 | 550 | "\n",
|
536 | | - "where $\\left| 0 \\right\\rangle^{\\otimes n},ドル means that we have $n$ qubits in the input register, $H^{\\otimes n}$ means applying $n$ Hadamard gates on each qubit in that register, $M^{\\otimes n}$ is $n$ measurements executed on $n$ (all) qubits. As you can see the circuit is very similar to the circuit from Deutsch algorithm. Now we will go through the steps of the Deutsch-Jozsa algorithm. After $n$ Hadamard gates applied on the input register and one Hadamard gate applied on the output register we will have [[1](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)]:\n", |
| 551 | + "where $\\left| 0 \\right\\rangle^{\\otimes n},ドル means that we have $n$ qubits in the input register, $H^{\\otimes n}$ means applying $n$ Hadamard gates on each qubit in that register, $M^{\\otimes n}$ is $n$ measurements executed on $n$ (all) qubits. As you can see the circuit is very similar to the circuit from Deutsch algorithm. Now we will go through the steps of the Deutsch-Jozsa algorithm. After $n$ Hadamard gates applied on the input register and one Hadamard gate applied on the output register we will have [[1]]:\n", |
537 | 552 | "\n",
|
538 | 553 | "$$\n",
|
539 | 554 | "\\left| \\psi_1 \\right\\rangle = \\frac{1}{\\sqrt{2^n}} \\sum_{x} \\left| x \\right\\rangle \n",
|
|
566 | 581 | "\\left| - \\right\\rangle\n",
|
567 | 582 | "$$\n",
|
568 | 583 | "\n",
|
569 | | - "Now the qubits are back to Alice. She applies Hadamard gates on the input register and obtains in the input register $H^{\\otimes n} \\frac{1}{\\sqrt{2^n}}\\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle$. This is enough to calculate what is the probability of measuring $\\left|00...0 \\right\\rangle = \\left| 0^{\\otimes n} \\right\\rangle$ state, that will indicate whether the function is balanced or constant. For that, firstly, we should take the inner product of $\\left| 0^{\\otimes n} \\right\\rangle$ state and $H^{\\otimes n} \\frac{1}{\\sqrt{2^n}}\\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle$ state (similar to [[4](https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/)]):\n", |
| 584 | + "Now the qubits are back to Alice. She applies Hadamard gates on the input register and obtains in the input register $H^{\\otimes n} \\frac{1}{\\sqrt{2^n}}\\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle$. This is enough to calculate what is the probability of measuring $\\left|00...0 \\right\\rangle = \\left| 0^{\\otimes n} \\right\\rangle$ state, that will indicate whether the function is balanced or constant. For that, firstly, we should take the inner product of $\\left| 0^{\\otimes n} \\right\\rangle$ state and $H^{\\otimes n} \\frac{1}{\\sqrt{2^n}}\\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle$ state (similar to [[4]]):\n", |
570 | 585 | "\n",
|
571 | 586 | "\\begin{equation*}\n",
|
572 | 587 | "\\left\\langle 0^{\\otimes n} \\right| H^{\\otimes n} \\frac{1}{\\sqrt{2^n}} \\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle = \\frac{1}{2^n}\\sum_{y} \\left\\langle y \\right| \\sum_{x} (-1)^{f(x)}\\left| x \\right\\rangle = \n",
|
|
577 | 592 | "\n",
|
578 | 593 | "For this procedure, Bob will need to execute the circuit that corresponds to the chosen function only one time (like in the Deutsch algorithm). Classical deterministic approach for this problem will require to execute $f(x)$ function 2ドル^{n-1} + 1$ times in the worst-case scenario. Thus Alice and Bob are happy with their quantum computer.\n",
|
579 | 594 | "\n",
|
580 | | - "For simplicity, in the implementation, we will allow Bob to use only two functions: one is a constant $f(x) = 1$ function, that can be implemented by applying $x$ gate on the output qubit, and the second one is the function that we have used in the quantum parallelism chapter that is actually an example of a balanced function. The implementation is done for 4 qubits:" |
| 595 | + "For simplicity, in the implementation, we will allow Bob to use only two functions: one is a constant $f(x) = 1$ function, that can be implemented by applying $x$ gate on the output qubit, and the second one is the function that we have used in the quantum parallelism chapter that is actually an example of a balanced function. The implementation is done for 4 qubits:\n", |
| 596 | + "\n", |
| 597 | + " [1]: https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB\n", |
| 598 | + " [2]: https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie\n", |
| 599 | + " [3]: https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s\n", |
| 600 | + " [4]: https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/" |
581 | 601 | ]
|
582 | 602 | },
|
583 | 603 | {
|
|
776 | 796 | "cell_type": "markdown",
|
777 | 797 | "metadata": {},
|
778 | 798 | "source": [
|
779 | | - "[1] [M.A. Nielsen, I.L. Chuang, Cambridge University Press New York, \"Quantum Computation and Quantum Information: 10th Anniversary Edition\n", |
780 | | - "10th\" (2011)](https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB)\n", |
| 799 | + "[[1]] [M.A. Nielsen, I.L. Chuang, Cambridge University Press New York, \"Quantum Computation and Quantum Information: 10th Anniversary Edition\n", |
| 800 | + "10th\" (2011)][1]\n", |
| 801 | + "\n", |
| 802 | + "[[2]] [A question about implementing four oracles for the Deutsch algorithm in the Quantum Computing Stack Exchange][2]\n", |
781 | 803 | "\n",
|
782 | | - "[2] [A question about implementing four oracles for the Deutsch algorithm in the Quantum Computing Stack Exchange](https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie)\n", |
| 804 | + "[[3]] [Video lecture \"24. Entanglement — QComputing, EPR, and Bell\" by Allan Adams: starting from 50:20 the Deutsch algorithm][3]\n", |
783 | 805 | "\n",
|
784 | | - "[3] [Video lecture \"24. Entanglement — QComputing, EPR, and Bell\" by Allan Adams: starting from 50:20 the Deutsch algorithm](https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s)\n", |
| 806 | + "[[4]] [edx course: Quantum Information Science I, Part 2][4]\n", |
785 | 807 | "\n",
|
786 | | - "[4] [edx course: Quantum Information Science I, Part 2](https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/)" |
| 808 | + " [1]: https://www.cambridge.org/am/academic/subjects/physics/quantum-physics-quantum-information-and-quantum-computation/quantum-computation-and-quantum-information-10th-anniversary-edition?format=HB\n", |
| 809 | + " [2]: https://quantumcomputing.stackexchange.com/questions/9566/implementing-four-oracles-for-the-deutsch-algorithm-preferably-on-ibm-q-experie\n", |
| 810 | + " [3]: https://www.youtube.com/watch?v=awpnsGl08bc&list=LLEPoMdv-DZViRaaObznY_-A&index=113&t=0s\n", |
| 811 | + " [4]: https://courses.edx.org/courses/course-v1:MITx+8.370.2x+1T2018/course/" |
787 | 812 | ]
|
788 | 813 | }
|
789 | 814 | ],
|
|
0 commit comments