#have to install the qiskit library first before we do anything
!pip install qiskit
#do our usual installation of some standard libraries
%matplotlib inline
import numpy as np
#you need to get your personal IBM Token from IBM Quantum Experience
#put your token inside '*****'
token='******'
from qiskit import QuantumCircuit, execute, Aer, IBMQ
IBMQ.save_account(token)
from qiskit.compiler import transpile, assemble
from qiskit.tools.jupyter import *
from qiskit.visualization import *
from qiskit import QuantumCircuit, QuantumRegister, ClassicalRegister
provider = IBMQ.load_account()

#execute this cell to start the initialization process
n = 3 #number of qubits
grover_circuit = QuantumCircuit(n)

# complete this code block to initialize all the qubits with Hadamards, and then draw the circuit
# initialize circuit here between lines
#__________________________________________
#________________________________________
grover_circuit.draw()

# Copy and past your code for the Oracle from the IBM Composer here
# Execute this cell to have the full circuit drawn for you so you can
# double check everything looks right.
#copy/paste code here between the lines
#_____________________________
#_____________________________
#draw the circut to show the gates you have added
grover_circuit.draw()

# This cell adds a general diffuser to the grover circuit.
#add Hadamards to all qubits
grover_circuit.h(0)
grover_circuit.h(1)
grover_circuit.h(2)
#add X to all qubits
grover_circuit.x(0)
grover_circuit.x(1)
grover_circuit.x(2)
#perform a multi-controled z gate using primitive gates
grover_circuit.barrier(0,1,2)
grover_circuit.h(2) #this always goes on last qubit
grover_circuit.ccx(0,1,2) #the target is always the last quibt, with controls from all others
grover_circuit.h(2) #this always goes on last qubit
grover_circuit.barrier(0,1,2)
#add more X gates to all qubits
grover_circuit.x(0)
grover_circuit.x(1)
grover_circuit.x(2)
#add more Hadamards to all qubits
grover_circuit.h(0)
grover_circuit.h(1)
grover_circuit.h(2)

grover_circuit.draw()

sv_sim = Aer.get_backend('statevector_simulator')
job_sim = execute(grover_circuit, sv_sim)
statevec = job_sim.result().get_statevector()
grover_circuit.measure_all()
qasm_simulator = Aer.get_backend('qasm_simulator')
shots = 1024
results = execute(grover_circuit, backend=qasm_simulator, shots=shots).result()
answer = results.get_counts()
plot_histogram(answer)

backend = provider.backend.****** # replace the **** with the name of the computer you want to use EXAMPLE: ibmq_quito
shots = 1024
results = execute(grover_circuit, backend=backend, shots=shots).result()
answer = results.get_counts()
plot_histogram(answer)