-
Notifications
You must be signed in to change notification settings - Fork 2
/
hello.py
30 lines (25 loc) · 984 Bytes
/
hello.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import qiskit
from qiskit import ClassicalRegister, QuantumRegister, QuantumCircuit
from qiskit import IBMQ
from configparser import RawConfigParser
# Setup the API key for the real quantum computer.
parser = RawConfigParser()
parser.read('config.ini')
IBMQ.enable_account(parser.get('IBM', 'key'))
# Setup a qubit.
qr = QuantumRegister(1)
cr = ClassicalRegister(1)
program = QuantumCircuit(qr, cr);
# Measure the value of the qubit.
program.measure(qr, cr);
# Execute the program in the simulator.
print("Running on the simulator.")
job = qiskit.execute(program, qiskit.Aer.get_backend('qasm_simulator'), shots=100)
counts = job.result().get_counts()
print('Hello World! ' + str(counts))
# Execute the program on a real quantum computer.
backend = qiskit.providers.ibmq.least_busy(qiskit.IBMQ.backends(simulator=False))
print("Running on", backend.name())
job = qiskit.execute(program, backend, shots=100)
counts = job.result().get_counts()
print('Hello World! ' + str(counts))