ข้ามไปยังเนื้อหาหลัก
โครงการนี้อยู่ในช่วงเบต้า พบข้อผิดพลาด? สร้าง GitHub Issue มีคำถามหรือไอเดีย? ถามใน Discussions — ยินดีรับฟังความคิดเห็น!
คุณภาพการแปลในหน้านี้เป็นอย่างไร?

เริ่มต้นอย่างรวดเร็ว


title: Quickstart description: คู่มือ quickstart สำหรับ Qiskit addon Shaded lightcones (qiskit-addon-slc)​

คู่มือนี้แสดงตัวอย่างที่ใช้งานได้แบบเรียบง่ายของแพ็กเกจ qiskit-addon-slc โดยคำนวณ shaded lightcone เพื่อลดต้นทุนการสุ่มของ probabilistic error cancellation (PEC)

PEC ลดสัญญาณรบกวนของ gate โดยสุ่มจาก quasiprobability decomposition ของ noise channel ผกผัน ต้นทุนการสุ่มจะเพิ่มขึ้นตามทุก error term ที่ต้องลด อย่างไรก็ตาม ข้อผิดพลาดไม่ได้ส่งผลต่อ observable เท่ากันทั้งหมด ข้อผิดพลาดที่อยู่นอก causal lightcone ของ observable ไม่สามารถส่งผลต่อ expectation value ที่วัดได้ และแม้อยู่ภายใน lightcone ข้อผิดพลาดบางตัวก็เสียหายกว่าตัวอื่น shaded lightcone หาปริมาณนี้โดยกำหนดขอบเขตผลที่ Pauli error term แต่ละตัวมีต่อ observable การตัด error term ที่มีผลน้อยที่สุดออกจะทำให้ noise model ที่ PEC ต้องลดเล็กลง ลดต้นทุนการสุ่มโดยแลกกับ bias เล็กน้อยที่มีขอบเขต

หากต้องการดูวิธีสร้าง workflow ที่สมจริงและรันบนฮาร์ดแวร์ควอนตัม ดูบทเรียน Probabilistic error cancellation with shaded lightcones บน IBM Quantum Platform

1. เตรียมอินพุตสำหรับ SLC​

ขั้นแรก สร้าง circuit transverse-field Ising แบบ Trotterized ขนาด 10 qubit และเลือก observable ZZ แบบ single-qubit บน qubit ตรงกลาง

# Added by doQumentation — installs the packages this notebook needs if they are missing
import importlib.util

_needed = {"numpy": "numpy", "qiskit": "qiskit", "qiskit_addon_slc": "qiskit-addon-slc", "samplomatic": "samplomatic"}
_missing = [pip for module, pip in _needed.items()
if importlib.util.find_spec(module) is None]
# One at a time, so a package that fails to install does not block the others
for _pip in _missing:
%pip install -q {_pip}
if not _missing:
print("\u2713 All required packages are installed")
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)
Observable: IIIIZIIIII

Output of the previous code cell

SLC ทำงานกับ layer ของ two-qubit gate ที่มีสัญญาณรบกวนของ circuit ที่นี่เราใช้ samplomatic จัดกลุ่ม gate เป็นกล่องที่มี annotation และแนบ annotation สำหรับการฉีดสัญญาณรบกวนให้กับแต่ละ two-qubit layer SLC ต้องการให้ทุก noisy box มี modifier_ref ที่ไม่ซ้ำกัน ซึ่ง inject_noise_strategy="individual_modification" จัดให้ แต่ถ้าใช้กลยุทธ์ค่าเริ่มต้นของ samplomatic ค่าขอบเขตจะผิดหรือการคำนวณไม่มีวันเสร็จ จากนั้น generate_noise_model_paulis จะไล่ list Pauli error term ของทุก noisy layer ที่ไม่ซ้ำกัน

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}")
Noisy layers: 2
Pauli error terms across all layers: 198

2. คำนวณ shaded lightcone​

shaded lightcone ถูกประกอบขึ้นโดยกำหนดสเกลให้ Pauli error term แต่ละตัวใน noise model ตามว่ามันมีผลต่อ expectation value ของ observable มากเพียงใด สเกลเหล่านี้ได้มาจากขอบเขตข้อผิดพลาดแบบ forward และ backward ของแต่ละ error term (อธิบายด้านล่าง) รวมถึงอัตราข้อผิดพลาดของมัน:

  • compute_forward_bounds วิวัฒน์ error term แต่ละตัวไปข้างหน้าจนถึงท้าย circuit เพื่อกำหนดขอบเขตผลที่มีต่อ observable ที่วัดตรงนั้น

  • compute_backward_bounds วิวัฒน์ error term แต่ละตัวย้อนกลับไปยังจุดเริ่มต้นของ circuit เพื่อกำหนดขอบเขตผลที่มีต่อสถานะเริ่มต้น

merge_bounds รวมทั้งสองเข้าด้วยกันเป็นขอบเขตเดียวต่อ error term โดยแต่ละขอบเขตถูกปรับสเกลด้วยอัตราข้อผิดพลาดของเทอมนั้น อัตราเหล่านี้มักมาจากการทดลอง noise learning (เช่น 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
)
Optimal spacetime partitioning not implemented!Just partitioning list of noisy boxes.

ในภาพแสดงผล shaded lightcone ด้านล่าง แต่ละกล่องถูกแรเงาตามความแรงที่ข้อผิดพลาด ณ ตำแหน่งนั้นส่งผลต่อ observable ได้ กล่องที่สว่างมีค่าขอบเขตมากที่สุด ส่วนกล่องที่จางหายไปกับพื้นหลังมี error term ที่มีผลต่อการคำนวณน้อยมาก -- ข้อผิดพลาดเหล่านี้เป็นตัวเลือกตามธรรมชาติที่จะตัดออกจาก noise model ค่าในภาพด้านล่างเป็นผลรวมของขอบเขตข้อผิดพลาดของ Pauli error ทั้งหมด ณ ตำแหน่งนั้น ซึ่งเป็นเหตุให้บางค่าโตเกิน 2.0 ซึ่งเป็นขอบเขตของ Pauli error เดี่ยวใด ๆ

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 of the previous code cell

3. ลดต้นทุนการสุ่มตัวอย่าง​

compute_local_scales เปลี่ยน shaded lightcone ให้เป็นการตั้งค่า PEC ที่ใช้งานได้จริง โดยจัดลำดับความสำคัญของ error term ตามผลที่มีขอบเขตต่อ observable และตัดตัวที่มีผลน้อยที่สุดออกจนถึง bias_tolerance ที่ต้องการ ฟังก์ชันคืนค่าสเกลของแต่ละ error term: 0.0 สำหรับเทอมที่ละเว้นระหว่างการลดข้อผิดพลาด และ -1.0 สำหรับเทอมที่ควรลด นอกจากนี้ยังคืน overhead ของ sampling cost (γ2\gamma^2) และขอบเขตของ residual bias ที่เกิดจากการตัดทอน

การตั้ง bias_tolerance=0.0 จะลดทุก error term ภายใน causal lightcone ของ observable และให้ sampling cost พื้นฐาน การยอมให้มี bias เล็กน้อยทำให้ 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"
)
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