Acessibilidade / Reportar erro

Classical simulation of Grovers quantum algorithm

Abstract

This paper in a didactic way, presents an introduction to quantum computing where some quantum formalisms are analyzed to finally address Grover's algorithm. It is widely known that this algorithm is one of the key algorithms in quantum computing, being its ability to explode successfully the superposition principle one of the reasons. In addition, this algorithm can be used for both locating efficiently a specific element in a cluttered database and solving certain problems when it is difficult finding a proper solution, but at the same time it is very simple to try with possible candidates. Finally, a simulation of this algorithm is carried out and the results are compared with other classical algorithms to illustrate the significant potential advantages of quantum computing.

Keywords:
quantun computing; Grovers algorithm; simulation

1. Introduction

It is well known that since the mid-nineteenth century with the emergence of classical computing under the architecture of the Church-Turing and Von Neumann machines [1][1] P. Benioff. The computer as a physical system: A microscopic quantum mechanical Hamiltonian model of computers as represented by Turing machines. J. Stat. Phys. 22, 563--591 (1980)., it was possible to build a computer capable of performing basic operations such as addition and multiplication in a few seconds. Over the years, technological developments have allowed optimizing the response time of all kinds of operations; however, there are still a large number of mathematical calculations that would take decades to be solved (e.g., determining whether a large number is prime or not.). These types of complex calculations encouraged Paul Beniof [2[2] P. Benioff. Quantum mechanical Hamiltonian models of Turing machines. J. Stat. Phys. 29, 515--546 (1982)., 3[3] P. Benioff. Quantum mechanical models of Turing machines that dissipate no energy. Phys. Rev. Lett. 48, 1581--1585 (1982)., 4[4] R. P. Feynman. Simulating physics with computers. Int. J. Theor. Phys. 21, 467--488 (1982).] and Richard Feynmann [5][5] R. P. Feynman. Quantum Mechanical Computer. Foundations of Physics, 1986, Volume 16, Issue 6, pp 507--531 to reconsider the idea of using computers under the principles of quantum physics, so they started working with classical computers that they adapted and operated with some of the main principles of quantum mechanics. On the other hand, every day it becomes more difficult to handle classical computing because of the constant demands of miniaturization that electronic components require, knowing that soon it will not be possible to reduce them anymore and the laws of classical physics will not be considered anymore. An example of this is that transistors have a limit where they simply stop working properly. This limit is met when the electrons escape from the channels where they are supposed to flow because of the so-called “tunnel effect”, that in other words means if a classical particle reaches an obstacle, normally this particle can go through it and bounces back, but the electrons are quantum particles which exhibit wave behavior keeping the possibility that a significant portion of these electrons may go through the walls where they are confined. In this way, the signal can interfere through channels where it is not supposed to, causing the chip to stop working [6][6] V. Moret-Bonillo. Principios fundamentales de computación cuántica.(2013).; therefore, at some point, the technical progress will come to an end leaving space to the development of quantum mechanics.

It is important to stress that a quantum computer can perform all kinds of tasks that a classical computer does thanks to the fact that computability is the same, the difference lies in the time of convergence in the results obtained by the running algorithms since quantum computers have the ability to process information in parallel in a massive way. This is known as the superposition principle or superposition property; superposition is the fundamental law of quantum mechanics which defines the collection of all possible states that an object can have, meaning that a system can even be in two or more of its states at the same time, which allows the development of new and innovating algorithms.

Grover's algorithm is one of the most important algorithms of the quantum computing illustrating the fundamental quantum superposition principle by searching N records in an unordered sequence inspecting all possible combinations simultaneously, causing a significant reduction of the response time to O(N) steps compared with a classical algorithm. Grover's algorithm is defined as a probabilistic algorithm, so the correct answer is obtained with a certain error probability that, at the same time, can be as low as desired by running more iterations. This algorithm receives a list of numbers and simultaneously the specific data to be found; afterward, a function f which its primary goal is to assign the state f(x)=0 if the element that is being searched is not requested; otherwise, the assigned state is f(x)=1. As soon as the desired data matches a record, the amplitude of the mentioned state is modified without affecting the other elements, obtaining that in the end, the probability of one state differs completely from the rest. The simplicity and helpfulness of this algorithm stand out the speed on response times intended to implement in the computers of the future.

It is important to note that a classic simulation of the Grover algorithm and the study of other quantum algorithms has been studied in different works such as [7[7] Zhuang Jiaya; et al, Analysis and Simulation of Grover algorithm, International Journal of Machine Learning and Computer, vol 4 No1 2014,8[8] A.B Mutibara and R.Refianti. Simulation of Grover algorithm Quantum search in a Classical Computer, International Journal of computer Scince and Information security, Vol 8 No9, 2010.,9[9] Yohan Vianna, Mariana R. Barros, Malena Hor-Meyll. Classical realization of the quantum Deutsch algorithm, American Journal of Physics, 86, 914 (2018),10[10] Wang, D.S., Hill, C.D and Hollenberg, L.C.L. Simulations of Shor's algorithm using matrix product states, Quantum Inf Process (2017) 16: 176,11[11] Johansson, N. & Larsson, JÅ Efficient classical simulation of the Deutsch--Jozsa and Simon's algorithms, Quantum Inf Process (2017) 16: 233].

Unlike these works, in this article, in a didactic way and sequentially, the physical and mathematical foundations are constructed to better understand the Grover algorithm in three steps.

For the simulation of the algorithm the Java programming language is used, because it is independent of the platform and because it has no problems with the release of the system memory. The implementation of the algorithm is easy to understand and is according to previously developed concepts.

This paper has been organized in the following way: First of all, preliminary concepts are introduced and some concepts of the formalisms of quantum mechanics are illustrated which will allow introducing Grover's algorithm that will be covered in the second part. Last of all, a classical simulation of Grover's algorithm is carried out and the results are compared with other classical algorithms.

2. Preliminary concepts

2.1. About the superposition principle

Following Penrose [12][12] Roger Penrose, García Sanz Javier. Las sombras de la mente. Crítica, (1996)., "think of the position of an electron." As we know, in a classical image, the electron by an indivisible particle could be located in position A or position B, however in the mechanical quantum-image, in some sense it has the possibility of occupying both positions simultaneously. Let A be the state for the electron in position A and be B the state of the electron in position B. According to the quantum theory (principle of superposition), there are other possible states open to the electron that is written as wA+ zB where w and z are complex weight factors. If the weight factors are taken as real numbers (not negative), then it could be considered that this combination represents, in a certain sense, a weighted probability of the expected value for the position of the electron, where w and z represent the weighted probabilities of the electron in the position A or in the position B. If w=0 then the electron would certainly be in B, and if z=0 it would be in A. If w=z=1, then it represents equal possibilities for the electron in A or in B. But w and z are Complex, so that such an interpretation does not make any sense. As Penrose [12][12] Roger Penrose, García Sanz Javier. Las sombras de la mente. Crítica, (1996). states, we can not say, in familiar and everyday terms, what "means" that an electron is in a state of superposition of two places at the same time with complex w and z weights. For the moment, we must simply accept that this is really the kind of description we have to adopt for quantum-level systems. In fact, quantum superposition gives rise to many directly observable effects, such as the interference peaks of a wave electron in the double-slit experiment, the last of them made in 2008 [13][13] H.T. Schmid et al.,. Evidence of wave-particule duality for single fast hidrogen atom. Phys. Rev. Lett. 101.083201(2008) its most ambitious form, electron to electron, thus proving the quantum-mechanical hypothesis

2.2. Quantum bits and Unitary transformations.

In classical computation the minimum unit of information is the bit, which can be a 0 or 1 state. A quantum bit or qubit can be in a state that is a superposition of states 0 and 1. In mathematical formalism a qubit is a Hilbert space vector H2

Definition 2.1 A qubit or quantum bit is a normalized vector of the space of H2. Considering the base {|0,|1} of H2, any qubit can be written as |ψ= α|0+β|1, with |α|2+ |β|2=1

Definition 2.2 A system of n-qubits is a space vector H2n =i=1nH2.

Definition 2.3 A quantum algorithm consists of the evolution of a system represented by n-qubits.

To describe the states of a quantum system, the Dirac representation and notation is usually used [9][9] Yohan Vianna, Mariana R. Barros, Malena Hor-Meyll. Classical realization of the quantum Deutsch algorithm, American Journal of Physics, 86, 914 (2018).

Instead of writing the vector as v the notation ket |v is used. In particular the base {|0,|1} of H2 is written as:

(1) | 0 = ( 1 0 ) and | 1 = ( 0 1 )

Therefore, in H2any vector representing the state of a quantum system is written as:

(2) | ψ = α | 0 + β | 1 = α ( 1 0 ) + β ( 0 1 )

Definition 2.4 Every vector ket has the form:

(3) | ψ = ( α 1 α 2 . . . α N % % )

And bra a vector of the form:

(4) ψ | = ( α 1 , α 2 , ............ α N )

Definition 2.5 the scalar product of bras and kets, we call it "braket":

(5) ψ | φ = ( α 1 , α 2 , ............ α N ) ( β 1 β 2 . . . β N % % ) = a ϵ

Definition 2.6 Given a set B={|u1,|u2,......|uN},B is an orthonormal basis of HN if for all i, j we have ui|uj=δi,j={0siij1sii=j

Theorem 2.1 Let B={|u1,|u2,......|uN} be an orthonormal basis, then i=1N|uiui|=I

Demonstration.

As I|ψ=(i=1N|uiui|)(j=1Naj|uj)=i=1Nj=1N aj|uiui|uj=i=1Nai|ui=|ψ

Definition 2.7 An operator A of HN is a square matrix of dimension N and complex coefficients.

Definition 2.8 The tensor product , also called the external product between two matrices A and B, is defined as the matrix.

(6) C = A B = ( a 11 B .. .. a 1 m B . . . . a n 1 B .. .. a n m B )

Definition 2.9 The adjunct of an operator A is denoted by A and is defined as the transposed and conjugated operator of A. That is, if αij=ui|A|uj are the components of A, the components of A, are αji=uj|A|ui=ui|A|uj

Definition 2.10 An operator A is Hermitian if A=A. If it is Hermitian its diagonal must be real, since αij=αji, therefore αii=αii, that is, their eigenvalues are real.

Definition 2.11 An operator U is unitary if UU=UU=I

Definition 2.12 To the operators of the form P=|φφ| they are called projectors,since they project orthogonally any ket |Φ on a ket |φ

(7) P | Φ = | φ φ | Φ = a | φ

Definition 2.13 A set of projectors {M1,M2.....Ml} is said to be a measurement operator if

(8) i = 1 l M i M i = I

Definition 2.14 Unitary and Hermitian operators are called quantum gates.

Definition 2.15 It is said that a system represented by a ket |ψ evolves into system |φ when one of the following operations is carried out:

(9) | ψ U | φ o | ψ M | φ

Definition 2.16 Quantum gates.The most important quantum gates, for their usefulness in the design of algorithms, are the following:

Gateh of Walsh-Hadamard.

The Hadamard gate applied to n-qubits, is known as the Walsh-Hadamard transformation and produces the superposition off all 2n possible states.

This transformation is defined as:

(10) W = h h ........ h

Where h=12(1111). For example, the transformation of WalshHadamard applied to n=2 qubits is defined as:

(11) W = 1 2 ( 1 1 1 1 ) 1 2 ( 1 1 1 1 ) = 1 2 ( 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 )

3. Grover's algorithm

This algorithm is one of the most important of quantum computing since it exploits the principle of superposition to the maximum. It is a very attractive algorithm, since it can be used both to efficiently locate a certain element in a disorganized database, and to solve those problems in which it is very difficult to find a solution, but at the same time very simple tot est possible candidates. That is, a list of size N is available. The classical theory needs, on average, to read N2 values, however, the Grover algorithm requires only N interactions.

Mathematically the problem can be reduced to finding a x{0,1,2,.......N1} with N=2n, such that f(x)=a for a a known. The idea proposed by Grover is based on the implementation of a function f such that,if w denoted the x sought, then:

(12) f ( x ) = { 0 if x w 1 if x = w

From the perspective of a quantum computer, what is needed is a unitary transformationUf such that Uf|x=(1)f(x)|x={|xifxw|xifx=w

As we can observe in the previous equation, if it is a state x which is not the mark, then the transformation will have no effect on the state |x. If now

Uf|w=(1)f(w)|w then the result will be Uf|w=|w. The geometric interpretation is that the unitary matrix Uf makes a reflection in its amplitude to the marked within the set of N elements.

Grover's algorithm works in three steps as follows:

Step No1. It consists in the normalization of the amplitudes of all the states, which is achieved with a transformation of Hadamard: |s=hn|0, therefore, in the instant t=0, |ψt=0=|ψ0=|s, that is, all states have the same amplitude of probability.

Step No2. The reflection Uf is applied to all states: |ψt=Uf|ψ0 where if |ψt is the state |w, then it can be interpreted as a reflection negative |w and yes they are the non-marked states |x the transformation has not effect. Mathematically the transformation Uf has the following form:

(13) U f = I 2 | w w |

It is not difficult to observe that: Uf|w=(I2|ww|)|w=I|w2|ww|w=|w2|w=|w and that Uf|x=(I2|ww|)|x=I|x2|ww|x=I|x=|x since w|x=0.

The transformation (13) could classically be interpreted as an If-then-else selection operator.

Step No3. The third step is to apply a reflection to the state |s, which is described as:

(14) U s = 2 | s s | I

The transformation (14) modifies all the states to Us|ψt and thus completes the transformation:

(15) | ψ t + 1 = U s U f | ψ 0

The transformation (15) is amplified by the amplitude of the element marked on the average of the amplitudes.

Mathematically:

(16) | ψ t = x = 0 N 1 α x | x " , U s = ( 2 ( 1 N x = 0 N 1 | x ) ( 1 N x = 0 N 1 x | ) 1 )

therefore

U s | ψ = ( 2 ( 1 N x = 0 N 1 | x ) ( 1 N x = 0 N 1 x | ) 1 ) x = 0 N 1 α x | x "

or

U s | ψ t = ( 2 N x = 0 , x = 0 , x = 0 N 1 α x | x x | x " x = 0 N 1 α x | x

or

U s | ψ t = ( 2 N x = 0 N 1 α x " x = 0 N 1 | x x = 0 N 1 α x | x )

from where

U s | ψ t = x = 0 N 1 ( 2 x = 0 N 1 α x " N α x ) | x = x = 0 N 1 ( 2 A α x ) | x

Where A is the average of each αx .

(17) A = x = 0 N 1 α x " N

After some reductions by the summations and the average for the state |ψt+1 we have:

(18) | ψ t + 1 = U s U f | ψ t = { % 2 n + 1 + 2 n 4 2 n 2 n | x if x = w 2 n + 1 2 n 4 2 n 2 n | x if x w

When implementing the algorithm in a quantum computer it repeats the three steps, and a response with a greater amplitude of probability is obtained.

4. Simulation of Grover's algorithm.

Grover's algorithm is a search algorithm that returns the match with the highest probability to be correct from an unordered sequence of data with N elements. The running time from the classical point of view has an order of 2n but the quantum version has an order of 2n. This simulation intends to show how the running time of a quantum algorithm in a classical computer is crucial when the goal is reducing response times.

This simulation consists of three important parts:

  1. The initialization of the amplitudes of the different states obtained by the superposition, in other words, when the state of the system is for t=0, |ψt=0=|ψ0=|s=hn|0

  2. The reflection to all states, this means |ψt=Uf|ψ0 where only the marked state will be affected.

  3. And finally, the reflection that modifies all the states |ψt+1=Us|ψt completing this way the transformation.

4.1. Input of data

This simulation needs the number of Qbits that will consider executing the search. This will determine the number of records.


4.2. Data processing

This process starts by executing the initializeBinary() method which will allow printing the bit string provided by the user in binary, getting as a result a bra-ket notation array using Walsh-Hadamar transform. (12)


At the same time, the inversionMean() method is being called which calculates the reflection over the mean value, equation (16). The output shows the change of the amplitudes from the initial array, so the chance that the state collapse is higher.


4.3. Output

Finally, the simulation calculates the probability of using the amplitude to the second power using the findProbability() method.


Example

Step 1. Capture the size of the vector and the number you want to find:


Step 2. View of the initial vector in decimal and in binary:


Step 3. Capture of the numbers that the vector will store:


Step 4. View of the complete vector and the final vector after the completion of the search:


4.4. Comparison of results with other classical algorithms

The simulation of a quantum search using Grover's algorithm (G) and the simulations of sequential search (SS) and binary search (BS), allow determining the efficiency of the quantum algorithm compared to a simple search algorithm. After analyzing five different sizes of arrays, each with a sample of 20 measurements, it is possible to obtain an average which is illustrated in the next table. In the three algorithms, the simulation uses an unordered list with N elements.

vector size algorithm # of interactions response time
4 G 2 0,0028369
BS 4 0,3298
BB 3 0,28
16 G 4 0,00328628
BS 16 0,3845
BB 5 0,3
32 G 5 0,003958214
BS 32 0,3911
BB 6 0,3096
64 G 8 0,00523802
BS 64 0,3997
BB 10 0,3141
128 G 11 0,01546982
BS 128 0,4009
BB 12 0,3299

5. Conclusions

To conclude, the development of this simulation allowed understanding the scope and the potential that quantum computing may have in future's technology, it is now only necessary to create new tools that will implement algorithms such as Grover's, which not only seek to speed up and improve response times when solving mathematical calculations, but also, to start being a fundamental part of new software development that can solve many problems as computer security, where these new algorithms will be the first choice and eventually leaving behind classical computing.

Once again, it is important to point out that the potential and the speed of the Grover Algorithm and other quantum algorithms [9][9] Yohan Vianna, Mariana R. Barros, Malena Hor-Meyll. Classical realization of the quantum Deutsch algorithm, American Journal of Physics, 86, 914 (2018) lies in the fact that the principle of quantum superposition is exploited to the maximum exploiting the possibility of a coherent quantum superposition of states as input. Therefore, the quantum algorithm allows solving the problem in exponentially less time if compared to the classical procedure.

The authors thank the reviewer for the observations.

References

  • [1]
    P. Benioff. The computer as a physical system: A microscopic quantum mechanical Hamiltonian model of computers as represented by Turing machines. J. Stat. Phys. 22, 563--591 (1980).
  • [2]
    P. Benioff. Quantum mechanical Hamiltonian models of Turing machines. J. Stat. Phys. 29, 515--546 (1982).
  • [3]
    P. Benioff. Quantum mechanical models of Turing machines that dissipate no energy. Phys. Rev. Lett. 48, 1581--1585 (1982).
  • [4]
    R. P. Feynman. Simulating physics with computers. Int. J. Theor. Phys. 21, 467--488 (1982).
  • [5]
    R. P. Feynman. Quantum Mechanical Computer. Foundations of Physics, 1986, Volume 16, Issue 6, pp 507--531
  • [6]
    V. Moret-Bonillo. Principios fundamentales de computación cuántica.(2013).
  • [7]
    Zhuang Jiaya; et al, Analysis and Simulation of Grover algorithm, International Journal of Machine Learning and Computer, vol 4 No1 2014
  • [8]
    A.B Mutibara and R.Refianti. Simulation of Grover algorithm Quantum search in a Classical Computer, International Journal of computer Scince and Information security, Vol 8 No9, 2010.
  • [9]
    Yohan Vianna, Mariana R. Barros, Malena Hor-Meyll. Classical realization of the quantum Deutsch algorithm, American Journal of Physics, 86, 914 (2018)
  • [10]
    Wang, D.S., Hill, C.D and Hollenberg, L.C.L. Simulations of Shor's algorithm using matrix product states, Quantum Inf Process (2017) 16: 176
  • [11]
    Johansson, N. & Larsson, JÅ Efficient classical simulation of the Deutsch--Jozsa and Simon's algorithms, Quantum Inf Process (2017) 16: 233
  • [12]
    Roger Penrose, García Sanz Javier. Las sombras de la mente. Crítica, (1996).
  • [13]
    H.T. Schmid et al.,. Evidence of wave-particule duality for single fast hidrogen atom. Phys. Rev. Lett. 101.083201(2008)

Publication Dates

  • Publication in this collection
    11 Nov 2019
  • Date of issue
    2020

History

  • Received
    16 May 2019
  • Reviewed
    21 Aug 2019
  • Accepted
    24 Aug 2019
Sociedade Brasileira de Física Caixa Postal 66328, 05389-970 São Paulo SP - Brazil - São Paulo - SP - Brazil
E-mail: marcio@sbfisica.org.br