In [1]:
## "MY_API_TOKEN" に、上で取得したtokenを入れる
from qiskit_ibm_provider import IBMProvider
provider = IBMProvider()

backend = provider.get_backend('ibmq_qasm_simulator')
In [2]:
# 自分のアカウントで使用できるバックエンドを見る
provider.backends()
Out[2]:
[<IBMBackend('simulator_extended_stabilizer')>,
 <IBMBackend('simulator_mps')>,
 <IBMBackend('simulator_statevector')>,
 <IBMBackend('simulator_stabilizer')>,
 <IBMBackend('ibm_brisbane')>,
 <IBMBackend('ibm_kyoto')>,
 <IBMBackend('ibm_osaka')>,
 <IBMBackend('ibmq_qasm_simulator')>]
In [3]:
from qiskit_ibm_provider import least_busy

backend_lb = least_busy(provider.backends(simulator=False, operational=True))
print("Least busy backend: ", backend_lb)
Least busy backend:  <IBMBackend('ibm_kyoto')>
In [5]:
backend_ex = provider.get_backend('ibm_kyoto')
In [7]:
# まずは必要になるpythonモジュールをすべてインポートしておく
import numpy as np
import matplotlib.pyplot as plt
from qiskit import Aer, execute
from qiskit import QuantumCircuit, ClassicalRegister, QuantumRegister, IBMQ, execute
from qiskit.tools.monitor import job_monitor
from qiskit.visualization import plot_histogram
In [8]:
theta1 = 2. * np.arctan(np.sqrt(5./3))
theta2 = 2. * np.arctan(np.sqrt(5.))
theta3 = 2. * np.arctan(np.sqrt(3. / 7))
In [9]:
import qiskit
qc = QuantumCircuit(2)
qc.ry(theta1, 1)
qc.ry(theta2, 0)
qc.barrier()
qc.cry(theta3 - theta2, 1, 0) # C[Ry] 1が制御で0が標的
Out[9]:
<qiskit.circuit.instructionset.InstructionSet at 0x7fbb4ac2f430>
In [10]:
qc = qiskit.compiler.transpile(qc)
qc.measure_all()
In [11]:
print('This circuit has', qc.num_qubits, 'qubits and', qc.size(), 'operations')
qc.draw(output='mpl')
This circuit has 2 qubits and 5 operations
Out[11]:
In [12]:
#localのシミュレータとleast busyなbackend
backend_sim = Aer.get_backend("qasm_simulator")
In [13]:
#量子回路qcを指定したバックエンドシミュレータ(backend_sim)で4096回実行する。
result = execute(qc, backend_sim, shots=4096).result()
In [14]:
#結果を出力する。
print(result.get_counts(qc))
{'01': 1317, '11': 754, '00': 244, '10': 1781}
In [15]:
#結果をグラフ出力する。
plot_histogram(result.get_counts(qc))
Out[15]:
In [18]:
#量子回路qcを指定したバックエンド(backend_lb)で4096回実行する。
result_ex = execute(qc, backend=backend_ex, shots=4096).result()
In [19]:
#結果を出力する。
print(result_ex.get_counts(qc))
{'01': 1231, '11': 1023, '00': 375, '10': 1467}
In [20]:
#結果をグラフ出力する。
plot_histogram(result_ex.get_counts(qc))
Out[20]:
In [ ]: