Created
May 2, 2020 07:14
-
-
Save GDLMadushanka/9a2d3496c54411f9651678621256064a to your computer and use it in GitHub Desktop.
Grover's oracle
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 * | |
from qiskit.tools.visualization import plot_histogram | |
from qiskit.tools.visualization import plot_state_city | |
from qiskit.providers.aer import StatevectorSimulator | |
# Creating quantum circuit with 3 qubits | |
qc = QuantumCircuit(3) | |
# Preparing inputs | |
qc.h(0) | |
qc.h(1) | |
qc.h(2) | |
qc.barrier() | |
# Oracle function for number 5 = 101 | |
qc.x(1) | |
qc.h(2) | |
qc.ccx(0,1,2) | |
qc.x(1) | |
qc.h(2) | |
qc.barrier() | |
qc.draw(output='mpl') | |
backend = Aer.get_backend('statevector_simulator') | |
result = execute(qc, backend, shots=1024).result() | |
# Get the statevector from result(). | |
statevector = result.get_statevector(qc) | |
plot_state_city(statevector) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment