Skip to main content
IBM Quantum Platform


title: "빠른 시작" description: "Shaded lightcones Qiskit 애드온(qiskit-addon-slc)을 위한 빠른 시작 가이드"

빠른 시작

이 가이드에서는 해당 qiskit-addon-slc 패키지의 최소 실행 가능한 예제를 보여줍니다. 이 알고리즘은 확률적 오차 상쇄(PEC)의 샘플링 비용을 줄이기 위해 음영 처리된 광뿔을 계산합니다.

PEC는 역잡음 채널의 준확률 분해로부터 샘플링을 수행함으로써 게이트 잡음을 완화합니다. 이 모델의 표본 추출 비용은 완화해야 할 오차 항이 늘어날 때마다 증가하지만, 모든 오차가 관측 가능한 변수에 똑같이 영향을 미치는 것은 아닙니다. 관측 가능한 대상의 인과 광뿔 밖에서 발생하는 오차는 측정된 기대값에 영향을 미칠 수 없으며, 광뿔 내부에서도 어떤 오차는 다른 오차보다 더 큰 악영향을 미칩니다. 음영 처리된 광뿔은 각 파울리 오차 항이 관측량에 미치는 영향을 경계로 설정함으로써 이를 정량화합니다. 영향이 가장 작은 오차 항을 잘라내면 PEC가 완화해야 하는 노이즈 모델의 규모가 줄어들며, 그 대가로 작고 유한한 편향을 감수하는 대신 샘플링 비용이 감소합니다.

현실적인 워크플로를 구축하고 양자 하드웨어에서 실행하는 방법을 알아보려면, IBM Quantum Platform 의 ‘음영 처리된 라이트콘을 이용한 확률적 오류 보정(Probabilistic error cancellation with shaded lightcones) ’ 튜토리얼을 확인해 보세요.


1. SLC에 필요한 입력 자료를 준비합니다

먼저, 10 큐비트 규모의 트로터화(Trotterized) 횡자기장 이징(Ising) 회로를 구축하고, 중간 큐비트에 대한 단일 큐비트 관측량 ZZ 을 선택합니다.

import numpy as np
from qiskit import QuantumCircuit
from qiskit.quantum_info import Pauli


def trotter_ising_circuit(num_qubits, num_steps, rx_angle, rzz_angle):
    """Trotterized transverse-field Ising evolution on a 1D chain."""
    circuit = QuantumCircuit(num_qubits)
    for _ in range(num_steps):
        circuit.rx(rx_angle, range(num_qubits))
        circuit.barrier()
        for start in (0, 1):  # even then odd bonds
            for i in range(start, num_qubits - 1, 2):
                circuit.rzz(rzz_angle, i, i + 1)
        circuit.barrier()
    return circuit


num_qubits = 10
circuit = trotter_ising_circuit(
    num_qubits, num_steps=4, rx_angle=np.pi / 16, rzz_angle=-np.pi / 3
)

# Measure <Z> on the middle qubit
observable = Pauli("I" * num_qubits).compose("Z", [num_qubits // 2])

print(f"Observable: {observable}")
circuit.draw("mpl", fold=-1, scale=0.7)

Output:

Observable: IIIIZIIIII
Output of the previous code cell

SLC는 회로의 잡음이 많은 2-큐비트 게이트 계층에서 작동합니다. 여기서는 를 사용하여 게이트를 주석이 달린 상자로 묶고 samplomatic , 각 2-큐비트 층에 노이즈 주입 주석을 부여합니다. SLC는 모든 노이즈 발생 상자에 고유한 값을 할당하도록 요구하며 modifier_ref, 이는 samplomatic의 기본 전략에서는 경계값이 잘못 산출되거나 계산이 전혀 완료되지 않는 결과를 초래합니다 inject_noise_strategy="individual_modification" . generate_noise_model_paulis 그런 다음, 잡음이 섞인 각 레이어에 대한 파울리 오차 항을 열거합니다.

from qiskit_addon_slc.utils import generate_noise_model_paulis
from samplomatic.transpiler import generate_boxing_pass_manager
from samplomatic.utils import find_unique_box_instructions

# Group gates into boxes and annotate each two-qubit layer with a noise-injection point
boxing_pass = generate_boxing_pass_manager(
    inject_noise_targets="all",
    inject_noise_strategy="individual_modification",  # required: one modifier_ref per box
    inject_noise_site="after",
    twirling_strategy="active",
    remove_barriers="never",
)
boxed_circuit = boxing_pass.run(circuit)

# Enumerate the 1- and 2-weight Pauli error terms of each unique noisy layer
noise_model_paulis = generate_noise_model_paulis(
    find_unique_box_instructions(boxed_circuit)
)

num_terms = sum(len(paulis) for paulis in noise_model_paulis.values())
print(f"Noisy layers: {len(noise_model_paulis)}")
print(f"Pauli error terms across all layers: {num_terms}")

Output:

Noisy layers: 2
Pauli error terms across all layers: 198

2. 음영 처리된 광뿔을 계산한다

음영 처리된 광뿔은 잡음 모델 내의 각 파울리 오차 항이 관측량의 기대값에 미치는 영향의 크기에 따라 각 항에 가중치를 할당함으로써 구성된다. 이러한 척도는 각 오차 항의 전방 및 후방 오차 한계(아래에서 설명함)와 해당 오차율로부터 도출됩니다:

  • compute_forward_bounds 각 오차 항을 회로 끝까지 전진 시켜, 그곳에서 측정되는 관측량에 미치는 영향을 제한한다.
  • compute_backward_bounds 각 오차 항을 회로의 시작 지점까지 역방향으로 전파시켜 초기 상태에 미치는 영향을 제한합니다.

merge_bounds 이 두 가지를 결합하여 오차 항당 하나의 결합으로 만듭니다. 각 바운드는 해당 항의 오차율에 따라 조정됩니다. 이러한 비율은 일반적으로 노이즈 학습 실험(예: NoiseLearnerV3)에서 도출된 것이지만, 이 가이드에서는 설명을 간결하게 하기 위해 임의의 비율을 사용합니다.

from qiskit.quantum_info import PauliLindbladMap, QubitSparsePauliList
from qiskit_addon_slc.bounds import (
    compute_backward_bounds,
    compute_forward_bounds,
    merge_bounds,
)

forward_bounds = compute_forward_bounds(
    boxed_circuit, noise_model_paulis, observable
)
backward_bounds = compute_backward_bounds(boxed_circuit, noise_model_paulis)

# Stand-in for rates that would be measured by a noise-learning experiment on hardware
rng = np.random.default_rng(42)
noise_rates = {
    layer_id: PauliLindbladMap.from_components(
        rng.random(len(paulis)) * 5e-3,
        QubitSparsePauliList.from_sparse_list(
            paulis.to_sparse_list(), paulis.num_qubits
        ),
    )
    for layer_id, paulis in noise_model_paulis.items()
}

merged_bounds = merge_bounds(
    boxed_circuit, forward_bounds, backward_bounds, noise_rates
)

Output:

Optimal spacetime partitioning not implemented!Just partitioning list of noisy boxes.

아래의 음영 처리된 광뿔 시각화에서, 각 상자는 해당 위치의 오차가 관측량에 미칠 수 있는 영향의 크기에 따라 음영이 처리되어 있습니다. 밝은 상자는 가장 큰 오차 범위를 나타내는 반면, 배경으로 희미하게 사라지는 상자에는 계산에 거의 영향을 미치지 않는 오차 항이 포함되어 있습니다. 이러한 오차들은 노이즈 모델에서 제외하기에 가장 적합한 대상입니다. 아래 시각화 자료에 표시된 값들은 해당 위치에서 발생하는 모든 파울리 오류의 오차 범위의 합을 나타내므로 2.0, 일부 값이 단일 파울리 오류에 대한 상한인 보다 커지는 것입니다.

from qiskit_addon_slc.visualization import draw_shaded_lightcone

draw_shaded_lightcone(
    boxed_circuit, merged_bounds, noise_model_paulis, fold=-1, scale=0.5
)

Output:

Output of the previous code cell

3. 표본 추출 비용 절감

compute_local_scales 음영 처리된 광뿔을 구체적인 PEC 구성으로 변환합니다. 이 방법은 관측 변수에 미치는 영향이 제한적인 오차 항을 우선순위에 따라 정렬하고, 요청된 값에 도달할 bias_tolerance 때까지 영향이 가장 적은 항들을 제거합니다. 각 오류 항에 대한 가중치를 반환합니다. 0.0 는 완화 과정에서 무시해야 할 항을, -1.0 는 완화해야 할 항을 나타냅니다. 이 함수는 또한 결과적인 샘플링 비용 오버헤드( γ2\gamma^2 )와 잘림으로 인해 발생하는 잔여 편향의 상한값을 반환합니다.

이 설정을 적용하면 관측량의 인과광뿔 내 모든 오차 항이 완화되며 bias_tolerance=0.0 , 기준 샘플링 비용이 산출됩니다. 약간의 편향을 허용하면 SLC가 영향도가 낮은 항들을 생략하여 비용을 더욱 절감할 수 있습니다.

from qiskit_addon_slc.bounds import compute_local_scales

_, full_cost, full_bias = compute_local_scales(
    boxed_circuit, merged_bounds, noise_rates, bias_tolerance=0.0
)
local_scales, reduced_cost, reduced_bias = compute_local_scales(
    boxed_circuit, merged_bounds, noise_rates, bias_tolerance=0.05
)

print(
    f"Full PEC (bias_tolerance=0.0) : sampling cost {full_cost:6.3f}, residual bias {full_bias:5.3f}"
)
print(
    f"Shaded   (bias_tolerance=0.05): sampling cost {reduced_cost:6.3f}, residual bias {reduced_bias:5.3f}"
)
print(
    f"\nSampling-cost reduction: {(1 - reduced_cost / full_cost):.0%} for <= 0.05 bias"
)

Output:

Full PEC (bias_tolerance=0.0) : sampling cost 21.206, residual bias 0.000
Shaded   (bias_tolerance=0.05): sampling cost  5.403, residual bias 0.049

Sampling-cost reduction: 75% for <= 0.05 bias
이 페이지가 도움이 되었습니까?
GitHub에서 버그, 오타를 보고하거나 컨텐츠를 요청하십시오.