Path: blob/main/notebooks/ch-algorithms/quantum-walk-search-algorithm.ipynb
3855 views
Quantum Walk Search Algorithm
Quantum walks are the quantum equivalence of a classical Markov chain and have become key in many quantum algorithms. In this section, we implement a quantum walk search algorithm that finds marked elements in a graph. The algorithm has a quadratic speedup compared to its classical counterpart.
1.Classical Markov chains
A Markov chain is a stochastic process often used to model real-life processes. It consists of states and associated transition probabilities, which describe the probabilities to move between the states in each time step. In discrete-time Markov chains, which we work with here, the time steps are discrete. Markov chains satisfy the Markov property, which means that the next step of the process only depends on the current and not any of the previous steps. A Markov chain has an associated transition matrix, P, which describes the probability to move between each of the states. We show an example of a Markov chain and its associated transition matrix below. ParseError: KaTeX parse error: Undefined control sequence: \label at position 104: …
\end{pmatrix}
\̲l̲a̲b̲e̲l̲{eq:matrix_exam… 
Given a transition matrix , we can obtain the probability distribution after time steps by .
2.Quantum walks
Quantum walks are the quantum equivalent of the classical Markov chain. Due to superposition, a quantum walk will take all possible paths simultaneously until we measure the circuit. Due to quantum interference, some state will cancel out. This makes quantum walk algorithms faster than classical ones, since we can design them in such way that wrong answers quickly cancel out. There are two common models for quantum walks, coined quantum walks and Szegedy quantum walks, which are equivalent under certain circumstances. A coined quantum walk is a walk on the vertices of the graph while Szegedy quantum walk takes place on the edges. Before we show how we can implement a quantum walk, we will introduce both models.
2.A Coined quantum walks
A simple example of a coined quantum walk is a walk on the infinite integer line. In this case, we represent the walker's position with an integer, , since the walker can walk all integers in . A coin decides how the walker should move. On the integer line, the walker can go either left or right. Therefore, the coin's computational basis is , and we move the walker in one direction if the coin is and in the other direction if the coin is .
A coined quantum is a walk on the nodes in a graph, and we refer to the nodes as states. The walker can move between states that are connected with an edge. In the coin model, we have two quantum states and two operators. The first state is the position state, which represents the walker's position. For the walk above, this is an integer since the walker can be anywhere on the integer line. The other state is the coin state. The coin state decides how the walker should move in the next step. We can represent both the coin state and the position state by vectors in Hilbert space. If we can express the coin state by a vector in and the position state with a vector in , we can express the quantum space for the entire walker as .
As we mentioned, the model also has two operators; the coin operator, , and the shift operator, . The coin operator acts on during each time step and puts the walker in superposition, so it walks all possible paths simultaneously. For the walk on the integer line, this means that it moves both to the left and right in each time step. There are different coin operators, but the most common ones are the Hadamard coin and the Grover coin. A Hadamard coin is a Hadamard gate that puts the walker in an equal superposition:
A Grover coin is the Grover diffusion operator from Grover's algorithm. We define it as
Like the Hadamard coin, a Grover coin puts the walker in superposition. However, it behaves a bit differently. If we apply a Grover coin to a walker in position , we obtain the state vector probabilities shown in the figure below. As we can see, the coin does not put the walker in an equal superposition as the Hadamard coin does. Instead, has a much larger probability than the other states.
The other operator in the model, the shift operator, acts on and moves the walker to the next position. For the walk on the integer line, the shift operator moves the walker to the left of the coin is and to the right if the coin is :
With the shift operator defined as above, we can represent one step of the coined quantum as the unitary operator given by
where C is the coin operator. For the quantum walk on the integer line we use the Hadamard coin, but C can be either Hadamard coin, Grover coin or any other coin operator.
We can also look several steps ahead. We can express the quantum state after time steps as where is the initial state and U is the operator for one step of the walk [1].
Coined quantum walks are most suitable for regular graphs, graphs where all nodes have the same number of neighbors [2]. An alternative quantum walk model that is more convenient for non-regular graphs is the Szegedy model that we will look at next.
2.B Szedgedy quantum walk
While a coined walk is a walk on the graph's nodes, a Szegedy walk is a walk on the edges on a bipartite double-cover of the original graph. The double-cover graph is a graph with twice as many vertices as the original graph. Two nodes in the bipartite double-cover graph are connected with an edge if and only if the nodes are also connected in the original graph. To create this model, we start with the transition probability matrix P for the classical walk. As described in section 1, we represent a classical discrete-time random walk by a transition matrix . For any -vertex graph with transition matrix , we can define the corresponding discrete-time quantum walk as a unitary operation on the Hilbert space . Let define the probability that we make a transition from state to . Before we define the walk, we define the normalized states
and the projection onto
ParseError: KaTeX parse error: Undefined control sequence: \label at position 68: …} \bra{\psi_j} \̲l̲a̲b̲e̲l̲{eq:sz_pi} \end…We also introduce the shift operator S:
ParseError: KaTeX parse error: Undefined control sequence: \label at position 62: …j,k} \bra{k,j} \̲l̲a̲b̲e̲l̲{eq:sz_s} \end{…With and defined as above we can introduce one step of the discrete-time quantum walk:
ParseError: KaTeX parse error: Undefined control sequence: \label at position 41: … S(2 \Pi - 1), \̲l̲a̲b̲e̲l̲{eq:sz_op} \end…where is the reflection operator. We also define steps of the walk as [2].
2.C Equivalence of coined and Szegedy quantum walks
It is known that a coined walk with Grover coin is equivalent to Szegedy quantum walk. For more details, we refer to this article [3] by Thomas G. Wong, where he also shows the equivalence between the operators in the two models.
3. Example: Implementing quantum walk on a hypercube
A hypercube is the -dimensional counterpart of the -dimensional cube. All nodes have degree , and the hypercube has a total of nodes. We can represent the nodes in a hypercube graph by -tuples of binary numbers. The binary representation of the neighbors of a node will differ by only one binary number. For example, in the 4-dimensional hypercube, the neighbors to are , , , and . Thus, a node is connected to all nodes to which the Hamming distance is 1. The edges are also labeled. Two neighboring nodes that differ in the a:th bit are connected by the edge labeled .
The Hilbert space representing a coined quantum walk on the hypercube is , where denotes the coin space and the walker's position. The computational basis is
The value of the coin computational basis , which is associated with edge , decides where the walker should move. If the , the walker will go to the node where the first binary value differs from the current node. If , the walker will move to the node in which the second value differs from the current, et cetera. Let be an n-tuple where all binary values, except the value with index , are . Then the shift operator moves the walker from the state to :
We use the Grover coin, , for this walk. Thus, the evolution operator is
We will now show how we can implement a quantum walk on a 4-dimensional hypercube. We need to implement the coin operator and the shift operator. We start by importing all necessary libraries from Qiskit.
The circuit will have 6 qubits, 4 that represents the position and 2 that represents the coin. As we mentioned previously, the coin is a Grover coin, which is the diffuser in Grover's algorithm. We start by implementing this.
Now, let us implement the shift operator. We know that the walker can only move to neighboring nodes, and all neighboring nodes differ by only one bit. We want to move the walker according to the coin, and we move the walker by applying a NOT gate to one of the node qubits. If the coin is in state , we move the walker to the state in which the first node qubit differ. If the coin is or , the walker moves to the state where the second and third qubit, respectively, differ. Finally, if the Grover coin is , we flip the fourth qubit. We implement this with CCNOT- and NOT gates after the Grover coin. Together, they are one step of a quantum walk on a 4-dimensional hypercube.
4. Quantum walk search algorithm
We will now implement a quantum walk search algorithm that finds a marked vertex in a graph. First, we describe the algorithm, then we go through its implementation. The quantum walk search algorithm solves the problem of finding marked vertices in a graph by a quantum walk. That is, we mark some set of vertices , start at an arbitrary node in the graph and move according to the walk until we find the marked nodes. The basis states in the quantum walk search algorithm have two registers, one corresponding to the current node and the other corresponding to the previous node. That is, the basis states corresponds to the edges in the graph. We denote the quantum walk based on the classical Markov chain with transition matrix by the unitary operation on . We also define as the uniform superposition over the node 's neighbors. Let be a basis state. We define the basis state as ''good'' if is a marked node. Otherwise, we refer to it as ''bad''. We now introduce ''good'' and ''bad'' states:
which are the superpositions over good and bad basis states. Next, let us define and .
In short, the algorithm consists of three steps:
Set up the initial state , a uniform superposition over all edges
Repeat times:
(a) Reflect through
(b) Reflect through
Do a measurement in the computational basis
We can easily implement step with Hadamard gates and the reflection through with a phase oracle that shifts the phase of if is in the first register, and leaves the circuit unchanged otherwise.
Step 2(b) is equivalent to finding a unitary that performs the following mapping: ParseError: KaTeX parse error: Undefined control sequence: \label at position 15: \begin{align} \̲l̲a̲b̲e̲l̲{eq:mapping_1} …
To find this operator we apply phase estimation on . Above we defined as the evolution operator for the random walk. As we saw in section 2.A, this is a unitary operator. From this follows that the eigenvalues of have norm . Because of this, we can write the eigenvalues of on the form . The unitary has one eigenvector with corresponding eigenvalue , which is . This is given by . will find this vector by adding a register with auxiliary qubits and perform phase estimation with precision , where is the spectral gap of . To do this, we need to apply times. Let be an eigenvector of with eigenvalue . Assume that is the best approximation to given by the phase estimation. The operation that performs the mappings in for in step 2(b) is given by [4]
5.Example: Quantum walk search on 4-dimensional hypercube
The quantum walk search algorithm makes it possible to find a marked set of nodes in steps, , where is the number of marked nodes and is the total number of nodes. This algorithm is originally used with Szegedy quantum walks, where we use two node registers to represent the quantum state. However, a coined walk with a Grover coin is equivalent to a Szegedy quantum walk and since implementations of coined walks are less complex in general, we choose to implement the algorithm with a coined walk. We will use the 4-dimensional hypercube that we implemented in section 3.
In short, we will implement the algorithm as follows. We achieve step 1, a uniform superposition over all edges, by applying Hadamard gates to the node qubits as well as the coin qubits. For step 2(a), we implement a phase oracle. Step 2(b) is implemented by a phase estimation on one step of the quantum walk on the hypercube followed by marking all quantum states where . We do this by rotating an auxiliary qubit. In the last part of this step, we reverse the phase estimation. The number of theta qubits depends on the precision of .
Below, we implement the quantum walk search algorithm on the 4-dimensional hypercube.
For this algorithm we will need to use the inverse of the one step gate implemented earlier. We get this by using the built in circuit function inverse().
The inversed one step gate will be used to reverse the phase estimation later. We need to make controlled gates from both the one step gate that we implemented in section 3 and its inverse. We will later use them depending on the value of the control qubit.
Both the controlled one step gate and the controlled inversed one step gate will be used in the phase estimation. Another thing we will use in the phase estimation is the Quantum Fourier Transform. Qiskit has a function, QFT, which implements the Quantum Fourier Transform. The phase estimation uses the inverse Quantum Fourier Transform but we also will need to use the ordinary QFT to reverse the phase estimation.
Before we implement the phase estimation, we implement a phase oracle that marks the states 1011 and 1111. Then, we make it a circuit. This is step 2(a) of the algorithm.
We will now implement a gate that rotates an auxiliary qubit if the other qubits are non-zero. We will use this gate in the phase estimation, where it will rotate the auxiliary qubit if .
Now, we will implement step 2(b) of the algorithm. This step consists of a phase estimation one step of the quantum walk followed by an auxiliary qubit that we rotate if . For this, we use the mark_auxiliary_gate that we just created. Thereafter, we reverse the phase estimation.
Now we implement the whole quantum walk search algorithm using the gates we made previously. We start by applying Hadamard gates to node and coin qubits, which is step 1 in the algorithm. Thereafter, we iteratively apply the phase oracle gate and the phase estimation gate (steps 2(a) and 2(b)). We need iterations as stated in the description of the algorithm in section 4. Lastly, we measure the node qubits.
Finally we run the implementation on the qasm simulator. We see that the circuit collapse to the marked states a clear majority of the times.
6. References
Renato Portugal. Quantum Walks and Search Algorithms. New York, NY: Springer New York, 2013
Markus G. Kuhn.Some Introductory Notes on Quantum Computing. Apr. 2000
Thomas G. Wong. “Equivalence of Szegedy’s and coined quantum walks”. In: Quantum InformationProcessing 16.9 (July 2017). ISSN: 1573-1332. DOI:10.1007/s11128-017-1667-y. URL:http://dx.doi.org/10.1007/s11128-017-1667-y.37
Ronald de Wolf. Quantum Computing: Lecture Notes. 2021. arXiv:1907.09415 [quant-ph]