diff --git a/community/terra/qis_adv/quantum_walk.ipynb b/community/terra/qis_adv/quantum_walk.ipynb index 3fdbe0626..885b903f4 100644 --- a/community/terra/qis_adv/quantum_walk.ipynb +++ b/community/terra/qis_adv/quantum_walk.ipynb @@ -15,7 +15,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "# Implementation of Quantum Walks on graph for IBM Q\n", + "# Implementation of Quantum Walks on Cycle Graph\n", "This notebook is based on the paper of B L Douglas and J B Wang, \"Efficient quantum circuit implementation of quantum walks\", arXiv:0706.0304 [quant-ph]." ] }, @@ -24,16 +24,16 @@ "metadata": {}, "source": [ "## Contributors\n", - "Jordan Kemp(University of Chicago), Shin Nishio(Keio University), Ryosuke Satoh(Keio University), Desiree Vogt-Lee(University of Queensland), and Tanisha Bassan(The Knowledge Society)" + "Jordan Kemp (University of Chicago), Shin Nishio (Keio University), Ryosuke Satoh (Keio University), Desiree Vogt-Lee (University of Queensland), and Tanisha Bassan (The Knowledge Society)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Introduction: challenges in implementing quantum walk\n", + "## Introduction\n", "\n", - "There are so many types of quantum walks. Walker can walk on n-dimensional space or any limited graphs. First we talk about the concept and dynamics of Quantum and Classical random walk. After that we show the implementation of Quantum Walk on cycle graph." + "There are many different types of quantum walks: a walker can walk on n-dimensional space or any limited graphs. First we will talk about the concept and dynamics of the quantum random walk and then show the implementation of a quantum walk on cycle graph." ] }, { @@ -41,7 +41,7 @@ "metadata": {}, "source": [ "## Random walk \n", - "Random walk is a dynamics which is randomly time evolving system. Figure shows a simple type of random walk. " + "A random walk is a dynamical path with a randomly evolving time system. The figure below shows a simple type of random walk. " ] }, { @@ -55,70 +55,81 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The dynamics can be regarded as a simple algorithm as shown.\n", - "1. There is a $n$-dimension(in this case, one for simple) space and a walker start at the point $x=0$\n", - "2. take a step either forward (toward $+x$) or backward(toward $-x$) \n", - "in 2., the choice is to be made randomly(ex: coin-flip). We call this \"Coin Operator\". \n", + "The dynamics can be regarded as a simple algorithm:\n", + "1. There is a $n$-dimensional space (in this case, one for simplicity) and a walker which starts at the point $x=0$\n", + "2. The walker then takes a step either forwards (towards $+x$) or backwards (towards $-x$) \n", "\n", - "In this system, $p+q = 1$" + "In the second step, the choice is made randomly (eg. a coin-flip). We can call this the \"Coin Operator\". \n", + "\n", + "For this system: $p+q = 1$." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Quantum walk \n", - "Quantum walk is \"quantum version\" of random walk. This means the coin function can be Unitary gate($U(2)$) which is non-random and reversible. \n", + "## Quantum Walk \n", + "A quantum walk is the \"quantum version\" of a classical random walk. This means the coin function will be a Unitary gate ($U(2)$) which is non-random and reversible:\n", + "\n", + "$$p+q = U \\in U(2)$$\n", "\n", - "$$p+q = U ∈ U(2)$$\n", + "In this notebook, we use a Hadamard gate for executing the coin function since it puts our qubits in a state of superposition, allowing for the simulation of a coin based probability:\n", "\n", - "In this experiments, we use Hadamard gate for coin function since it puts our qubits in a state of superposition simulating the coin based probability, \n", "$$H=\\frac{1}{\\sqrt{2}}\\left [{\\begin{array}{rr}1 & 1 \\\\ 1 & -1\\\\ \\end{array}}\\right]$$\n", "\n", - "There are continuous and discrete quantum walks, in our experiment we use the discrete framework. In the discrete, unitary operations are made of coin and shift operators U = SC which work in a state space.\n", - "An arbitrary undirected graph $G(V,E)$ where $V = {v_1, v_2, ..v_n}$ as nodes on the graph and $E = {(v_x, v_y) , ( v_i, v_j) …}$ as edges that combine different nodes together.\n", - "The quantum walk extends into a position space where each node vi with a certain valency di is split into di subnodes. The shifting operator then acts as $S (v_i, a_i) = (v_j, a_j)$ and coin operator are unitary gates which combine the probability amplitudes with individual subnodes under each node.\n", - "A unitary of $v_i$ with valency $d_i$ can be represented as $(d_i \\times d_i)$. The total states of system is defined by the hilbert space $$H = H_c + H_p$$, respectively coin hilbert space and position hilbert space. \n" + "There are two kinds of random walks, continuous and discrete, and in this notebook we will use the discrete framework. In the discrete, unitary operations are made of coin and shift operators $U = SC$ which work in a state space.\n", + "\n", + "It is represented by an arbitrary undirected graph $G(V,E)$ where $V = {v_1, v_2, ..v_n}$ as nodes on the graph and $E = {(v_x, v_y) , ( v_i, v_j) …}$ as edges that combine different nodes together.\n", + "\n", + "The quantum walk extends into a position space where each node $v_i$ has a certain valency $d_i$ and is split into $d_i$ subnodes. The shifting operator then acts as $S (v_i, a_i) = (v_j, a_j)$ and with the coin operator, are unitary gates which combine the probability amplitudes with individual subnodes under each node.\n", + "\n", + "A unitary of $v_i$ with valency $d_i$ can be represented as $(d_i \\times d_i)$. The total state of system is defined by the Hilbert space \n", + "\n", + "$$H = H_c + H_p$$ \n", + "\n", + "Where $H_C$ is the coin Hilbert space and $H_P$ is the position Hilbert space. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - "## Coin function\n", - "The first step in a quantum random walk is the coin operator. The operation works by an arbitrary unitary transformation in the coin space which creates a rotation similar to “coin-flip” in random walk. This is mainly the hadamard gate which models the balanced unitary coin. \n", - "$$H=\\frac{1}{\\sqrt{2}}\\left [{\\begin{array}{rr}1 & 1 \\\\ 1 & -1\\\\ \\end{array}}\\right]$$" + "## The Coin Operator \n", + "The first operation in a quantum random walk is the coin operator. The operator works by performing an arbitrary unitary transformation in the coin space which creates a rotation similar to “coin-flip” in random walk. This is namely the Hadamard gate, which models a balanced unitary coin. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The coin register will continue interfering with it’s position state until measured after all intermediate steps. The results are very different from random walks, it doesn’t converge to a gaussian distribution but to evolves into an asymmetric probability distribution. This happens because the hadamard coin operator treats each basis vectors |↑> and |↓> differently. The rightwards path interferes more destructively as it’s multiplied but -1 but leftwards path is constructive interference. System tends to take steps towards the left. To reach symmetric results, both base vectors will start in superposition states of both |↑> and |↓>. Another way to reach symmetry is use a different coin operator which doesn’t bias the coin towards a certain base vector. \n", - "$$Y=\\frac{1}{\\sqrt{2}}\\left [{\\begin{array}{rr}1 & i \\\\ i & 1\\\\ \\end{array}}\\right]$$\n" + "The coin register will continue interfering with its position state until it is measured, after all intermediate steps. The results are very different from random walks as it doesn’t converge to a Gaussian distribution, but rather evolves into an asymmetric probability distribution. This happens because the Hadamard coin operator treats each basis vectors, |↑> and |↓> , differently. \n", + "\n", + "The rightwards path interferes more destructively as it is multiplied by -1, however, the leftwards path undergoes more constructive interference and the system tends to take steps towards the left. To reach symmetric results, both base vectors will start in a superposition of states (between |↑> and |↓>). Another way to reach symmetry is use a different coin operator which doesn’t bias the coin towards a certain base vector, such as the Y gate:\n", + "\n", + "$$Y=\\frac{1}{\\sqrt{2}}\\left [{\\begin{array}{rr}1 & i \\\\ i & 1\\\\ \\end{array}}\\right]$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Quantum walk on cycle graph\n", - "Our experiment is conducting a quantum random walk on circular graph which is efficiently and simply implemented on the quantum circuit. The graph has 8 nodes with 2 attached edges which act as the subnodes on the circuit. \n" + "## Quantum Walk on the Cycle Graph\n", + "\n", + "The goal of this notebook is to conduct a quantum random walk on circular graph which can be efficiently and simply implemented on the quantum circuit. The graph has 8 nodes with 2 attached edges which act as the subnodes on the circuit. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "\"Note: Trusted Notebook\" width=\"500 px\" align=\"center\">" + "\"Note: Trusted Notebook\" width=\"350 px\" align=\"center\">" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "The operations propagate systemically around the graph as each node is a seperate bit-string value in lexicographic order. For 2n graph, n qubits required to encode problem and 1 ancilla qubit for subnode(coin). " + "The operations propagate systemically around the graph as each node is a seperate bit-string value in lexicographic order. For a 2n graph, n qubits are required to encode the problem and 1 ancilla qubit is required for the subnode (coin). " ] }, { @@ -132,20 +143,32 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "This circuits shows whole process(for 2 flip) of Quantum Walk on cycle graph with $2^3$nodes. \n", - "Gray square frame is a set of Coin operator and shift operator. \n", - "In this circuit, q[0] to q[2] represents the state (position) of quantum walker, and q[3] represents Coin Operator.\n", + "The above circuit shows the whole process of the quantum walk on a cycle graph with $2^3$ nodes. \n", + "\n", + "The gray rectangular frame outlines a set of coin operators and shift operators. \n", + "\n", + "In this circuit, q[0] to q[2] represent the state (position) of quantum walker, and q[3] represents the coin operator.\n", "\n", - "In this style, programmer can insert initial position of walker as 3-qubits state. For example, if the input is $110$, the position is $6$.\n", + "In this style, a programmer can insert the initial position of walker as a 3-qubit state. For example, if the input is $110$, then the position is $6$ (see the earlier cycle graph). \n", "\n", - "Coin operator decide whether walker go Clockwise or Counterclockwise.\n", + "The coin operator decides whether the walker proceeds clockwise or counterclockwise.\n", "\n", - "INC is gates that increment the state of walker which is equal to Clockwise rotation in the cycle graph. \n", - "DEC is gates that decrement the state of walker which is equal to Counterclockwise rotation in cycle graph.\n", + "INC is a gate that increments the state of the walker which is equal to a clockwise rotation in the cycle graph. \n", "\n", - "After repeating of the coin operator and the shift operator, measure the qubits other than the coin qubit, it is possible to know the position of the walker.\n", + "DEC is gate that decrements the state of the walker which is equal to a counterclockwise rotation in cycle graph.\n", "\n", - "## $n$-qubit Toffoli" + "After repeatedly executing the coin operator and the shift operator, we can measure the qubits (excluding the ancilla coin qubit), and it is then possible to know the position of the walker." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## $n$-qubit Toffoli\n", + "\n", + "The Toffoli gate is a CCNOT(CCX) gate. By using the Toffoli gate, X gates executed on Q2 if Q0 and Q1 is equal to 1.\n", + "\n", + "In our quantum walk implementation, we need more connections to expand the quantum walk implementation." ] }, { @@ -159,13 +182,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Toffoli gate is CCNOT(CCX) gate.\n", - "By using Toffoli, X gates executed on Q2 if Q0 and Q1 is 1.\n", - "In quantum walk implementation, we need more connection for expanding quantum walk implementation.\n", - "For example, CCX can be written as below by using only available gate set of IBMQ devices.\n", + "For example, CCX can be written as in the below circuit by using only the available gate sets of the IBMQ devices.\n", "\n", - "Thus, more than 4 qubits, we can implement many qubits of CX gate (\"C$N$X gate\") with this way.\n", - "Reference is shown [here](\"https://journals.aps.org/pra/abstract/10.1103/PhysRevA.52.3457\").\n" + "Therefore, for more than 4 qubits, we can implement many qubits of CX gate (\"C$N$X gate\") using this method. Reference shown [here](\"https://journals.aps.org/pra/abstract/10.1103/PhysRevA.52.3457\")." ] }, { @@ -184,28 +203,27 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "def cnx(qc,*qubits):\n", + "def cnx(qc, *qubits):\n", " if len(qubits) >= 3:\n", " last = qubits[-1]\n", - " #A matrix: (made up of a and Y rotation, lemma4.3)\n", + " # A matrix: (made up of a and Y rotation, lemma4.3)\n", " qc.crz(np.pi/2, qubits[-2], qubits[-1])\n", - " #cry\n", " qc.cu3(np.pi/2, 0, 0, qubits[-2],qubits[-1])\n", " \n", - " #Control not gate\n", + " # Control not gate\n", " cnx(qc,*qubits[:-2],qubits[-1])\n", " \n", - " #B matrix (cry again, but opposite angle)\n", + " # B matrix (pposite angle)\n", " qc.cu3(-np.pi/2, 0, 0, qubits[-2], qubits[-1])\n", " \n", - " #Control\n", + " # Control\n", " cnx(qc,*qubits[:-2],qubits[-1])\n", " \n", - " #C matrix (final rotation)\n", + " # C matrix (final rotation)\n", " qc.crz(-np.pi/2,qubits[-2],qubits[-1])\n", " elif len(qubits)==3:\n", " qc.ccx(*qubits)\n", @@ -217,7 +235,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Decide the number of qubits $n$ for represent walker's state. (Whole circuits requires $n+1$ qubits)" + "We then need to decide the number of qubits $n$ to represent the walker's state (the whole circuit requires $n+1$ qubits)." ] }, { @@ -232,7 +250,7 @@ "source": [ "import numpy as np\n", "from qiskit import IBMQ, QuantumCircuit, ClassicalRegister, QuantumRegister, execute\n", - "from qiskit.tools.visualization import plot_histogram,plot_state_city\n", + "from qiskit.tools.visualization import plot_histogram, plot_state_city\n", "\n", "n=3" ] @@ -272,13 +290,12 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Increment gate and decrement gate are the shift operator for walk.\n", - "Both of them including the C$N$X gates and change the position of the walker based on the coin operator." + "We then need to execute the increment and decrement gate in order for the shift operator to walk, including the C$N$X gates which changes the position of the walker based on the coin operator." ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 2, "metadata": { "colab": {}, "colab_type": "code", @@ -286,8 +303,6 @@ }, "outputs": [], "source": [ - "#IN/DECREMENT GATES FOR N=3\n", - "\n", "def increment_gate(qwc, q, subnode):\n", " \n", " cnx(qwc, subnode[0], q[2], q[1], q[0])\n", @@ -318,7 +333,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Repeat coin operator and shift operator for any steps(in this case 15)." + "Rerun the coin and shift operators for n number of steps (in this case 15)." ] }, { @@ -360,13 +375,13 @@ "\n", " return qwc\n", "\n", - "\n", "import matplotlib as mpl\n", + "\n", "step = 1\n", "qwc = runQWC(qwc, step)\n", "qwc.draw(output=\"mpl\")\n", - "# print(qwc)\n", "result = ibmsim(qwc)\n", + "\n", "print(result)" ] }, @@ -394,9 +409,9 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "The first qubit which is always 0 is the coin qubit.\n", - "Second to fourth is the position of the walker(binary).\n", - "You can also see the distribution using plot_histogram." + "The first qubit which is always 0, is the coin qubit.\n", + "The second to fourth, is the position of the walker (binary).\n", + "The distribution can be seen using plot_histogram." ] }, { @@ -426,7 +441,8 @@ "metadata": {}, "source": [ "## Results\n", - "This is the example of whole iteration. The size of each node represents probability of existing quantum walker. " + "\n", + "The following animation is what the quantum walk looks like over its 19 iterations. The size of each node represents probability of the quantum walker existing in that position. " ] }, { @@ -441,7 +457,8 @@ "metadata": {}, "source": [ "## Required Resources\n", - "In this algorithm, we need $n+1$ qubits for a cycle graph with $2^n$ nodes. As you can see in the circuit, time complexity increases linearly. We take $7$ data points of steps($1, 10, 20, 30, 40, 50, 100$). This is the result of relation between execution time on 'qasm_simulator' and the number of steps." + "\n", + "In this algorithm, we needed $n+1$ qubits for a cycle graph with $2^n$ nodes. As you can see in the following graph, the time complexity increases linearly. This is the result of relation between execution time on 'qasm_simulator' and the number of steps." ] }, { @@ -455,27 +472,27 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "\n", - "32 qubits 2^31 nodes ← cost time....(execution) \n", - "Limitations \n", - "\n", "## Discussion about Future Work and Applications\n", - "\n", - "_Many particle quantum random walk_\n", - "\n", - "Simulation evolution of spatial entanglement in many-body physics problems. The graph is a 1D lattice with a particle on each node as initial state. Each particle has separate position and coin hilbert space H = (Hc ⊗ Hp)⊗M. The particles independantly evolve and don't interact. 3-particle system graph are easily implemented in quantum walk but more particles increase number of steps in quantum walk and measurement of entanglement become difficult. More efficient methods of quantum walk implementation will help increase the number of particle systems studied in evolution. \n", - "\n", "_Expansion of number of nodes on graph_ \n", "\n", - "The graph implemented in this project is 3 qubits for 8 nodes and 1 qubit for coin operation. In total only 4 qubits are used for evolution. The total time for iterating through coin and shift operator is 16 seconds for 100 flips. \n", - "We look at a real world problem that can be applied in quantum random walk on graphs with more nodes. Mapping enzymes as nodes on a graph to understand their evolution when in contact with mutagens only requires 33 nodes which can be mapped out on 7 qubit circuit. This will increase total time to 49 seconds for 100 flips. This is a scalable model which can continue to grow to map more complex graphs to problems. \n", + "The walk implemented in this project required 3 qubits for 8 nodes plus an additional 1 qubit for the coin operator. The total time for iterating through coin and shift operator was 16 seconds for 100 flips. \n", + "\n", + "An example of a real world problem that can be solved using quantum random walks is the mapping of enzymes to understand their evolution when in contact with mutagens. This problem only requires 33 nodes which can be mapped out on 7 qubit circuit. This increase in qubits would increase the total time to 49 seconds for 100 flips. This is a scalable model which can continue to grow to map more complex graphs to problems. \n", "\n", - "Time complexity for classcal computer (QC-simulator) get approximately $({\\frac{m+1}{n+1}})^2$ if the number of nodes becomes $2^m$ from $2^n$. This value is based on number of qubits and roughly estimated. \n", + "The time complexity for the quantum simulator approximately follows $({\\frac{m+1}{n+1}})^2$ if the number of nodes becomes $2^m$ from $2^n$. This value is based on number of qubits and is roughly estimated. \n", "\n", "## Conclusion\n", - "In this notebook we showed the basics of Quantum Walk and implementation on Quantum Circuit.\n", - "This algorithm requires $n+1$ qubits for any cycle graph with $2^n$ nodes. " + "In this notebook we showed the basics of the quantum random walk and its implementation on a cyclic quantum circuit.\n", + "\n", + "The implemented algorithm requires $n+1$ qubits for any cycle graph with $2^n$ nodes. " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -500,7 +517,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.6.8" } }, "nbformat": 4,