#%pip install qiskit-aqua qiskit

from qiskit.visualization import iplot_histogram, plot_histogram
%pylab inline
import qiskit as qk

qr = qk.QuantumRegister(2)
cr = qk.ClassicalRegister(2)
qc = qk.QuantumCircuit(qr,cr)

qc.h(qr[0])

qc.draw(output='mpl')

qc.cx(qr[0], qr[1])

qc.draw(output='mpl')

qc.measure(qr,cr)

qc.draw(output='mpl')

qk.Aer.backends()

sim = qk.Aer.get_backend('qasm_simulator')

res = qk.execute(qc, sim).result()

res

plot_histogram(res.get_counts())

from qiskit import IBMQ
IBMQ.delete_account()
IBMQ.save_account('4fd56...',
                  overwrite=True) # the token you obtained above
IBMQ.load_account()

provider = IBMQ.get_provider()
procs=provider.backends(operational=True, simulator=False)
procs

from qiskit.tools.jupyter import *
%qiskit_backend_overview

from qiskit.tools import monitor
backend = qk.providers.ibmq.least_busy([p for p in procs if len(p.properties().qubits) >= 2])

from qiskit.tools.monitor import backend_overview, backend_monitor
backend_monitor(backend)

#%%qiskit_job_status
#%%qiskit_progress_bar
%time job = qk.execute(qc, backend=backend, shots=2**10)
#mon = monitor.job_monitor(job)


%time res2 = job.result()

plot_histogram(res2.get_counts(qc))

res2.get_counts(qc)

