from IPython.display import IFrame
IFrame(src="http://www.youtube.com/embed/RrUTwq5jKM4", width=1920/2, height=1080/2)

from qiskit import *

qr = QuantumRegister(2)
cr = ClassicalRegister(2)

circuit = QuantumCircuit(qr, cr)

circuit = QuantumCircuit(2,2)

circuit.draw()

%matplotlib inline 
circuit.draw(output='mpl')

# the quantum circuit has two qubits. they are indexed as qubits 0 and 1
circuit.h(0)
circuit.cx(0,1) # order is control, target
circuit.measure([0,1], [0,1]) # qubits [0,1] are measured and results are stored in classical bits [0,1] in order
circuit.draw(output='mpl')

simulator = Aer.get_backend('qasm_simulator')

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

from qiskit.visualization import plot_histogram

plot_histogram(result.get_counts(circuit))

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

qcomp = provider.get_backend('ibmq_16_melbourne')

num_qubits = 2

from qiskit.providers.ibmq import least_busy
possible_devices = provider.backends(filters=lambda x: 
                                     x.configuration().n_qubits >= num_qubits
                                       and 
                                     x.configuration().simulator == False)
qcomp = least_busy(possible_devices)
print(qcomp)

import qiskit.tools.jupyter
%qiskit_job_watcher

job = execute(circuit, backend=qcomp)

from qiskit.tools.monitor import job_monitor
job_monitor(job)

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

%qiskit_disable_job_watcher

qiskit.__qiskit_version__

%qiskit_copyright