Grover's Search

#quantum #qbronze

Part of Womanium Quantum + AI 2024 program


Definition

Grover's search is unstructured quantum search algorithm that provides a clear quantum advantage over classical unstructured search.

Grover's search helps to speed up general functions with no other promises. (quadratic speed up)

Unstructured Search Example

Searching a function f:{0,1}^2 -> {0,1} to find x such that f(x) = 1

  • Classical approach is a linear search with a complexity of O(2n)
  • Quantum approach gives a complexity of O(2n)

Grover's Algorithm

Grover's Algorithm works by repeating a specific process multiple times to ultimately increase the probability of measuring the "correct" answer. This process of increasing the probability of the right answer is known as amplitude amplification.

Grover's Algorithm makes use of a quantum oracle that can indicate the "correct" answer, which is the target of the search.

There are different ways to illustrate this algorithm, two of which are inversion around the mean and phase rotations.

Grover's Operator (G^)

G^=HnZ0HnZf

Where

Z0|x={|xx=0n|xx0n=(100010001)=I2|0n0n|

This is basically an identity matrix where the first entry is -1.

Inversion Around the Mean

Let’s assume we have 8 options, but only 1 option is correct.

The algorithm start by setting an equal probability of measurement to each options (i.e. uniform superposition).

G1.png|700

Then the oracle is queried, by doing that, the oracle "stores" the answer in the phase of the correct option, in other words it flips the phase of the correct option.

G2.png

Now we apply Grover's operator (G^), which computes the following for each option:

2μαx

Where:

The Grover's operator is defined in unitary operators as:

G^=HnZ0HnZf

grover's operator circuit.png

The |1 qubit is needed to enable the oracle to apply phase kickback.

This will lower the amplitude of all options except the option with an inverted phase, i.e. the correct answer.

G3.png

G5.png

The figure clearly shows the amplification effect of the algorithm.

Finally, we repeat G^ for k times, making sure not to overshoot the correct answer, since the mean might eventually get negative and destruct the amplitude of the correct answer.

Important

It's important to note that we are not exploring all options at once, as most people think, instead we manipulating the probability of measuring a specific result.

We are starting the algorithm with a superposition of all possible options, therefore it's only one quantum state and not multiple.

Applying Grover's Operator

To able to see how Grover's operator (G^) applies our goal of inverting around the mean through 2μαx, we will re-express G^ as:

G^=HnZ0HnZf=U Zf

such that

U=HnZ0Hn=Hn(I2|0n0n|)Hn=(Hn2Hn|0n0n|)Hn=(Hn2|h0n|)Hn=(I2|h0n|Hn)=(I2|hh|)=2|hh|I

U is known as the diffusion operator, and it inverts the amplitudes about μ.

where we define |h as the Hadamard applied to n qubits in the |0 state:

|h=N1/2x{0,1}n|𝑥,whereN=2n

Finally, we can represent U as the matrix:

U=2(1N(11)1N(11))I=2N(11)(11)I=2N(1111)I

Now we plug in U into the state x

Ux{0,1}nαx|x=x{0,1}nαxU|x=x{0,1}nαx(2N(1111)I)|x=x{0,1}n(2αxN(1111)αx)|x

But we know that

x{0,1}nαxN(1111)=x{0,1}nαxN

is the sum of the amplitudes of all options divided by their number, which means it's the mean μ.

U=x{0,1}n(2αxN(1111)αxI)|x=x{0,1}n(2μαx)|x

The final step to complete G^ is to plug in Zf:

G^=x{0,1}n(2μαx)Zf|x=x{0,1}n(2μαx)(1)f(x)|x

We can see now that U is responsible for inverting the amplitude around the mean, and Zf flips the phase of the correct answer through phase kickback.

Phase Rotations

We start by splitting our set of options into two sets, set A contains "good" strings (strings we are searching for), and set B containing bad string.

We show that as:

A={x{0,1}n|f(x)=1}B={x{0,1}n|f(x)=0}wherea=|A|=number of good stringsb=|B|=number of bad strings

Now we define these sets as state vectors

|A=1axA|x|B=1bxB|x
Note

The set A and the set B are orthogonal sets, since there is no element that's shared between them, in other words, they're disjoint.

The overall system state Ψ becomes

|Ψ=α|A+β|Bα2+β2=1

Since now we need to apply our operations on |A and |B, then let's define |h in these terms.

|h=aN|A+bN|B
Applying Grover's Operator

In phase rotations representation it's beneficial to change the grouping of the operator from what we did last time. We group the operator as follows:

G^=HnZ0HnZf=(HnZ0Hn)(Zf)

We notice that the first part is similar to U, in fact, it is U, so we simplify it as:

(2|hh|I)=I2|hh|

Now for Zf, we know that Zf applies a minus sign to the correct strings, therefore it will always assign a minus sign to all strings in A, so we can say

Zf|A=()|A=|A

We also know that Zf will not apply the minus sign for any string in B, so we can say

Zf|B=(+)|B=|B

Now, we start applying the operator to the system then expanding it out to the state vectors |A and |B.

G^|Ψ=αG^|A+βG^|B

Now we can apply the operator to each state vector separately.

G^|A=(I2|hh|)(Zf)|A=(I2|hh|)|A=|A2|hh|Abuth|A=(aNA|+bNB|)|A=aNA|A+bNB|A=aN1+bN0=aN

This makes sense because h| has an equal amplitude for all options (1N) and |A has 1s only for the set A strings.

=|A2|hh|A=|A2|haN=|A2(aN|A+bN|B)aN=|A2(aN|A+abN|B)=|A2aN|A2abN|B=(12aN)|A2abN|BG^|A=(12aN)|A2abN|B

Now we apply G^ to |B

G^|B=(I2|hh|)(Zf)|B=(I2|hh|)(1)|B=(2|hh|I)|B=2|hh|B|B=2|hbN|B=2(aN|A+bN|B)bN|B=2abN|A+2bN|B|B=2abN|A+(2bN1)|BG^|B=2abN|A(12bN)|B

Finally, we get it all together to finish applying G^ to the state |Ψ.

G^|Ψ=αG^|A+βG^|B=α((12aN)|A2abN|B)+β(2abN|A(12bN)|B)
G^ as a Rotation Operator

Let's define G^ as a unitary matrix

G^=((12bN)2abN2abN12aN)

We notice that we can rewrite this matrix as

G^=((12bN)2abN2abN12aN)=(bNaNaNbN)2

which is similar to the rotation matrix in Euclidean space

R(θ)=(cosθsinθsinθcosθ)

Therefore, we can represent G^ as a rotation matrix which means that we can say the following.

Grover's operator is two rotation operators in Euclidean space, where:

cosθ=bNsinθ=aN

such that after k applications of G^ the state of the system can be represented as

|Ψ=cos((2k+1)θ)|B+sin((2k+1)θ)|A

where the goal of the algorithm is to maximize sin((2k+1)θ), such that sin((2k+1)θ)1.

Here we draw one application of G^ on the unite circle where:

Pasted image 20240701231210.png

Note

Notice that the starting state |Ψ doesn't have to be in between |A and |B (θ=π4). The starting angle depends on the ratio of good and bad options ab.

Calculating k

Since out goal is to get sin((2k+1)θ)1, we can figure out k as follows:

sin((2k+1)θ)1(2k+1)θπ2kπ4θ12butsinθ=aNθ=arcsin(aN)θaN
Important

Since the use of this algorithm only makes sense when we have a massive number of options to search through, we can assume that

aN0

And therefore, we can approximate arcsin to be

arcsin(aN)aN
kπ4θ12π4aN12πNa412kπNa412
Note

The computed value of k is a lower bound of k.

Complexity Analysis

We can assume that G^ is a constant-time operation (O(1)), therefore we can define the time complexity by the number of iterations k.

For the worst-case scenario we will assume a=1.

k=πN1412=πN412O(k)=O(πN412)=O(N)

This proves that Grover's search algorithm offers a quadratic speed up over classical search of unstructured data.

Classical Search Grover's Search
O(N) O(N)

Circuit Implementation of the Diffusion Operator (U)

We discussed the application and effect of Grover's diffusion operator U, but we didn't explore how it's implemented in a quantum circuit. Recall that

U=2|hh|I

Let's see how we can implement that in a circuit. Note that we will be implementing U instead of U, which will not effect the measurement results as long as we are consistent.

Now let's expand the form U to be able to construct the gates.

U=I2|hh|=I2(Hn|00|Hn)=HnHn2Hn|00|Hn=Hn(Hn2|00|Hn)=Hn(I2|00|)Hn

We can see that we have two Hadamard operators at each end which we can simply implement with two Hadamard gates. Since we know how to implement the Hadamard operators, let's discard of them.

Hn(I2|00|)HnI2|00|

But from constructing the diffusion operator earlier we know that the remaining part is just flipping the sign of the zero state |0, which we can do with a Controlled-Z gate, but since we are looking for the zero-state and not the one-state we need to flip all the states before the Controlled-Z gate, then flip them back.

Finally, we can implement the diffusion operator as shown in the image:

U operator.png|700

Applying Multi-Controlled-Z Gate

Notice that we can apply the MCZ gate to an arbitrary target since it would result in the same effect of flipping the sign of the entire state.

We also notice that the target bit of the Z gate is not contributing to the control, and that's because it is indirectly controlling the application of the Z gate, since Z|0=|0 and only Z|1=|1

Summary

Grover's algorithm employs the following steps:

  1. Let X be an n-qubit register, initialized to |0n. Using n Hadamard gates (Hn), put X in a uniform superposition:

    |0nHnN1/2x{0,1}n|𝑥=|h
  2. Apply the unitary transformation G^=HnZ0HnZf to register X k times.

  3. Measure register X and output result.

Grover's search algorithm offer a quadratic speed up over classical search (linear search) for unstructured data.


< Prev