# Do not forget to Import Qiskit 

from qiskit.visualization import * 
from qiskit import * 

S_simulator=Aer.backends(name='statevector_simulator')[0] 
M_simulator=Aer.backends(name='qasm_simulator')[0] 

# We will have two top qubits (n=2) and one bottom qubit so our circuit 
# will have 3 qubits in total. 

# Initialize ***

grover = QuantumCircuit(3,3)

# put the last qubit into the |1> state.

one=[0,1]

grover.initialize(one, 1)

#barrier to seperate steps for organization 
grover.barrier()

# Apply H to all the gates *** 
grover.h(0)
grover.h(1)
grover.h(2)

#barrier to seperate steps for organization 
grover.barrier()

#Black box Oracle ***
grover.append(circuit.library.MCXGate(2, ctrl_state='10'), [0,1,2]) 
grover.barrier()

# Phase Shift ***

# Apply H to top qubits
grover.h(0)
grover.h(1) 

# Apply X to top qubits
grover.x(0)
grover.x(1)

#barrier for organization
grover.barrier()


# H on second qubit
grover.h(1)

#barrier for organization
grover.barrier()

# Cnot on first and second qubits
grover.cx(0,1)

# barrier for organization
grover.barrier()

# H on second qubit
grover.h(1)

#barrier
grover.barrier()

# X on first and second qubits
grover.x(0)
grover.x(1)

#barrier
grover.barrier()

# Apply H at the end ***
grover.h(0)
grover.h(1)
grover.h(2)

# barrier
grover.barrier()


# measure all the qubits and put the measurements in their corresponding classical bits 

grover.measure([0,1,2], [0,1,2])

#draw it out 

grover.draw(output='mpl')

