import qiskit as q
from qiskit import IBMQ
%matplotlib inline
IBMQ.save_account("5bd4ecfdc74e6680da7c79998259781431661e5326ae2f88eea95dee8f74b87530ba63fbca8105404de4ffd36e4b484631907acff73c805580928218a5ccf0b3")
# Details in: https://qiskit.org/documentation/install.html 

# https://quantumcomputing.stackexchange.com/questions/7098/loading-qiskit-account-in-the-jupyter-notebook-gives-requestsapierror-error
'''
IBMQ.delete_account()
IBMQ.active_account()
'''

API_KEY = "5bd4ecfdc74e6680da7c79998259781431661e5326ae2f88eea95dee8f74b87530ba63fbca8105404de4ffd36e4b484631907acff73c805580928218a5ccf0b3"
IBMQ.save_account(API_KEY, overwrite=True)

IBMQ.load_account()

circuit = q.QuantumCircuit(2,2) # 2 qubits, 2 classical bits

# Currently: 0,0
circuit.x(0) # Creates quantum bit of 0,1 or any combination of both
#1,0
circuit.cx(0,1) #cnot, controlled not, Flibs 2nd qubit value if first quibit is 1

#1,1
circuit.measure([0,1],[0,1]) # Observer performs measurements between the qubit and classical bit

circuit.draw()

#  pip install pylatexenc
circuit.draw(output = "mpl")

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

for backend in provider.backends():
    try:
        qubit_count = len(backend.properties().quibits)
    except:
        qubit_count = "simulated"
        
    print(f"{backend.name()} has {backend.status().pending_jobs} queued and { qubit_count} qubits")

from qiskit.tools.monitor import job_monitor
backend = provider.get_backend("ibmq_bogota")
job = q.execute(circuit, backend, shots = 500)
job_monitor(job)

from qiskit.visualization import plot_histogram
from matplotlib import style

style.use("dark_background")

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

plot_histogram([counts])

# Currently: 0,0
circuit.h(0) # Creates quantum bit of 0,1 or any combination of both
#1,0
circuit.cx(0,1) #cnot, controlled not, Flibs 2nd qubit value if first quibit is 1

#1,1
circuit.measure([0,1],[0,1]) # Observer performs measurements between the qubit and classical bit

circuit.draw()

job = q.execute(circuit, backend, shots = 500)
job_monitor(job)

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

plot_histogram([counts])