|
15 | 15 | "source": [ |
16 | 16 | "\"Quantum Walk\" is an approach for developing and designing quantum algorithms. Consider it as a quantum analogy to the classical random walk. This generic technique underlies many quantum algorithms. In particular, the Grover's search algorithm can be viewed as a quantum walk.\n", |
17 | 17 | "\n", |
18 | | - "Similarly to classical random walks, quantum walks are divided into the discrete case and the continuous one. This notebook focuses on discrete quantum walks, and is organized as follows: first, [one to one](##Classical-Random-Walks-vs.-Quantum-Walks) compares classical random walks with quantum walks via a specific example: a walk on a circle. Then, a [general quantum model](##How-to-Build-a-general-Quantum-Walk-with-Classiq) studies quantum walks and subsequently applies it to the [circle case](##Example:-Symmetric-Quantum-Walk-on-a-Circle) and to a [hypercube graph](##Example:-4D-Hypercube-with-a-Grover-Coin). " |
| 18 | + "Similarly to classical random walks, quantum walks are divided into the discrete and continuous cases. This notebook focuses on discrete quantum walks, and is organized as follows: \n", |
| 19 | + "\n", |
| 20 | + "1. [One to one](##Classical-Random-Walks-vs.-Quantum-Walks) compares classical random walks with quantum walks via a specific example: a walk on a circle.\n", |
| 21 | + "2. A [general quantum model](##How-to-Build-a-general-Quantum-Walk-with-Classiq) studies quantum walks and subsequently applies it to the [circle case](##Example:-Symmetric-Quantum-Walk-on-a-Circle) and to a [hypercube graph](##Example:-4D-Hypercube-with-a-Grover-Coin). " |
19 | 22 | ] |
20 | 23 | }, |
21 | 24 | { |
|
24 | 27 | "metadata": {}, |
25 | 28 | "source": [ |
26 | 29 | "This tutorial demonstrates the following concepts of Classiq:\n", |
| 30 | + "\n", |
27 | 31 | "* The resemblance between classical and quantum programming with Classiq.\n", |
28 | 32 | "* Classiq's built-in constructs:\n", |
29 | 33 | " * `control`: general controlled-logic\n", |
|
51 | 55 | "metadata": {}, |
52 | 56 | "source": [ |
53 | 57 | "Specify and implement a simple example: a discrete walk on a circle, or more precisely, on a regular polygon with $2^N$ nodes (see Figure 1). The idea behind the random/quantum walk:\n", |
| 58 | + "\n", |
54 | 59 | "1. Start at some initial point, e.g., the zeroth node.\n", |
55 | 60 | "2. Flip a coin. Heads moves one step clockwise; tails moves counterclockwise.\n", |
56 | 61 | "3. Repeat steps 1-2 for a given total number of steps $T$." |
|
101 | 106 | "metadata": {}, |
102 | 107 | "source": [ |
103 | 108 | "Define a function to flip a coin:\n", |
| 109 | + "\n", |
104 | 110 | "* Classical: the coin is either 0 or 1. To flip the coin, draw a random number from the set $\\{0,1\\}$.\n", |
105 | 111 | "* Quantum: the coin is represented by a qubit and a \"flip\" is defined by some unitary operation on it. Choose the Hadamard gate, which sends the $|0\\rangle$ state into an equal superposition of $|0\\rangle$ and $|1\\rangle$." |
106 | 112 | ] |
|
133 | 139 | "id": "d10a317a-0267-4b51-b230-3d3cd393d3fd", |
134 | 140 | "metadata": {}, |
135 | 141 | "source": [ |
136 | | - "Next, define a function for moving clockwise and counterclockwise. This operation is a modular addition by $\\pm 1$.\n", |
| 142 | + "Next, define a function for moving clockwise and counterclockwise. This operation is a modular addition by $\\pm 1$:\n", |
| 143 | + "\n", |
137 | 144 | "* Classical: the position is an integer in $[-2^{N-1}, 2^{N-1}-1]$. Use basic arithmetic operations.\n", |
138 | 145 | "* Quantum: the position is an $N$-qubits state. Build an in-place modular addition by 1 (see an explanation at [the end of this notebook](#Technical-Notes)). Note that since quantum operations are reversible, you can define a counterclockwise step as the inverse of the clockwise step." |
139 | 146 | ] |
|
237 | 244 | "id": "ea9266b8-60a0-4f93-bc6b-942cd6d85cb7", |
238 | 245 | "metadata": {}, |
239 | 246 | "source": [ |
240 | | - "Define and run a specific example, taking a circle of size $2^7$, a total time of 50 steps, and 10000 samples. " |
| 247 | + "Define and run a specific example, taking a circle of size $2^7$, a total time of 50 steps, and 10,000 samples. " |
241 | 248 | ] |
242 | 249 | }, |
243 | 250 | { |
|
323 | 330 | "source": [ |
324 | 331 | "<center>\n", |
325 | 332 | "<img src=\"https://docs.classiq.io/resources/quantum_walk_circle_circuit.png\" style=\"width:100%\">\n", |
326 | | - "<figcaption align = \"middle\"> Figure 2. The circuit for a quantum walk on a circle with $2^7$ nodes. The last three blocks are repeated `t` times. </figcaption>\n", |
| 333 | + "<figcaption align = \"middle\"> Figure 2. The circuit for a quantum walk on a circle with $2^7$ nodes. The last three blocks repeat `t` times. </figcaption>\n", |
327 | 334 | "</center>" |
328 | 335 | ] |
329 | 336 | }, |
|
399 | 406 | "id": "922b31e2-d1c4-4d7d-afd1-c633b5981441", |
400 | 407 | "metadata": {}, |
401 | 408 | "source": [ |
402 | | - "There is a clear difference between the two distributions. The classical distribution is symmetric around the zero position, whereas the quantum example is asymmetric with a peak far from 0. This is a small example of the different behaviors of classical random walks and quantum walks. More details and examples are in Ref. [[1](#review)]." |
| 409 | + "There is a clear difference between the two distributions: the classical distribution is symmetric around the zero position, whereas the quantum example is asymmetric with a peak far from 0. This is a small example of the different behaviors of classical random walks and quantum walks. More details and examples are in Ref. [[1](#review)]." |
403 | 410 | ] |
404 | 411 | }, |
405 | 412 | { |
406 | 413 | "cell_type": "markdown", |
407 | 414 | "id": "d0115edd-4b37-4482-8a30-c80bc0e50bac", |
408 | 415 | "metadata": {}, |
409 | 416 | "source": [ |
410 | | - "## How to Build a General Quantum Walk with Classiq" |
| 417 | + "## Building a General Quantum Walk with Classiq" |
411 | 418 | ] |
412 | 419 | }, |
413 | 420 | { |
|
416 | 423 | "metadata": {}, |
417 | 424 | "source": [ |
418 | 425 | "Define a quantum function for a discrete quantum walk. The arguments of the function:\n", |
| 426 | + "\n", |
419 | 427 | "* `time`: an integer for the number of walking steps.\n", |
420 | 428 | "* `coin_flip_qfunc`: the quantum function for \"flipping\" the coin.\n", |
421 | 429 | "* `walks_qfuncs`: a list of quantum functions for all possible transitions at a given point.\n", |
|
633 | 641 | "id": "7dc4fde2-43ee-4249-84ee-909c3b694ce0", |
634 | 642 | "metadata": {}, |
635 | 643 | "source": [ |
636 | | - "Define a model for quantum walk on a hypercube. Two nodes in the hypercube are connected to each other if their Hamming distance is 1. Thus, a step along a hypercube is given by moving \"1 Hamming distance away\". For a $d$-dimentional hypercube, at each node there are $d$ possible directions to move. Each of them is given by applying a bit flip on one of the bits. In the quantum case, this is obtained by applying an X gate on one of the $N$ qubits.\n", |
| 644 | + "Define a model for quantum walk on a hypercube. Two nodes in the hypercube are connected to each other if their Hamming distance is 1. Thus, a step along a hypercube is given by moving \"1 Hamming distance away\". For a $d$-dimensional hypercube, at each node there are $d$ possible directions to move. Each of them is given by applying a bit flip on one of the bits. In the quantum case, this is obtained by applying an X gate on one of the $N$ qubits.\n", |
637 | 645 | "\n", |
638 | 646 | "For the coin operator, take the \"Grover diffuser\" function. This choice refers to a symmetric quantum walk [[1](#review)]. The Grover diffuser operator is a reflection around a given state $|\\psi\\rangle$:\n", |
639 | 647 | "$$\n", |
|
767 | 775 | "source": [ |
768 | 776 | "<center>\n", |
769 | 777 | "<img src=\"https://docs.classiq.io/resources/quantum_walk_hypercube_circuit.png\" style=\"width:100%\">\n", |
770 | | - "<figcaption align = \"middle\"> Figure 4. The circuit for a quantum walk on a 4D cube with a Grover coin. The last two blocks are repeated `t` times. </figcaption>\n", |
| 778 | + "<figcaption align = \"middle\"> Figure 4. The circuit for a quantum walk on a 4D cube with a Grover coin. The last two blocks repeat `t` times. </figcaption>\n", |
771 | 779 | "</center>" |
772 | 780 | ] |
773 | 781 | }, |
|
821 | 829 | "id": "3cca3d17-4ec3-4cba-b770-13b38e58faa4", |
822 | 830 | "metadata": {}, |
823 | 831 | "source": [ |
824 | | - "We found that at $T=4$ the probability to measure the walker at the opposite corner is larger than $1/2$. We can check an analogous question in the classical random walk, where the distribution is taken over an ensemble of independent experiments):" |
| 832 | + "At $T=4$, the probability to measure the walker at the opposite corner is larger than $1/2$. Check an analogous question in the classical random walk, where the distribution is taken over an ensemble of independent experiments:" |
825 | 833 | ] |
826 | 834 | }, |
827 | 835 | { |
|
876 | 884 | "id": "916c1dd1-3f08-417e-a7f7-adbaa33b60d4", |
877 | 885 | "metadata": {}, |
878 | 886 | "source": [ |
879 | | - "## Technical Notes\n", |
880 | | - "\n", |
881 | | - "### QFT modular adder\n", |
| 887 | + "## Note Regarding QFT Modular Adder\n", |
882 | 888 | "\n", |
883 | | - "Below we explain the `quantum_step_clockwise` function defined for the quantum walk on a circle. The unitary matrix that represents walking on a circle operates as follows:\n", |
| 889 | + "This section explains the `quantum_step_clockwise` function defined for the quantum walk on a circle. The unitary matrix that represents walking on a circle operates as follows:\n", |
884 | 890 | "$$\n", |
885 | 891 | "U_{+}|i\\rangle =\n", |
886 | 892 | "\\left\\{\n", |
|
902 | 908 | "\t 1 & 0 & 0 & \\cdots & 0 & 0\n", |
903 | 909 | "\\end{pmatrix}.\n", |
904 | 910 | "$$\n", |
905 | | - "In Fourier space this matrix is diagonal, namely, the Fourier matrix $\\mathcal{FT} $ diagonalizes it. Moreover, the diagonal entries forms a goemetric series:\n", |
| 911 | + "In Fourier space, this matrix is diagonal; namely, the Fourier matrix $\\mathcal{FT} $ diagonalizes it. Moreover, the diagonal entries forms a goemetric series:\n", |
906 | 912 | "$$\n", |
907 | 913 | "U_+ = \\mathcal{FT} \\cdot \\begin{pmatrix}\n", |
908 | 914 | "\t\\alpha^0 & 0 & \\cdots& \\cdots & 0 \\\\\n", |
|
912 | 918 | "\t 0 & \\cdots & 0 & \\cdots & \\alpha^{2^N-1}\n", |
913 | 919 | "\\end{pmatrix} \\cdot \\mathcal{FT}^{\\dagger},\n", |
914 | 920 | "$$\n", |
915 | | - "with $\\alpha=e^{2\\pi i /2^N }$. We can implement both the $\\mathcal{FT}$ matrix and the diagonal matrix efficiently on a quantum computer, the former by a QFT and the latter by applying a series of $N$ RZ rotations." |
| 921 | + "with $\\alpha=e^{2\\pi i /2^N }$. You can implement both the $\\mathcal{FT}$ matrix and the diagonal matrix efficiently on a quantum computer; the former by a QFT and the latter by applying a series of $N$ RZ rotations." |
916 | 922 | ] |
917 | 923 | }, |
918 | 924 | { |
919 | 925 | "cell_type": "markdown", |
920 | 926 | "id": "88b24611-5d16-4fa0-a014-d192459198d3", |
921 | 927 | "metadata": {}, |
922 | 928 | "source": [ |
923 | | - "<a id='review'>[1]</a>: [Kempe, J. \"Quantum random walks: an introductory overview.\" Contemporary Physics 44, 307 (2003)](https://arxiv.org/abs/quant-ph/0303081).\n", |
| 929 | + "<a id='review'>[1]</a>: [Kempe, J. \"Quantum random walks: An introductory overview.\" Contemporary Physics 44, 307 (2003)](https://arxiv.org/abs/quant-ph/0303081).\n", |
924 | 930 | "\n", |
925 | 931 | "<a id='hypercube'>[2]</a>: [Kempe, J. \"Discrete quantum walks hit exponentially faster.\" Probability theory and related fields 133, 215 (2005)](https://arxiv.org/abs/quant-ph/0205083)." |
926 | 932 | ] |
|
0 commit comments