Hello World
Quantum Qiskit Hello World
In [1]:
from qiskit import *
In [2]:
qr = QuantumRegister(2)
In [3]:
cr = ClassicalRegister(2)
In [4]:
circuit = QuantumCircuit(qr, cr)
In [5]:
%matplotlib inline
In [6]:
circuit.draw()
Out[6]:
In [7]:
circuit.h(qr[0])
Out[7]:
In [8]:
circuit.draw(output='mpl')
Out[8]:
In [9]:
circuit.cx(qr[0],qr[1])
Out[9]:
In [10]:
circuit.draw(output ='mpl')
Out[10]:
In [11]:
circuit.measure(qr, cr)
Out[11]:
In [12]:
circuit.draw(output = 'mpl')
Out[12]:
In [13]:
simulator = Aer.get_backend('qasm_simulator')
In [14]:
result = execute(circuit, backend = simulator).result()
In [15]:
from qiskit.tools.visualization import plot_histogram
In [16]:
plot_histogram(result.get_counts(circuit))
Out[16]:
In [17]:
IBMQ.load_account()
Out[17]:
In [18]:
provider = IBMQ.get_provider('ibm-q')
In [19]:
qcomp = provider.get_backend('ibmq_16_melbourne')
In [20]:
job = execute(circuit, backend=qcomp)
In [21]:
from qiskit.tools.monitor import job_monitor
In [22]:
job_monitor(job)
In [26]:
result = job.result()
In [27]:
plot_histogram(result.get_counts(circuit))
Out[27]: