Created
May 1, 2020 08:25
-
-
Save GDLMadushanka/220ad685b82f08235de04110428a9764 to your computer and use it in GitHub Desktop.
Deutsch–Jozsa algorithm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from matplotlib import pyplot as plt | |
import numpy as np | |
from qiskit import * | |
# Creating a circuit with 3 quantum bits and 2 classical bit | |
qc = QuantumCircuit(3,2) | |
# Preparing inputs | |
qc.h(0) | |
qc.h(1) | |
qc.x(2) | |
qc.h(2) | |
qc.barrier() | |
# Oracle function | |
qc.cx(0,2) | |
qc.cx(1,2) | |
qc.barrier() | |
# Preparing output | |
qc.h(0) | |
qc.h(1) | |
qc.barrier() | |
# measuring the results | |
qc.measure(0,0) | |
qc.measure(1,1) | |
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()) | |
# Running the experiment in actual IBM quantum computer | |
IBMQ.load_account() | |
job = execute(qc,IBMQ.get_provider('ibm-q').get_backend('ibmq_16_melbourne')) | |
# Job status = queued -> finished | |
job_monitor(job) | |
plot_histogram(job.result().get_counts()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment