from qiskit import QuantumCircuit, Aer,execute, IBMQ
from qiskit.visualization import plot_histogram


## Sample Program: Bell Circuit

qc=QuantumCircuit(2,2) # 2 qubits and 2 classical bits
qc.h(0)
qc.cx(0,1)
qc.draw(output="mpl")

qc.measure([0,1],[0,1])
qc.draw(output="mpl")

backend=Aer.get_backend('qasm_simulator')

job=execute(qc,backend,shots=1024)

result=job.result()

counts=result.get_counts()

print(counts)

plot_histogram(counts,title="Bell State without noise")

#Load the  account
provider=IBMQ.load_account() 

#List all the available backends for the account
#provider.backends()

#Get the backend
backend=provider.get_backend('ibmq_bogota')

#Execute the circuit on the backend

job=execute(qc,backend,shots=1024)

#job.cancel()

job.status()

from qiskit.tools import job_monitor

job_monitor(job)

job.status()

result=job.result()

counts=result.get_counts()

print(counts)

plot_histogram(counts,title="Bell State with noise")

job.job_id()

from qiskit.compiler import transpile

backend=provider.get_backend('ibmq_qasm_simulator')

transpile_circuit=transpile(qc,backend)

transpile_circuit.draw(output="mpl")


from qiskit.compiler import transpile,assemble

backend=provider.get_backend('ibmq_bogota')

transpile_circuit=transpile(qc,backend)

transpile_circuit.draw(output="mpl")

backend.configuration().basis_gates

backend=provider.get_backend('ibmq_bogota')

transpile_circuit=transpile(qc,backend)

job=backend.run(transpile_circuit)

job.status()

job_monitor(job)

result=job.result()
counts=result.get_counts()
print(counts)

plot_histogram(counts)