Spaces:
Sleeping
Sleeping
File size: 833 Bytes
4c17cfe | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | from __future__ import annotations
from typing import Dict, List
def baseline_decoder(syndrome: List[int], n_qubits: int) -> Dict[int, str]:
"""
Simple deterministic decoder used for /baseline.
It maps active syndrome bits to nearby qubit indices and applies alternating
X/Z corrections, which creates a stable non-adaptive reference policy.
"""
corrections: Dict[int, str] = {}
if not syndrome:
return corrections
for idx, bit in enumerate(syndrome):
if bit != 1:
continue
q = idx % max(1, n_qubits)
corrections[q] = "X" if (idx % 2 == 0) else "Z"
# Cap correction count to keep action bounded and low latency.
if len(corrections) > 12:
items = list(corrections.items())[:12]
corrections = dict(items)
return corrections
|