sci-run / tasks /surface-code-decoding /surface-code-decoding-astra-xhigh-1h100-48h-20261020b /submissions /S040 /r3_pattern_model.py
Download tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/submissions/S040/r3_pattern_model.py from s42chen/sci-run: direct link, hf CLI and curl.
- Browser
- Download file 932 Bytes
-
https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/submissions/S040/r3_pattern_model.py
- Command line
-
hf download hf://datasets/s42chen/sci-run/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/submissions/S040/r3_pattern_model.py
-
curl -L -o r3_pattern_model.py https://huggingface.co/datasets/s42chen/sci-run/resolve/main/tasks/surface-code-decoding/surface-code-decoding-astra-xhigh-1h100-48h-20261020b/submissions/S040/r3_pattern_model.py
932 Bytes
| """Categorical logical probabilities keyed only by 24 hard detection events.""" | |
| import numpy as np | |
| from scipy.special import expit | |
| def codes(packed): | |
| assert packed.dtype == np.uint8 and packed.ndim == 2 and packed.shape[1] == 3 | |
| return np.sum(packed.astype(np.uint32) * np.array([1, 256, 65536], np.uint32), | |
| axis=1, dtype=np.uint32) | |
| def predict(packed, state, fallback, mode='raw'): | |
| assert mode in ['raw', 'equal'] | |
| key = codes(packed) | |
| known = state['codes'] | |
| at = np.searchsorted(known, key) | |
| safe = np.minimum(at, len(known)-1) | |
| seen = (at < len(known)) & (known[safe] == key) | |
| p = np.asarray(fallback, dtype=np.float32).copy() | |
| assert p.shape == (len(packed),) | |
| learned = expit(state['prior_logits'][safe[seen]] + state['residual_logits'][safe[seen]]).astype(np.float32) | |
| p[seen] = learned if mode == 'raw' else ((learned + p[seen])/2).astype(np.float32) | |
| return p | |