Git Product home page Git Product logo

deutschjozsaalgorithm's Introduction

Deutsch-Jozsa Algorithm using Qiskit

The Deutsch-Jozsa algorithm is a quantum algorithm for determining the properties of Boolean functions. Specifically, it can determine whether a given function is constant or balanced, where a constant function always evaluates to the same output (either 0 or 1), and a balanced function evaluates to 0 for half of its inputs and 1 for the other half. It solves the problem of determining the properties of Boolean function on a single input in one query, where a classical algorithm would take at least n/2 queries where n is number of bits in input.

It is one of the first examples of quantum algorithms that provided exponential speedup over their classical counterparts. The circuit diagram of the Deutsch-Jozsa algorithm is as follows for 3 Qubit input:

     ┌───┐      ░ ┌─────────────────┐ ░ ┌───┐ ░ ┌─┐   
q_0: ┤ H ├──────░─┤0                ├─░─┤ H ├─░─┤M├───
     ├───┤      ░ │                 │ ░ ├───┤ ░ └╥┘┌─┐
q_1: ┤ H ├──────░─┤1                ├─░─┤ H ├─░──╫─┤M├
     ├───┤┌───┐ ░ │                 │ ░ └───┘ ░  ║ └╥┘
q_2: ┤ X ├┤ H ├─░─┤2 A Oracle Block ├─░───────░──╫──╫─
     └───┘└───┘ ░ │  That We Don't  │ ░       ░  ║  ║ 
c_0: ═════════════╡0     Know       ╞════════════╩══╬═
                  │                 │               ║ 
c_1: ═════════════╡1                ╞═══════════════╩═
                  └─────────────────┘                 

Usage

It is recommended to use a virtual environment to run the program. To install the required dependencies, run the following command:

$ pip3 install -r requirements.txt

To run the program interface, simply run the following command:

$ python3 djalgorithm.py

Application Interface

from djalgorithm import DJAlgorithm

n = 4  # Number of qubits.

# Create a function to test with.
# some_function = DJAlgorithm.give_a_constant_function(n)
some_function = DJAlgorithm.give_a_balanced_function(n)

# Use the Deutsch-Jozsa algorithm to solve which function it is.
result = DJAlgorithm.simulate(some_function)

# Print the result.
print(result["result"])

deutschjozsaalgorithm's People

Contributors

electricalgorithm avatar

Watchers

 avatar

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.