qalgora-QX · Quantum Error Correction
The QEC library provides encoders, syndrome measurement, and decoders for stabilizer codes — the building blocks of fault-tolerant quantum computing.
qalgora-qec is not yet published and cannot be installed today; the APIs below are planned interfaces.Installation
# python3 -m pip install qalgora-qec # planned — not yet installable
A repetition-code memory experiment
The snippet below is a planned/specification interface — it sketches the intended encode → noise → syndrome → decode flow rather than a runnable reference build.
import qalgora_qec as qec
# 3-qubit bit-flip repetition code (planned / spec interface)
code = qec.get_code("repetition", distance=3)
# encode -> noise -> syndrome-extraction
noise = qec.NoiseModel.bit_flip(p=0.01)
state = code.encode_logical_zero()
syndromes = code.measure_syndromes(state, rounds=5, noise_model=noise)
decoder = qec.get_decoder("lookup", code)
corrections = decoder.decode(syndromes)
ler = code.logical_error_rate(syndromes=syndromes, corrections=corrections)
print("logical error rate:", ler)Codes & decoders
| Code | Notes |
|---|---|
"repetition" | Bit-flip-only, the simplest distance-d memory |
"steane" | [[7,1,3]] CSS code, corrects any single error |
"surface" | 2D topological code, distance-configurable |
| Decoder | Method | Best for | Status |
|---|---|---|---|
"lookup" | syndrome → correction lookup table for small codes or low-weight errors | small codes, fastest | planned interface |
"matching" | minimum-weight perfect matching (MWPM) | surface / matchable codes | planned interface |
"bposd" | belief propagation + ordered-statistics decoding | general qLDPC codes | planned interface |
"qldpc-gpu" | GPU-accelerated BP + OSD, batched over shots | large qLDPC at scale | planned interface |
"tensor-network" | contracts the error tensor network for near-ML accuracy | highest accuracy, small/medium codes | planned interface |
"sliding-window" | decodes a streaming window of rounds for low latency | real-time / continuous syndrome streams | planned interface |
Real-time decoding
For a fault-tolerant control loop the decoder runs while syndromes arrive. Feed rounds in as they are measured and pull corrections back without waiting for the full experiment, then reset between logical operations.
decoder = qec.get_decoder("sliding-window", code, window=3)
for round_syndromes in syndrome_stream: # arriving each QEC cycle
decoder.enqueue_syndromes(round_syndromes)
correction = decoder.get_corrections() # latest frame correction
apply_feedback(correction)
decoder.reset_decoder() # clear state for the next logical block
Decoding from a detector error model
Decoders consume a Detector Error Model — the graph of how noise flips detectors — which you can extract straight from a noisy syndrome circuit.
dem = qalgora.dem_from_kernel(code.syndrome_circuit, noise_model=noise)
decoder = qec.get_decoder("matching", dem)
logical_errors = decoder.decode_batch(detector_samples)Tools
- Parity-check matrices, Tanner graphs, and stabilizer generators.
- Threshold estimation by sweeping physical error rate across code distances.
- Logical error-rate analysis to confirm the below-threshold regime.
qalgora-QX · 量子纠错
QEC 库提供稳定子码所需的编码器、校验子测量与解码器——这些是构建容错量子计算的基础模块。
qalgora-qec 尚未发布,当前不可安装;以下 API 为规划接口。安装
# python3 -m pip install qalgora-qec # 规划中,暂不可安装
重复码存储实验
下面这段属于规划/规范接口,仅勾勒「编码 → 噪声 → 校验子 → 解码」的预期流程,并非可运行的参考实现。
import qalgora_qec as qec
# 3 比特比特翻转重复码(规划/规范接口)
code = qec.get_code("repetition", distance=3)
# 编码 -> 噪声 -> 校验子提取
noise = qec.NoiseModel.bit_flip(p=0.01)
state = code.encode_logical_zero()
syndromes = code.measure_syndromes(state, rounds=5, noise_model=noise)
decoder = qec.get_decoder("lookup", code)
corrections = decoder.decode(syndromes)
ler = code.logical_error_rate(syndromes=syndromes, corrections=corrections)
print("logical error rate:", ler)纠错码与解码器
| 纠错码 | 说明 |
|---|---|
"repetition" | 仅处理比特翻转,码距为 d 的最简存储码 |
"steane" | [[7,1,3]] CSS 码,可纠正任意单量子比特错误 |
"surface" | 二维拓扑码,码距可配置 |
| 解码器 | 方法 | 适用 | 状态 |
|---|---|---|---|
"lookup" | 小码或低权重错误的校验子到纠正查找表 | 小码 最快 | 规划接口 |
"matching" | 最小权完美匹配 MWPM | 表面码 / 可匹配码 | 规划接口 |
"bposd" | 置信传播 + 有序统计解码 | 通用 qLDPC 码 | 规划接口 |
"qldpc-gpu" | GPU 加速的 BP + OSD 跨 shot 批处理 | 大规模 qLDPC | 规划接口 |
"tensor-network" | 收缩误差张量网络 逼近最大似然精度 | 最高精度 中小码 | 规划接口 |
"sliding-window" | 对滚动的若干轮窗口解码 低延迟 | 实时 / 连续校验子流 | 规划接口 |
实时解码
在容错控制回路里,解码器在校验子到达的同时就开始运行:各轮一边测量一边喂进来,不必等整个实验结束就能取回纠正,随后在逻辑操作之间复位。
decoder = qec.get_decoder("sliding-window", code, window=3)
for round_syndromes in syndrome_stream: # 每个 QEC 周期到达
decoder.enqueue_syndromes(round_syndromes)
correction = decoder.get_corrections() # 最新帧的纠正
apply_feedback(correction)
decoder.reset_decoder() # 为下一个逻辑块清空状态
从探测器错误模型解码
解码器以探测器错误模型为输入——该图描述了噪声如何翻转探测器——可直接从含噪校验子线路中提取。
dem = qalgora.dem_from_kernel(code.syndrome_circuit, noise_model=noise)
decoder = qec.get_decoder("matching", dem)
logical_errors = decoder.decode_batch(detector_samples)工具
- 校验矩阵、Tanner 图与稳定子生成元。
- 通过扫描不同码距下的物理错误率来估算阈值。
- 逻辑错误率分析,用于确认系统处于低于阈值的工作区间。