メインコンテンツへスキップ

オプションの概要

ニーズに合わせて Qiskit Runtime プリミティブをカスタマイズするためにオプションを使用できます。

構造

プリミティブを呼び出す際、オプションクラスまたは辞書を使用してオプションを渡すことができます。resilience_level などの一般的によく使われるオプションは第一レベルにあります。その他のオプションは execution などのカテゴリにグループ化されています。オプションは options.option.sub-option.sub-sub-option = choice という形式で指定してください。例: options.dynamical_decoupling.enable = True

デフォルト値

オプションの値を指定しない場合、Unset という特殊な値が与えられ、サーバーのデフォルト値が使用されます。そのため、デフォルト値はコードのバージョンに関わらず同じになります。

デフォルト値は、各プリミティブの「オプション」ガイドの「オプションクラスのまとめ」セクションの表に記載されています。

オプションの設定

オプションはプリミティブの構築前に定義し、オプションクラスのインスタンスまたは辞書としてプリミティブに渡すことができます。プリミティブはそのコピーを作成します。つまり、元の辞書またはオプションインスタンスを変更しても、プリミティブが保持するオプションには影響しません。

さらに、プリミティブの構築後にオプションを変更することも可能です。アプリケーションに最も適したワークフローをご使用ください。

プリミティブオプションの指定に関する注意事項
  • プリミティブの初期化中または初期化後に利用可能なオプションを確認できます。
  • オプションの値を指定しない場合、Unset という特殊な値が与えられ、サーバーのデフォルト値が使用されます。
  • options 属性は Python の dataclass 型です。組み込みの asdict メソッドを使用して辞書に変換できます。

options クラス

プリミティブクラスのインスタンスを作成する際に、options クラスのインスタンスを渡すことができます。その後、run() を使用して計算を実行するときにそれらのオプションが適用されます。オプションは options.option.sub-option.sub-sub-option = choice という形式で指定してください。例: options.dynamical_decoupling.enable = True

詳細については SamplerOptions または EstimatorOptions を参照してください。

以下の例では Estimator プリミティブを使用していますが、他のプリミティブでも構文は同様です。

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator
from qiskit_ibm_runtime.options import EstimatorOptions

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

options = EstimatorOptions(
resilience_level=2,
resilience={"zne_mitigation": True, "zne": {"noise_factors": [1, 3, 5]}},
)

# or...
options = EstimatorOptions()
options.resilience_level = 2
options.resilience.zne_mitigation = True
options.resilience.zne.noise_factors = [1, 3, 5]

estimator = Estimator(mode=backend, options=options)

辞書

プリミティブを初期化する際に辞書としてオプションを指定できます。

以下の例では Estimator プリミティブを使用していますが、他のプリミティブでも構文は同様です。

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

# Setting options during initialization
estimator = Estimator(
backend,
options={
"resilience_level": 2,
"resilience": {
"zne_mitigation": True,
"zne": {"noise_factors": [1, 3, 5]},
},
},
)

初期化後のオプションの更新

オートコンプリートを活用するには _primitive_.options.option.sub-option.sub-sub-option = choice という形式でオプションを指定するか、update() メソッドを使用して一括更新してください。

プリミティブを初期化した後にオプションを設定する場合、プリミティブのオプションクラス(EstimatorOptions または SamplerOptions)をインスタンス化する必要はありません。

以下の例では Estimator プリミティブを使用していますが、他のプリミティブでも構文は同様です。

from qiskit_ibm_runtime import QiskitRuntimeService
from qiskit_ibm_runtime import EstimatorV2 as Estimator

service = QiskitRuntimeService()
backend = service.least_busy(operational=True, simulator=False)

estimator = Estimator(mode=backend)

# Setting options after initialization
# This uses auto-complete.
estimator.options.default_precision = 0.01
# This does bulk update.
estimator.options.update(
default_precision=0.02, resilience={"zne_mitigation": True}
)

次のステップ

おすすめ