Skip to content

This algorithm lets you to find a the type of a binary function in O(1) complexity instead of classical O(n/2) approach. This repository is an application interface to use Deutsch-Jozsa Algorithm.

License

Notifications You must be signed in to change notification settings

electricalgorithm/DeutschJozsaAlgorithm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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"])

About

This algorithm lets you to find a the type of a binary function in O(1) complexity instead of classical O(n/2) approach. This repository is an application interface to use Deutsch-Jozsa Algorithm.

Topics

Resources

License

Stars

Watchers

Forks

Languages