import numpy as np
from qiskit import *
import matplotlib 


qr = QuantumRegister(2)
#measurements from quantum bits = use classical register
cr = ClassicalRegister(2)

circuit = QuantumCircuit(qr, cr)

circuit.draw()

# adding quantum gates to create entanglement (Hadamart gate)
circuit.h(qr[0])


%matplotlib inline

circuit.draw(output='mpl')

#two qubit operation control X (logical if)
circuit.cx(qr[0], qr[1])


circuit.draw(output='mpl') #entanglement achieved 

#measurement, storing measurements into computational register 
circuit.measure(qr,cr)

circuit.draw(output='mpl')

#performance simulations 
simulator = Aer.get_backend('qasm_simulator')

execute(circuit, backend = simulator)

result = execute(circuit, backend = simulator).result()

#plotting results
from qiskit.tools.visualization import plot_histogram
plot_histogram(result.get_counts(circuit))

#running circuit on quantum computer 
IBMQ.load_account()

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

qcomp = provider.get_backend('ibmq_manila')

job= execute(circuit, backend=qcomp)

from qiskit.tools import job_monitor
job_monitor(job)

result = job.result()

from qiskit.tools.visualization import plot_histogram
plot_histogram(result.get_counts(circuit), title='Performance metric on Quantum Computer')

