Japanese
言語
English
Japanese
Spanish

量子バックエンドで実行

**バックエンド**は、シミュレーターまたは実際の量子コンピューターのいずれかを表し、量子回路の実行、パルススケジュールの実行、および結果の返送を担当します。

In qiskit-ibm-runtime, a backend is represented by an instance of the IBMBackend class. Attributes of this class provides information about this backend. For example:

  • name: バックエンドの名前。

  • instructions: バックエンドがサポートする命令のリスト。

  • operation_names: バックエンドがサポートしている命令名のリスト。

  • num_qubits: バックエンドが持つ量子ビット数。

  • coupling_map: バックエンドのカップリングマップ。

  • dt: 入力信号のシステム時間分解能。

  • dtm: 出力信号のシステム時間分解能。

属性およびメソッドのすべてのリストは、 APIリファレンス を参照してください。

サービスの初期化

IBMBackend を呼び出す前にサービスを初期化します:

from qiskit_ibm_runtime import QiskitRuntimeService

# Initialize the account first.
service = QiskitRuntimeService()

バックエンドの一覧

アクセスできるすべてのバックエンドを一覧表示するには backends() メソッドを使用します。このメソッドは IBMBackend インスタンスのリストを返します。

service.backends()
[<IBMBackend('ibmq_qasm_simulator')>,
<IBMBackend('simulator_stabilizer')>,
<IBMBackend('simulator_mps')>,
<IBMBackend('simulator_extended_stabilizer')>,
<IBMBackend('simulator_statevector')>]

The backend() (note that this is singular: backend) method takes the name of the backend as the input parameter and returns an IBMBackend instance representing that particular backend:

service.backend("ibmq_qasm_simulator")
<IBMBackend('ibmq_qasm_simulator')>

バックエンドをフィルターする

オプションで、バックエンドの構成、ステータス、またはプロパティを照会する引数を渡すことにより、セットのバックエンドをフィルタリングすることもできます。 より一般的なフィルターの場合、ラムダ関数を使用して高度な関数を作成できます。 詳細については、APIドキュメントを参照してください。

これらの基準に合うバックエンドのみを取得してみましょう:

  • 実際の量子デバイス ( simulator=False )

  • 現在稼働中 ( operal=True )

  • 少なくとも 5 量子ビットを持つ ( min_num_qubits=5 )

service.backends(simulator=False, operational=True, min_num_qubits=5)

同様の方法は least_busy() です。 これは backends() と同じフィルタを取りますが、フィルタに一致するバックエンドを返し、キューに保留中のジョブの最小数を返します:

service.least_busy(operational=True, min_num_qubits=5)

バックエンド属性の決定

前述のように、IBMBackend クラス属性はバックエンドに関する情報を提供します。例えば:

backend = service.backend("ibmq_qasm_simulator")
backend.name #returns the backend's name
backend.backend_version #returns the version number
backend.simulator #returns True or False, depending on whether it is a simulator
backend.num_qubits #returns the number of qubits the backend has

バックエンド属性のすべてのリストは、 IBMBackend class documentation を参照してください。

他のチャンネルからバックエンド情報を探す

IBM Cloud で利用可能なシステムとシミュレーターを見つけるには、 Compute resources ページ をご覧ください。利用可能なコンピュート・リソースを確認するには、ログインする必要があります。各バックエンドのスナップショットが表示されます。 詳細な情報を見るには、バックエンドの名前をクリックしてください。また、このページからバックエンドを検索することもできます。

IBM Quantum Platform で利用可能なシステムとシミュレーターを見つけるには、 Compute resources ページ をご覧ください。各バックエンドのスナップショットが表示されます。 詳細な情報を見るには、バックエンドの名前をクリックしてください。また、このページではソート、フィルター、検索が可能です。

ジョブ実行時のバックエンドの指定

If you are using a runtime session, add the backend option when starting your session. For details about working with sessions, see Run a primitive in a session.

from qiskit.circuit.random import random_circuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Estimator, Options

circuit = random_circuit(2, 2, seed=1).decompose(reps=1)
observable = SparsePauliOp("IY")

options = Options()
options.optimization_level = 2
options.resilience_level = 2

service = QiskitRuntimeService()
with Session(service=service, backend="ibmq_qasm_simulator") as session:
     estimator = Estimator(session=session, options=options)
     job = estimator.run(circuit, observable)
     result = job.result()
     # Close the session only if all jobs are finished, and you don't need to run more in the session
     session.close() # Closes the session

display(circuit.draw("mpl"))
print(f" > Observable: {observable.paulis}")
print(f" > Expectation value: {result.values[0]}")
print(f" > Metadata: {result.metadata[0]}")

If you are not using a runtime session, you can pass the backend when initializing the primitive class.

from qiskit.circuit.random import random_circuit
from qiskit.quantum_info import SparsePauliOp
from qiskit_ibm_runtime import QiskitRuntimeService, Session, Estimator, Options

circuit = random_circuit(2, 2, seed=1).decompose(reps=1)
observable = SparsePauliOp("IY")

options = Options()
options.optimization_level = 2
options.resilience_level = 2

service = QiskitRuntimeService()
backend = service.backend("ibmq_qasm_simulator")
estimator = Estimator(backend, options=options)
job = estimator.run(circuit, observable)
result = job.result()

display(circuit.draw("mpl"))
print(f" > Observable: {observable.paulis}")
print(f" > Expectation value: {result.values[0]}")
print(f" > Metadata: {result.metadata[0]}")