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

ノイズ学習ヘルパー

Package versions

このページのコードは、以下の要件を使用して開発されました。 これらのバージョン以降を使用することを推奨します。

qiskit[all]~=2.3.0
qiskit-ibm-runtime~=0.43.1

エラー緩和技術である PEAPEC はいずれも、Pauli-Lindbladノイズモデルに基づくノイズ学習コンポーネントを使用しています。このコンポーネントは通常、qiskit-ibm-runtime を通じて1つ以上のジョブを送信した後の実行中に管理され、フィッティングされたノイズモデルへのローカルアクセスはありません。しかし、qiskit-ibm-runtime 0.27.1 以降、NoiseLearner クラスと関連する NoiseLearnerOptions クラスが作成され、これらのノイズ学習実験の結果を取得できるようになりました。これらの結果は NoiseLearnerResult としてローカルに保存し、後続の実験の入力として使用することができます。このページでは、その使用方法と利用可能なオプションの概要を説明します。

概要

NoiseLearner クラスは、1つ(または複数の)回路に対して、Pauli-Lindbladノイズモデルに基づいてノイズプロセスを特徴付ける実験を実行します。このクラスには run() メソッドがあり、学習実験を実行します。入力として回路のリストまたは PUB を受け取り、学習済みノイズチャネルと送信されたジョブに関するメタデータを含む NoiseLearnerResult を返します。以下は、ヘルパープログラムの使用方法を示すコードスニペットです。

# Added by doQumentation — required packages for this notebook
!pip install -q qiskit qiskit-ibm-runtime
from qiskit import QuantumCircuit
from qiskit.transpiler import CouplingMap
from qiskit.transpiler import generate_preset_pass_manager

from qiskit_ibm_runtime import QiskitRuntimeService, EstimatorV2
from qiskit_ibm_runtime.noise_learner import NoiseLearner
from qiskit_ibm_runtime.options import (
NoiseLearnerOptions,
ResilienceOptionsV2,
EstimatorOptions,
)

# Build a circuit with two entangling layers
num_qubits = 27
edges = list(CouplingMap.from_line(num_qubits, bidirectional=False))
even_edges = edges[::2]
odd_edges = edges[1::2]

circuit = QuantumCircuit(num_qubits)
for pair in even_edges:
circuit.cx(pair[0], pair[1])
for pair in odd_edges:
circuit.cx(pair[0], pair[1])

# Choose a backend to run on
service = QiskitRuntimeService()
backend = service.least_busy()

# Transpile the circuit for execution
pm = generate_preset_pass_manager(backend=backend, optimization_level=3)
circuit_to_learn = pm.run(circuit)

# Instantiate a NoiseLearner object and execute the noise learning program
learner = NoiseLearner(mode=backend)
job = learner.run([circuit_to_learn])
noise_model = job.result()

結果として得られる NoiseLearnerResult.data は、対象回路に属する個々のエンタングリング層ごとのノイズモデルを含む LayerError オブジェクトのリストです。各 LayerError は、回路と量子ビットラベルのセットという形で層の情報を格納するとともに、該当する層に対して学習されたノイズモデルの PauliLindbladError も格納します。

print(
f"Noise learner result contains {len(noise_model.data)} entries"
f" and has the following type:\n {type(noise_model)}\n"
)
print(
f"Each element of `NoiseLearnerResult` then contains"
f" an object of type:\n {type(noise_model.data[0])}\n"
)
print(
f"And each of these `LayerError` objects possess"
f" data on the generators for the error channel: \n{noise_model.data[0].error.generators}\n"
)
print(f"Along with the error rates: \n{noise_model.data[0].error.rates}\n")
Noise learner result contains 2 entries and has the following type:
<class 'qiskit_ibm_runtime.utils.noise_learner_result.NoiseLearnerResult'>

Each element of `NoiseLearnerResult` then contains an object of type:
<class 'qiskit_ibm_runtime.utils.noise_learner_result.LayerError'>

And each of these `LayerError` objects possess data on the generators for the error channel:
['IIIIIIIIIIIIIIIIIIIIIIIIIIX', 'IIIIIIIIIIIIIIIIIIIIIIIIIIY',
'IIIIIIIIIIIIIIIIIIIIIIIIIIZ', 'IIIIIIIIIIIIIIIIIIIIIIIIIXI',
'IIIIIIIIIIIIIIIIIIIIIIIIIXX', 'IIIIIIIIIIIIIIIIIIIIIIIIIXY',
'IIIIIIIIIIIIIIIIIIIIIIIIIXZ', 'IIIIIIIIIIIIIIIIIIIIIIIIIYI',
'IIIIIIIIIIIIIIIIIIIIIIIIIYX', 'IIIIIIIIIIIIIIIIIIIIIIIIIYY',
'IIIIIIIIIIIIIIIIIIIIIIIIIYZ', 'IIIIIIIIIIIIIIIIIIIIIIIIIZI',
'IIIIIIIIIIIIIIIIIIIIIIIIIZX', 'IIIIIIIIIIIIIIIIIIIIIIIIIZY',
'IIIIIIIIIIIIIIIIIIII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IIIIZYIII',
'IIIIIIIIIIIIIIIIIIIIIIZZIII', 'IIIIIIIIIIIIIIIIIIIIIXIIIII',
'IIIIIIIIIIIIIIIIIIIIIXXIIII', 'IIIIIIIIIIIIIIIIIIIIIXYIIII',
'IIIIIIIIIIIIIIIIIIIIIXZIIII', 'IIIIIIIIIIIIIIIIIIIIIYIIIII',
'IIIIIIIIIIIIIIIIIIIIIYXIIII', 'IIIIIIIIIIIIIIIIIIIIIYYIIII',
'IIIIIIIIIIIIIIIIIIIIIYZIIII', 'IIIIIIIIIIIIIIIIIIIIIZIIIII',
'IIIIIIIIIIIIIIIIIIIIIZXIIII', 'IIIIIIIIIIIIIIIIIIIIIZYIIII',
'IIIIIIIIIIIIIIIIIIIIIZZIIII', 'IIIIIIIIIIIIIIIIIIIIXIIIIII',
'IIIIIIIIIIIIIIIIIIIIYIIIIII', 'IIIIIIIIIIIIIIIIIIIIZIIIIII',
'IIIIIIIIIIIIIIIIIIIXIIIIIII', 'IIIIIIIIIIIIIIIIIIIXXIIIIII',
'IIIIIIIIIIIIIIIIIIIXYIIIIII', 'IIIIIIIIIIIIIIIIIIIXZIIIIII',
'IIIIIIIIIIIIIIIIIIIYIIIIIII', 'IIIIIIIIIIIIIIIIIIIYXIIIIII',
'IIIIIIIIIIIIIIIIIIIYYIIIIII', 'IIIIIIIIIIIIIIIIIIIYZIIIIII', ...]

Along with the error rates:
[8.80e-04 6.50e-04 3.10e-04 5.60e-04 0.00e+00 0.00e+00 0.00e+00 3.00e-04
6.00e-05 1.30e-04 7.00e-05 3.90e-04 0.00e+00 0.00e+00 3.00e-05 3.70e-04
0.00e+00 5.00e-05 7.50e-04 5.50e-04 5.00e-05 0.00e+00 7.60e-04 5.00e-04
5.60e-04 5.60e-04 2.50e-04 5.00e-05 7.00e-05 2.00e-04 1.40e-04 8.00e-05
2.80e-04 0.00e+00 1.70e-04 4.20e-04 3.00e-05 1.00e-05 1.30e-04 4.40e-04
1.00e-04 2.60e-04 7.10e-04 1.10e-04 2.60e-04 1.00e-04 6.80e-04 1.02e-03
4.60e-04 5.30e-04 3.00e-04 0.00e+00 0.00e+00 3.40e-04 0.00e+00 0.00e+00
2.70e-04 0.00e+00 5.00e-05 6.70e-04 0.00e+00 2.20e-04 0.00e+00 4.40e-04
4.30e-04 8.30e-04 1.42e-03 0.00e+00 0.00e+00 1.44e-03 8.70e-04 0.00e+00
0.00e+00 1.05e-03 6.80e-04 5.90e-04 5.10e-04 3.10e-04 5.60e-04 0.00e+00
4.00e-05 0.00e+00 5.50e-04 1.00e-05 2.00e-05 0.00e+00 1.10e-04 0.00e+00
1.20e-04 0.00e+00 2.20e-04 7.00e-05 4.00e-05 3.80e-04 2.80e-04 4.00e-05
7.00e-05 3.00e-04 1.20e-04 6.00e-04 5.80e-04 1.80e-04 5.00e-04 1.20e-04
2.00e-05 2.00e-05 4.80e-04 2.00e-05 0.00e+00 1.40e-04 4.00e-04 3.00e-05
0.00e+00 0.00e+00 4.40e-04 1.10e-04 5.00e-05 6.00e-04 2.30e-04 5.00e-05
1.10e-04 5.30e-04 3.60e-04 6.80e-04 6.70e-04 2.80e-04 4.90e-04 1.30e-04
6.00e-05 7.20e-04 3.00e-05 9.00e-05 1.10e-04 3.30e-04 6.00e-05 1.30e-04
7.60e-04 1.30e-04 1.50e-04 1.30e-04 0.00e+00 3.10e-04 2.50e-04 5.10e-04
0.00e+00 6.00e-05 2.50e-04 2.40e-04 8.00e-05 0.00e+00 0.00e+00 2.70e-04
0.00e+00 8.00e-05 0.00e+00 7.80e-04 7.00e-05 0.00e+00 0.00e+00 2.50e-04
1.70e-04 2.00e-05 4.50e-04 3.10e-04 2.00e-05 1.70e-04 4.60e-04 1.30e-04
3.20e-04 3.50e-04 3.80e-04 2.70e-04 2.00e-04 8.00e-05 1.00e-05 4.10e-04
0.00e+00 0.00e+00 0.00e+00 2.36e-03 0.00e+00 7.00e-05 1.20e-04 9.40e-04
0.00e+00 1.90e-04 1.38e-03 7.50e-04 1.90e-04 0.00e+00 1.14e-03 7.30e-04
5.70e-04 4.20e-04 6.20e-04 0.00e+00 2.20e-04 5.00e-05 1.20e-04 0.00e+00
0.00e+00 1.90e-04 6.00e-05 1.10e-04 2.10e-04 1.50e-04 1.20e-04 2.90e-04
4.60e-04 2.10e-04 4.00e-05 3.00e-05 1.70e-04 3.10e-04 1.00e-04 1.70e-04
3.00e-05 3.90e-04 0.00e+00 6.00e-04 5.60e-04 1.40e-04 3.50e-04 1.00e-04
1.20e-04 9.00e-05 3.20e-04 2.00e-05 1.70e-04 3.00e-05 4.00e-04 1.50e-04
0.00e+00 1.60e-04 1.90e-04 9.00e-05 6.00e-05 4.50e-04 3.10e-04 6.00e-05
9.00e-05 3.70e-04 2.80e-04 6.50e-04 5.30e-04 3.30e-04 8.00e-05 8.00e-05
5.00e-05 2.50e-04 3.50e-04 4.00e-05 0.00e+00 0.00e+00 1.70e-04 1.30e-04
0.00e+00 0.00e+00 7.00e-05 1.70e-04 1.00e-05 4.20e-04 2.00e-04 1.00e-05
1.70e-04 4.80e-04 1.40e-03 4.70e-04 4.00e-04 3.90e-04 4.40e-04 2.00e-04
1.90e-04 7.20e-04 1.80e-04 1.00e-04 0.00e+00 5.70e-04 1.90e-04 2.00e-04
8.70e-04 1.20e-04 1.70e-04 0.00e+00 0.00e+00 3.80e-04 2.40e-04 4.80e-04
6.00e-05 0.00e+00 9.00e-05 6.50e-04 2.00e-05 8.00e-05 1.40e-04 5.80e-04
1.30e-04 0.00e+00 2.00e-05 1.00e-05 1.60e-04 1.00e-05 1.80e-04 4.40e-04
8.00e-05 1.40e-04 4.40e-04 3.90e-04 1.40e-04 8.00e-05 3.90e-04 4.10e-04
8.80e-04 7.30e-04 1.90e-04]

ノイズ学習結果の LayerError.error 属性には、フィッティングされた Pauli Lindblad モデルのジェネレーターとエラーレートが含まれています。このモデルは以下の形式を持ちます。

Λ(ρ)=expjrj(PjρPjρ),\Lambda(\rho) = \exp{\sum_j r_j \left(P_j \rho P_j^\dagger - \rho\right)},

ここで、rjr_jLayerError.ratesPjP_jLayerError.generators に指定された Pauli 演算子です。

ノイズ学習オプション

NoiseLearner オブジェクトをインスタンス化する際に指定できるオプションがいくつかあります。これらのオプションは qiskit_ibm_runtime.options.NoiseLearnerOptions クラスにカプセル化されており、学習する最大層数、ランダム化の回数、twirling 戦略などを指定する機能が含まれています。詳細については、NoiseLearnerOptions の API ドキュメントを参照してください。

以下は、NoiseLearner 実験で NoiseLearnerOptions を使用する簡単な例です。

# Build a GHZ circuit
circuit = QuantumCircuit(10)
circuit.h(0)
circuit.cx(range(0, 9), range(1, 10))
# Choose a backend to run on
service = QiskitRuntimeService()
backend = service.least_busy()

# Transpile the circuit for execution
pm = generate_preset_pass_manager(backend=backend, optimization_level=3)
circuit_to_run = pm.run(circuit_to_learn)

# Instantiate a noise learner options object
learner_options = NoiseLearnerOptions(
max_layers_to_learn=3, num_randomizations=32, twirling_strategy="all"
)

# Instantiate a NoiseLearner object and execute the noise learning program
learner = NoiseLearner(mode=backend, options=learner_options)
job = learner.run([circuit_to_run])
noise_model = job.result()

プリミティブへのノイズモデルの入力

回路で学習したノイズモデルは、Qiskit IBM Runtime に実装されている EstimatorV2 プリミティブへの入力としても使用できます。このノイズモデルは、いくつかの異なる方法でプリミティブに渡すことができます。次の3つの例では、ノイズモデルを estimator.options 属性に直接渡す方法、Estimator プリミティブをインスタンス化する前に ResilienceOptionsV2 オブジェクトを経由して渡す方法、および適切にフォーマットされた辞書を渡す方法を示します。

# pass the noise model to the `estimator.options` attribute directly
estimator = EstimatorV2(mode=backend)
estimator.options.resilience.layer_noise_model = noise_model
# Specify options via a ResilienceOptionsV2 object
resilience_options = ResilienceOptionsV2(layer_noise_model=noise_model)
estimator_options = EstimatorOptions(resilience=resilience_options)
estimator = EstimatorV2(mode=backend, options=estimator_options)
# Specify options via a dictionary
options_dict = {
"resilience_level": 2,
"resilience": {"layer_noise_model": noise_model},
}

estimator = EstimatorV2(mode=backend, options=options_dict)

ノイズモデルが EstimatorV2 オブジェクトに渡されると、通常通りワークロードの実行とエラー緩和の実施に使用できます。

次のステップ

推奨事項