Skip to content

Instantly share code, notes, and snippets.

@GDLMadushanka
Created May 1, 2020 13:00
Show Gist options
  • Save GDLMadushanka/60211fb73a0ba616929c210803be6402 to your computer and use it in GitHub Desktop.
Save GDLMadushanka/60211fb73a0ba616929c210803be6402 to your computer and use it in GitHub Desktop.
Deutsch–Jozsa single bit code
from matplotlib import pyplot as plt
import numpy as np
from qiskit import *
from qiskit.tools.visualization import plot_histogram
# Creating a circuit with 3 quantum bits and 2 classical bit
qc = QuantumCircuit(2,1)
# Preparing inputs
qc.h(0)
qc.x(1)
qc.h(1)
qc.barrier()
# Oracle function 1
# Oracle function 2
#qc.x(1)
# Oracle function 3
#qc.cx(0,1)
# Oracle function 4
#qc.cx(0,1)
#qc.x(1)
qc.barrier()
# Preparing output
qc.h(0)
qc.barrier()
# measuring the results
qc.measure(0,0)
qc.draw(output='mpl')
# Running the experiment in simulator
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc,backend=simulator,shots=1024).result()
plot_histogram(result.get_counts())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment