Simulation of Quantum Search Algorithm

The rapid progress of computer science has been accompanied by a corresponding evolution of computation, from classical computation to quantum computation. As quantum computing is on its way to becoming an established discipline of computing science, much effort is being put into the development of new quantum algorithms. One of quantum algorithms is Grover's algorithm, which is used for searching an element in an unstructured list of N elements with quadratic speed-up over classical algorithms. In this work, Quantum Computer Language (QCL) is used to make a Grover's quantum search simulation in a classical computer document.


Introduction
These instructions give you guidelines for preparing papers for Journal of Computer Science and Information ± Universitas Indonesia. Use this document as a template if you are using Microsoft Word 6.0 or later. Otherwise, use this document as an instruction set. Instructions about final paper and figure submissions in this document are for Journal of Computer Science and Information ± Universitas Indonesia; please use this document DV D ³WHPSODWH´ WR SUHSDUH \RXU PDQXVFULSW The rapid progress of computer science has been accompanied by a corresponding evolution of computation, from classical computation to quantum computation. In classical computation, computer memory made up of bits, where each bit represents either a one or a zero. In quantum computation, there are some quantum mechanical phenomena, such as superposition and entanglement, to perform operations on data.
Instead of using bits, quantum computation uses qubits (quantum bits). A single qubit can represent a one, a zero, or both at the same time, which is called superposition. Because of this ability, quantum computation can perform many tasks simultaneously, faster than classical computing. There is also another phenomenon in quantum computation which is called entanglement. If two qubits get an outside force, then those qubits can be entangled condition. It means that, even the distance of both qubits is far, treating one of them will affect the other qubit too. For example, there are two entangled qubits, and one of them has spin up (we know it after done a measurement). Then without have to measure it, we can directly know that the other qubit has spin down. Because of this ability, communication in quantum computation can reach a very high speed because information can be transferred instantly, very fast like it overmatches the speed of light.
As quantum computing is on its way to becoming an established discipline of computing science, much effort is being put into the development of new quantum algorithms. One of quantum algorithms is Grover algorithm, which is used for searching an element in an unstructured list of N elements with quadratic speed-up over classical algorithms. Today, there are some quantum programming languages which can be used to simulate quantum mechanical and quantum algorithm without having a real quantum computer. In this work, Quantum Computer Language (QCL) will be used WR PDNH D *URYHU ¶V quantum search simulation in a classical computer.
This research is related to an invention of a quantum search algorithm by Lov K. Grover [1]. His invention presents an algorithm, which is known as Grover algorithm that is significantly faster than any classical algorithm can be. This quantum search algorithm can search for an element in an unsorted database containing N elements only in O( N ) steps, while in the models of classical computation, searching an unsorted database cannot be done in less than linear time (so merely searching through every item is optimal), which will be done in O(N) steps. Also, this research will also try to simulate Grover algorithm in a classical computer using one of quantum programming languages, Quantum Computer Language (QCL) [2,3].
In practice, this research can be used as the fastest known method or solution for searching an element in an unsorted database containing N elements. By using the method in this research, the searching process can speed-up quadratically over classical algorithms.
Considered points in this work are: 1. Is it possible to simulate Grover algorithm in a classical computer? 2. How many qubits and iterations the program needed to search an element? 3. How minimum and maximum the size of elements in the database that the program can hold?
The objective of this work is to to make a simulation of Grover algorithm using Quantum Computer Language (QCL), to know how many qubits and iterations needed for the searching process, and to know how minimum and maximum the size of elements in the database that can be hold by the program. This paper concerns on simulating Grover algorithm in a classical computer using Quantum Computer Language (QCL). The program can search a desired element in an unsorted database of N elements. This work begins with designing pseudocode for Grover algorithm. Then, the design will be implemented by using Quantum Computer Language. After that, there will be several test to know how many qubits and iterations needed for the searching process, also to know how minimum and maximum the size of elements in the database that can be hold by the program.

Literature Review
Computer science has grown faster, made an evolution in computation. Research has already begun on what comes after our current computing revolution. This research has discovered the possibility for an entirely new type of computer, one that operates according to the laws of quantum physics -a quantum computer.

Way to Quantum Computation
Quantum computers were first proposed in the 1970s and 1980s by theorists such as Richard Feynman, Paul Benioff, and David Deutsch. At those times, many scientists doubted that they could ever be made practical. Richard Feynman was the first to suggest, in a talk in 1981, that quantum-mechanical systems might be more powerful than classical computers. In this lecture [4], reproduced in the International Journal of Theoretical Physics in 1982, Feynman asked what kind of computer could simulate physics and then argued that only a quantum computer could simulate quantum physics efficiently. He focused on quantum physics rather than classical physics. He said that naturH LVQ ¶W FODVVLFDO DQG LI ZH ZDQW WR PDNH D VLPXODWLRQ RI QDWXUH ZH ¶G EHWWHU PDNH it quantum mechanical, because it does not look so easy. Around the same time, in a paper titled "Quantum mechanical models of Turing machines that dissipate no energy" [5] and related articles, Paul Benioff demonstrated that quantummechanical systems could model Turing machines. In other words, he proved that quantum computation is at least as powerful as classical computation. But is quantum computation more powerful than classical computation? David Deutsch explored this question and more in his 1985 paper "Quantum theory, the Church-Turing principle and the universal quantum computer" [6]. First, he introduced quantum counterparts to both the Turing machine and the universal Turing machine. He then demonstrated that the universal quantum computer can do things that the universal Turing machine cannot, including generate genuinely random numbers, perform some parallel calculations in a single register, and perfectly simulate physical systems with finite dimensional state spaces. In 1989, in "Quantum computational networks" [7], Deutsch described a second model for quantum computation: quantum circuits. He demonstrated that quantum gates can be combined to achieve quantum computation in the same way that Boolean gates can be combined to achieve classical computation. He then showed that quantum circuits can compute anything that the universal quantum computer can compute, and vice versa.

Superposition
Superposition is the fundamental law of quantum mechanics. It defines the collection of all possible states that an object can have. Superposition means a system can be in two or more of its states simultaneously. For example a single particle can be traveling along two different paths at once.
The principle of superposition states that if the world can be in any configuration, any possible arrangement of particles or fields, and if the world could also be in another configuration, then the world can also be in a state which is a superposition of the two, where the amount of each configuration that is in the superposition is specified by a complex number.
For example, if a particle can be in position A and position B, it can also be in a state where it is an amount "3i/5" in position A and an amount "4/5" in position B. To write this, physicists usually say: In the description, only the relative size of the different components matter and their angle to each other are on the complex plane. This is usually stated by declaring that two states which are a multiple of one another are the same as far as the description of the situation is concerned.

\ D \ |
The fundamental dynamical law of quantum mechanics is that the evolution is linear, meaning that if the state A turns into $ ¶ and B turns into % ¶ after 10 seconds, then after 10 seconds the superposition \ turns into a mixture of $ ¶ and % ¶ with the same coefficients as $ ¶ and % ¶.
Example: A particle can have any position, so that there are different states which have any value of the position x. These are written: x The principle of superposition guarantees that there are states which are arbitrary superpositions of all the positions with complex coefficients: If the index is over R, then the sum is not defined and is replaced by an integral instead. The quantity ) (x \ is called the wavefunction of the particle.
If a particle can have some discrete orientations of the spin, say the spin can be aligned with the z-axis or against it , then the particle can have any state of the form:

C C
If the particle has both position and spin, the state is a superposition of all possibilities for both: The configuration space of a quantum mechanical system cannot be worked out without some physical knowledge. The input is usually the allowed different classical configurations, but without the duplication of including both position and momentum.
A pair of particles can be in any combination of pairs of positions. A state where one particle is at position x and the other is at position y is written ¨x,y ². The most general state is a superposition of the possibilities: The description of the two particles is much larger than the description of one particle; it is a function in twice the number of dimensions. This is also true in probability, when the statistics of two random things are correlated. If two particles are uncorrelated, the probability distribution for their joint position ) , ( y x P is a product of the probability of finding one at one position and the other at the other position: In quantum mechanics, two particles can be in special states where the amplitudes of their position are uncorrelated. For quantum amplitudes, the word entanglement replaces the word correlation, but the analogy is exact. A disentangled wavefunction has the form: while an entangled wavefunction does not have this form. Like correlation in probability, there are many more entangled states than disentangled ones. For instance, when two particles which start out with an equal amplitude to be anywhere in a box have a strong attraction and a way to dissipate energy, they can easily come together to make a bound state. The bound state still has an equal probability to be anywhere, so that each particle is equally likely to be everywhere, but the two particles will become entangled so that wherever one particle is, the other is too.

Entanglement
Quantum entanglement, also called the quantum non-local connection, is a property of a quantum mechanical state of a system of two or more objects in which the quantum states of the constituting objects are linked together so that one object can no longer be adequately described without full mention of its counterpart -even if the individual objects are spatially separated in a space-like manner. The property of entanglement was understood in the early days of quantum theory, although not by that name. Quantum entanglement is at the heart of the EPR paradox developed in 1935. This interconnection leads to non-classical correlations between observable physical properties of remote systems, often referred to as nonlocal correlations.
Quantum mechanics holds that observable, for example, spin are indeterminate until such time as some physical intervention is made to measure the observable of the object in question. In the singlet state of two spins it is equally likely that any given particle will be observed to be spinup as that it will be spin-down. Measuring any number of particles will result in an unpredictable series of measures that will tend more and more closely to half up and half down. However, if this experiment is done with entangled particles the results are quite different. For example, when two members of an entangled pair are measured, their spin measurement results will be correlated. Two (out of infinitely many) possibilities are that the spins will be found to always have opposite spins (in the spin anti-correlated case), or that they will always have the same spin (in the spin correlated case). Measuring one member of the pair therefore tells you what spin the other member would have if it were also measured. The distance between the two particles is irrelevant.
7KHRULHV LQYROYLQJ ¶KLGGHQ YDULDEOHV ¶ KDYH been proposed in order to explain this result; these hidden variables account for the spin of each particle, and are determined when the entangled pair is created. It may appear then that the hidden variables must be in communication no matter how far apart the particles are that the hidden variable describing one particle must be able to change instantly when the other is measured. If the hidden variables stop interacting when they are far apart, the statistics of multiple measurements must obey an inequality (called %HOO ¶V LQHTXDOLW\ ZKLFK LV KRZHYHU YLRODWHGboth by quantum mechanical theory and in experiments. When pairs of particles are generated by the decay of other particles, naturally or through induced collision, these pairs may be termed "entangled", in that such pairs often necessarily have linked and opposite qualities, i.e. of spin or charge. The assumption that measurement in effect "creates" the state of the measured quality goes back to the arguments of, among others: Schroedinger, and Einstein, Podolsky, and Rosen FRQFHUQLQJ +HLVHQEHUJ ¶V XQFHUWDLQW\ SULQFLSOH DQG its relation to observation (see also the Copenhagen interpretation). The analysis of HQWDQJOHG SDUWLFOHV E\ PHDQV RI %HOO ¶V WKHRUHP can lead to an impression of non-locality (that is, that there exists a connection between the members of such a pair that defies both classical and relativistic concepts of space and time). This is reasonable if it is assumed that each particle GHSDUWV WKH VFHQH RI WKH SDLU ¶V FUHDWLRQ LQ DQ ambiguous state (as per a possible interpretation of Heisenberg). In such a case, for a given measurement either outcome remains a possibility; only measurement itself would precipitate a distinct value. On the other hand, if each particle departs the scene of its "entangled creation" with properties that would unambiguously determine the value of the quality to be subsequently measured, then a postulated instantaneous transmission of information across space and time would not be required to account for the result. The Bohm interpretation postulates that a guide wave exists connecting what are perceived as individual particles such that the supposed hidden variables are actually the particles themselves existing as functions of that wave.
Observation of wavefunction collapse can lead to the impression that measurements performed on one system instantaneously influence other systems entangled with the measured system, even when far apart. Yet another interpretation of this phenomenon is that quantum entanglement does not necessarily enable the transmission of classical information faster than the speed of light because a classical information channel is required to complete the process.

Hadamard Transform
The Hadamard transform (also known as the Walsh-Hadamard-transform, Hadamard-Rademacher-Walsh-transform, Walsh-transform, or Walsh-Fourier transform) is an example of a generalized class of Fourier transforms. It is named for the French mathematician Jacques Solomon Hadamard, the German-American mathematician Hans Adolph Rademacher, and the American mathematician Joseph Leonard Walsh. It performs an orthogonal, symmetric, involutional, linear operation on m 2 real numbers (or complex numbers, although the Hadamard matrices themselves are purely real).
The Hadamard transform can be regarded as being built out of size-2 discrete Fourier transforms (DFTs), and is in fact equivalent to a multidimensional DFT of size 2 2 2 2 u u . It decomposes an arbitrary input vector into a superposition of Walsh functions.
The Hadamard transform m H is a m m 2 2 u matrix, the Hadamard matrix (scaled by a normalization factor), that transforms m 2 real numbers x into m 2 real numbers k x . The Hadamard transform can be defined in two ways: recursively, or by using the binary (base-2) representation of the indices n and k .
Recursively, we define the 1 1u where the 2 / 1 is a normalization that is sometimes omitted. Thus, other than this normalization factor, the Hadamard matrices are made up entirely of 1 and -1. where the k j and n j are the binary digits (0 or 1) of n and k, respectively. In this case, we have: where i j is the bitwise dot product of the binary representations of the numbers i and j. For example, agreeing with the above (ignoring the overall constant). Note that the first row, first column of the matrix is denoted by 00 H . The rows of the Hadamard matrices are the Walsh functions.
In quantum information processing the Hadamard transformation, more often called Hadamard gate, is a one-qubit rotation, mapping the qubit-basis states ² 0 | and ² 1 | to two superposition states with equal weight of the computational basis states ² 0 | and ² 1 | . Usually the phases are chosen so that we have in Dirac notation. This corresponds to the transformation matrix Many quantum algorithms use the Hadamard transform as an initial step, since it maps n qubits initialized with ² 0 | to a superposition of all n 2 orthogonal states in the ² 0 | , ² 1 | basis with equal weight. Hadamard gate operations:
In models of classical computation, searching an unsorted database cannot be done in less than linear time (so merely searching through HYHU\ LWHP LV RSWLPDO *URYHU ¶V DOJRULWKP illustrates that in the quantum model searching can be done faster than this; in fact its time complexity O(N1/2) is asymptotically the fastest possible for searching an unsorted database in the quantum model. It provides a quadratic speedup.
There are already related works about Grover algorithm, such as done by Matthew Whitehead, Ahmed Younes, and C. Lavor et.al., 0DWWKHZ :KLWHKHDG ¶V SDSHU [8] shows how *URYHU ¶V TXDQWXP VHDUFK PD\ EH XVHG WR LPSURYH the effectiveness of traditional genetic search on a classical computer. He uses repeated applications RI *URYHU ¶V $OJRULWKP WR JHW D YDULHW\ RI GHFHQW chromosomes that will then be used to form a starting population for classical genetic search. He also provides the pseudo code for the modified genetic search, which is a combination between *URYHU ¶V TXDQWXP VHDUFK DQG VWDQGDUG JHQHWLF search. Another work related to Grover algorithm is done by Ahmed Younes. In his paper [9], he described the peUIRUPDQFH RI *URYHU ¶V DOJRULWKP, and also wrote a review about Grover algorithm by means of a detailed geometrical interpretation and a worked out example. Some basic concepts of Quantum Mechanics and quantum circuits are also reviewed.

Design and Implementation
Many problems in classical computer science can be reformulated as searching a list for a unique element which matches some predefined condition. If no additional knowledge about the search-condition C is available, the best classical algorithm is a brute-force search i.e. the elements are sequentially tested against C and as soon as an element matches the condition, the algorithm terminates. For a list of N elements, this requires an average of N/2 comparisons. By taking advantage of quantum parallelism and interference, Grover found a quantum algorithm [1] which can find the matching element in only O( N )steps.
In this paper, Grover algorithm and its implementation will be explained process by process. The algorithm consists of two parts: (1) H Input and initialization (2) Main loop. Each of the parts will be explained and implemented one by one below.

Input and Initialization 3.1.1. Input
This simulation needs to know what number it should search, so user will be prompted to input a round number (integer). The implementation of this input process can be seen below. input "Enter an integer that that will be find:",bil; In the code implementation above we can see that bil is a variable that is used to store the round number.

Initialization
Initialization is a process to initiate variables and qubit registers needed in the simulation.
The most important variables that we have to initiate are the number of qubits and the number of iterations needed. Assume that the number of qubits is called sumqubit, and the number of iterations is called iteration. To calculate the number of qubits needed, we can use this formula: To calculate the number of iterations needed, we can use this formula: Then, after the value of both sumqubit and iteration are known, another important step to do is to set up the registers for each qubits. Also, some variables need to be listed to for common process; looping, storing result, etc. The code implementation for initialization can be seen below.

Main Loop
Main loop is the main process to begin searching. The steps to do in the main loop are: 1. Reset all qubits to 0 and apply the Hadamard transform to each of them. 2. Repeat the following operation as much as the number of iterations needed (see the initialization part): x Rotate the marked state by a phase of S radians ( S f I ). A query function needs to be applied. The query function is needed to flip the variable f if x (the qubits) is equal to 1111... x Apply a phase process between S and f.
x Undo the query function.
x Apply a diffusion function. The process are apply Hadamard transform, invert q, then apply a phase process between S and q (rotate if q=1111..). After that, undo the invert process and undo Hadamard transform.
x Do an oracle function by measure the quantum register that has been found, and then compare the result to the input.
These iterations must be repeated again if the measurement result does not match with the wanted number.
The code implementation of the main loop including the functions in it can be seen below.

Oracle Procedure
This procedure is for checking whether the measurement result is match with the wanted number or not. In general, the oracle function can be formulated as below.
x is the indexes in the database, and x 0 is the wanted index. Back to the simulation, before we implement the oracle, we need to do a measurement to check if the number that been found is already matched with the wanted number. The code implementation can be seen below.

Results and Discussion
The GURYHU ¶V TXDQWXP VHDUFK simulation can be running from LLQX[ ¶V WHUPLQDO E\ JRLQJ WR WKH directory where the file is put in then typing "qcli -b32 SimulasiGrover.qcl". This command will start QCL then run a file named SimulasiGrover.qcl, and providing all qubits that QCL has (32 qubits).
To discuss the results of the program, Table  I. containing ten outputs from GURYHU ¶V TXDQWXP search simulation program is provided.
In Table I, column "Input" is for the number that the user wants to find. Column "Qubits" is the total of qubits needed to search the number. Column "Iterations" is the total iterations needed to find one number to be measuring. Column "List of Measured Numbers" is the list of numbers that are found and get measured until the number is same to the input. Column "Total Iterations" is the total of iterations needed to find the correct number. The value of this column is the multiplication of the value in column "Iterations" and the amount of numbers in column "List of Measured Number. From the table, we can see that the number of qubits and the number of iterations needed are depend on the value of the number that user wants to find. If the number is bigger, so will the qubits and the iterations be. Sometimes, the number that the program found is not matched with the input. If this condition is happen, the program will do the iterations again until the number is matched with the input. But even the program do the iterations more than one round, the total iterations is never exceed the value of the input. We can see this from the table in the column "Total IWHUDWLRQV %XW WKLV *URYHU ¶V TXDQWXP VHDUFK simulation has a limitation; the maximum qubits that the program can use is only 32 qubits (QCL limitation). For the possible real implementation, Grover ¶V algorithm can be used for searching a record in database and improving the traditional genetic search.

Concluding Remarks
8VLQJ 4&/ D *URYHU ¶V TXDQWXP VHDUFK simulation has been made. It is performed without using a quantum computer, but using a classic computer. To search an element, the program needs to use qubit instead of bit. The number of qubits needed depend on the value of the number that we want to find. The bigger the value of the number, the bigger qubits needed. It goes the same with the number of iterations needed. The minimum value for the number is 1, and the maximum value is depending on the qubits needed. At this far, the program has been tested to VHDUFK QXPEHU WLOO 7KLV *URYHU ¶V TXDQWXP search is just a simulation to simulate the algorithm, not a real quantum searching program that can be implemented on the real database.
7KLV *URYHU ¶V TXDQWXP VHDUFK is just a simulation of quantum search in a classic computer. That is some possible works for the future related to Grover algorithm. Some of them is implementing Grover algorithm in a real database using quantum computer, but in this case, the database must be converted in to quantum states which is probably the most difficult thing to do. Another possible work is improving the traditional genetic search by combine it with Grover ¶V algorithm.