#importing libraries
from qiskit import QuantumCircuit, QuantumRegister, Aer, execute, IBMQ
from qiskit.visualization import plot_histogram
from qiskit.tools.monitor import job_monitor

provider = IBMQ.load_account()

backend = provider.backends.ibmqx2
real_circ = QuantumCircuit(3, 3)
for i in range(200):
    real_circ.u3(0,0,0,0)
    real_circ.u3(0,0,0,1)
    real_circ.u3(0,0,0,2)
    real_circ.cx(0,1)
    real_circ.cx(1,2)
    real_circ.cx(2,0)
    real_circ.barrier()


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

job_exp = execute(real_circ, backend=backend, shots=8192)
print(job_exp.job_id())

job_monitor(job_exp)
exp_result = job_exp.result()

exp_measurement_result = exp_result.get_counts(real_circ)
print(exp_measurement_result)
plot_histogram(exp_measurement_result, color='midnightblue', title="NQRNG result on IBM Yorktown backend")

backend = provider.backends.ibmqx2
hada= QuantumCircuit(3, 3)

hada.h(0)
hada.h(1)
hada.h(2)

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

job_exp = execute(hada, backend=backend, shots=8192)
print(job_exp.job_id())
from qiskit.tools.monitor import job_monitor
job_monitor(job_exp)
exp_result = job_exp.result()
exp_measurement_result_hada = exp_result.get_counts(hada)
print(exp_measurement_result_hada)
plot_histogram(exp_measurement_result_hada, color='midnightblue', title="QRNS result on IBM Yorktown backend")

plot_histogram(exp_measurement_result_hada, color='midnightblue', title="QRNG result on IBM Yorktown backend")

plot_histogram(exp_measurement_result, color='midnightblue', title="NQRNG result on IBM Yorktown backend")

hada.draw('mpl')

backend = provider.backends.ibmqx2
real_circ = QuantumCircuit(3, 3)

real_circ.u3(0,0,0,0)
real_circ.u3(0,0,0,1)
real_circ.u3(0,0,0,2)
real_circ.cx(0,1)
real_circ.cx(1,2)
real_circ.cx(2,0)



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

job_exp = execute(real_circ, backend=backend, shots=8192)
print(job_exp.job_id())

job_monitor(job_exp)
exp_result = job_exp.result()

exp_measurement_result = exp_result.get_counts(real_circ)
print(exp_measurement_result)
plot_histogram(exp_measurement_result, color='midnightblue', title="Basic circuit on IBM Yorktown backend")

real_circ.draw('mpl')

