from qiskit import IBMQ, Aer
from qiskit.providers.ibmq import least_busy
from qiskit import QuantumCircuit, transpile, assemble
from qiskit.tools.monitor import job_monitor
import matplotlib as mpl
# import basic plot tools
from qiskit.visualization import plot_histogram, plot_bloch_multivector
import numpy as np
from numpy import pi

qft_circuit = QuantumCircuit(3)
qft_circuit.clear()


#input state= 5
qft_circuit.x(0)
qft_circuit.x(2)


qft_circuit.h(0)
qft_circuit.cp(pi/2,0,1)
qft_circuit.cp(pi/4,0,2)
qft_circuit.h(1)
qft_circuit.cp(pi/2,1,2)
qft_circuit.h(2)
#qft_circuit.swap(0,2)
qft_circuit.draw('mpl')

#output is the bloch sphere representation in the fourier basis
sim = Aer.get_backend("aer_simulator")
qft_circuit_init = qft_circuit.copy()
qft_circuit_init.save_statevector()
statevector = sim.run(qft_circuit_init).result().get_statevector()
plot_bloch_multivector(statevector)

IBMQ.save_account('')

IBMQ.load_account()
provider = IBMQ.get_provider(hub='ibm-q')

backend = least_busy(provider.backends(filters=lambda b: b.configuration().n_qubits >= 2 and not b.configuration().simulator and b.status().operational==True))
print(backend)
t_qc = transpile(qft_circuit, backend, optimization_level=3)#transpile=assembling the circuit and everything
job = backend.run(t_qc)#backend means device
job_monitor(job)

