Lumaktaw sa pangunahing nilalaman
Ang proyektong ito ay nasa beta. Nakakita ng bug? Mag-bukas ng GitHub issue. May tanong o ideya? Magtanong sa Discussions — gusto naming marinig ang iyong feedback!
Gaano kaganda ang kalidad ng pagsasalin sa pahinang ito?

Mabilisang simula


title: Quickstart description: Isang quickstart guide para sa Shaded lightcones Qiskit addon (qiskit-addon-slc)​

Ipinapakita ng gabay na ito ang isang minimal na gumaganang halimbawa ng package na qiskit-addon-slc. Kinakalkula nito ang isang shaded lightcone para bawasan ang sampling cost ng probabilistic error cancellation (PEC).

Minimitigate ng PEC ang gate noise sa pamamagitan ng pag-sample mula sa isang quasiprobability decomposition ng inverse noise channel. Lumalaki ang sampling cost nito sa bawat error term na kailangan nitong i-mitigate; gayunpaman, hindi pantay ang epekto ng bawat error sa observable. Ang error na nasa labas ng causal lightcone ng observable ay hindi makakaimpluwensya sa sinukat na expectation value, at kahit sa loob ng lightcone, may mga error na mas nakakasama kaysa sa iba. Kinukwantipika ito ng isang shaded lightcone sa pamamagitan ng pag-bound sa epekto ng bawat Pauli error term sa observable. Ang pag-truncate sa mga error term na may pinakamaliit na epekto ay nagpapaliit sa noise model na kailangang i-mitigate ng PEC, na binabawasan ang sampling cost kapalit ng maliit at may hangganang bias.

Para makita kung paano bumuo ng makatotohanang workflow at tumakbo sa quantum hardware, tingnan ang tutorial na Probabilistic error cancellation with shaded lightcones sa IBM Quantum Platform.

1. Ihanda ang mga input para sa SLC​

Una, bumuo ng 10-qubit na Trotterized transverse-field Ising circuit at pumili ng single-qubit na ZZ observable sa gitnang 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

Gumagana ang SLC sa mga noisy na layer ng two-qubit-gate ng circuit. Dito, ginagamit natin ang samplomatic para i-grupo ang mga gate sa mga annotated na box at maglagay ng noise-injection annotation sa bawat two-qubit layer. Kailangan ng SLC na may natatanging modifier_ref ang bawat noisy box, na ibinibigay ng inject_noise_strategy="individual_modification"; sa default na strategy ng samplomatic, mali ang lalabas na mga bound o hindi natatapos ang pagkalkula nito. Pagkatapos, binibilang ng generate_noise_model_paulis ang mga Pauli error term ng bawat natatanging 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. Kalkulahin ang shaded lightcone​

Binubuo ang shaded lightcone sa pamamagitan ng pagtatalaga ng scale sa bawat Pauli error term sa noise model batay sa kung gaano kalaki ang epekto nito sa expectation value ng observable. Nakukuha ang mga scale na ito mula sa forward at backward na error bound ng bawat error term (inilalarawan sa ibaba), pati na rin sa error rate nito:

  • Ineebolb ng compute_forward_bounds ang bawat error term pasulong hanggang sa dulo ng circuit para i-bound ang epekto nito sa observable na sinusukat doon.

  • Ineebolb ng compute_backward_bounds ang bawat error term paatras hanggang sa simula ng circuit para i-bound ang epekto nito sa initial state.

Pinagsasama ng merge_bounds ang dalawa sa isang bound kada error term. Ang bawat bound ay sinusukat ayon sa error rate ng term. Karaniwang galing ang mga rate na ito sa isang noise learning experiment (gaya ng NoiseLearnerV3); gumagamit ang gabay na ito ng mga random na rate para sa pagiging simple.

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.

Sa visualization ng shaded lightcone sa ibaba, ang bawat box ay may shade ayon sa kung gaano kalakas makaaapekto ang mga error sa site na iyon sa observable. Ang mga maliwanag na box ang may pinakamalalaking bound, habang ang mga box na lumalabo papunta sa background ay may mga error term na kaunti lang ang epekto sa kalkulasyon -- natural na kandidato ang mga error na ito para tanggalin sa noise model. Ang mga halaga sa visualization sa ibaba ay kumakatawan sa mga kabuuan ng error bound ng lahat ng Pauli error sa site na iyon, kaya may ilang halaga na lumalaki nang higit sa 2.0, ang bound para sa anumang iisang 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. Bawasan ang sampling cost​

Ginagawa ng compute_local_scales na konkretong PEC configuration ang shaded lightcone. Inuuna nito ang mga error term ayon sa naka-bound nilang epekto sa observable at tina-truncate ang mga pinakakaunti ang epekto hanggang maabot ang hiniling na bias_tolerance. Nagbabalik ito ng mga scale para sa bawat error term: 0.0 para sa mga term na babalewalain sa mitigation at -1.0 para sa mga term na dapat i-mitigate. Ibinabalik din ng function ang nagresultang overhead ng sampling cost (γ2\gamma^2) at isang bound sa residual bias na dulot ng pag-truncate.

Ang pagtatakda ng bias_tolerance=0.0 ay nagmi-mitigate sa bawat error term sa loob ng causal lightcone ng observable at nagbibigay ng baseline na sampling cost. Kapag pinayagan ang maliit na bias, maaaring tanggalin ng SLC ang mga term na mababa ang epekto at higit pang bawasan ang cost na iyon.

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