GithubHelp home page GithubHelp logo

haimasker / grover-search-algorithm Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 1.0 6 KB

Grover's search algorithm written in C++

C++ 100.00%
cpp grover-algorithm grovers-algorithm gsa matrix oop quantum quantum-algorithms quantum-computing quantum-gates qubit qubit-gates qubits

grover-search-algorithm's Introduction

Grover's search algorithm (GSA)

Simple C++ implementation of Grover's search algorithm with Qubit class.

GitHub code size in bytes Number of lines of code Code language count GitHub top language


Preamble

The purpose of this project is to create functions that implements Grover's quantum search algorithm.
Qubit quantum register is presented via Qubit class.

GSA is the quantum algorithm that finds root $x$ of some function $f(x)$ among the values $1...N$.
Usage of a quantum register allows not to perform a brute force to find root of the function.
There are two types of this algorithm: $f(x)$ has only one root and $f(x)$ has at least one root (singleGSA() and multipleGSA respectively).


Description

First of all, I recommend you to read some theoretical information about GSA and understand how it works here and here.
Let's tale a closer look to phase Oracle and Grover's diffusion operators (query and diffusion matrices in programm respectively).

  • Phase Oracle matrix has the following form:
        [ 1 0 ........ 0 ]
        [ 0 1 0 ...... 0 ]
query = [ .............. ]
        [ 0 ... -1 ... 0 ]
        [ 0 0 ........ 0 ]

So, the phase Oracle matrix is the square diagonal matrix with ones, but there is -1 at the row the number of which is equal to the root of the function.
The phase Oracle applies a conditional phase shift of −1 for the solution item.
Query matrix for the multiple roots case defines similarly.

  • Diffusion matrix has the following form:
            [ 2/N-1 2/N ........ 2/N ]
            [ 2/N   2/N-1 ...... 2/N ]
diffusion = [ ...................... ]
            [ 2/N ........ 2/N-1 2/N ]
            [ 2/N ........ 2/N 2/N-1 ]

The Grover's diffusion operator can be geometrically interpreted as a reflection in the vector space about the uniform superposition state.


Functions

  • singleGSA - takes qubit register size and solution item index.
    If index is equal to 0 then it determines randomly.
void singleGSA(unsigned, unsigned = 0);
  • multipleGSA - takes qubit register size and vector of solution items indices.
    If vector is empty then it determines randomly.
void multipleGSA(unsigned, std::set<unsigned> = {});

grover-search-algorithm's People

Contributors

haimasker avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Forkers

vishal-sys-code

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.