|
7 | 7 | - [`chromobius.CompiledDecoder`](#chromobius.CompiledDecoder)
|
8 | 8 | - [`chromobius.CompiledDecoder.from_dem`](#chromobius.CompiledDecoder.from_dem)
|
9 | 9 | - [`chromobius.CompiledDecoder.predict_obs_flips_from_dets_bit_packed`](#chromobius.CompiledDecoder.predict_obs_flips_from_dets_bit_packed)
|
| 10 | + - [`chromobius.CompiledDecoder.predict_weighted_obs_flips_from_dets_bit_packed`](#chromobius.CompiledDecoder.predict_weighted_obs_flips_from_dets_bit_packed) |
10 | 11 | ```python
|
11 | 12 | # Types used by the method definitions.
|
12 | 13 | from typing import overload, TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Union
|
@@ -37,6 +38,7 @@ def compile_decoder_for_dem(
|
37 | 38 | 3 = Red Z
|
38 | 39 | 4 = Green Z
|
39 | 40 | 5 = Blue Z
|
| 41 | + -1 = Ignore this Detector |
40 | 42 | 2. Rainbow triplets. Bulk errors with three symptoms in one basis should
|
41 | 43 | have one symptom of each color. Errors with three symptoms that
|
42 | 44 | repeat a color will cause an exception unless they can be decomposed
|
@@ -143,6 +145,7 @@ def from_dem(
|
143 | 145 | 3 = Red Z
|
144 | 146 | 4 = Green Z
|
145 | 147 | 5 = Blue Z
|
| 148 | + -1 = Ignore this Detector |
146 | 149 | 2. Rainbow triplets. Bulk errors with three symptoms in one basis should
|
147 | 150 | have one symptom of each color. Errors with three symptoms that
|
148 | 151 | repeat a color will cause an exception unless they can be decomposed
|
@@ -264,3 +267,91 @@ def predict_obs_flips_from_dets_bit_packed(
|
264 | 267 | >>> assert mistakes < shots / 5
|
265 | 268 | """
|
266 | 269 | ```
|
| 270 | + |
| 271 | +<a name="chromobius.CompiledDecoder.predict_weighted_obs_flips_from_dets_bit_packed"></a> |
| 272 | +```python |
| 273 | +# chromobius.CompiledDecoder.predict_weighted_obs_flips_from_dets_bit_packed |
| 274 | + |
| 275 | +# (in class chromobius.CompiledDecoder) |
| 276 | +@staticmethod |
| 277 | +def predict_weighted_obs_flips_from_dets_bit_packed( |
| 278 | + dets: np.ndarray, |
| 279 | +) -> tuple[np.ndarray, np.ndarray]: |
| 280 | + """Predicts observable flips and weights from detection events. |
| 281 | +
|
| 282 | + The returned weight comes directly from the underlying call to pymatching, not |
| 283 | + accounting for the lifting process. |
| 284 | +
|
| 285 | + Args: |
| 286 | + dets: A bit packed numpy array of detection event data. The array can either |
| 287 | + be 1-dimensional (a single shot to decode) or 2-dimensional (multiple |
| 288 | + shots to decode, with the first axis being the shot axis and the second |
| 289 | + axis being the detection event byte axis). |
| 290 | +
|
| 291 | + The array's dtype must be np.uint8. If you have an array of dtype |
| 292 | + np.bool_, you have data that's not bit packed. You can pack it by |
| 293 | + using `np.packbits(array, bitorder='little')`. But ideally you |
| 294 | + should attempt to never have unpacked data in the first place, |
| 295 | + since it's 8x larger which can be a large performance loss. For |
| 296 | + example, stim's sampler methods all have a `bit_packed=True` argument |
| 297 | + that cause them to return bit packed data. |
| 298 | +
|
| 299 | + Returns: |
| 300 | + A tuple (obs, weights). |
| 301 | + Obs is a bit packed numpy array of observable flip data. |
| 302 | + Weights is a numpy array (or scalar) of floats. |
| 303 | +
|
| 304 | + If dets is a 1D array, then the result has: |
| 305 | + obs.shape = (math.ceil(num_obs / 8),) |
| 306 | + obs.dtype = np.uint8 |
| 307 | + weights.shape = () |
| 308 | + weights.dtype = np.float32 |
| 309 | + If dets is a 2D array, then the result has: |
| 310 | + shape = (dets.shape[0], math.ceil(num_obs / 8),) |
| 311 | + dtype = np.uint8 |
| 312 | + weights.shape = (dets.shape[0],) |
| 313 | + weights.dtype = np.float32 |
| 314 | +
|
| 315 | + To determine if the observable with index k was flipped in shot s, compute: |
| 316 | + `bool((obs[s, k // 8] >> (k % 8)) & 1)` |
| 317 | +
|
| 318 | + Example: |
| 319 | + >>> import stim |
| 320 | + >>> import chromobius |
| 321 | + >>> import numpy as np |
| 322 | +
|
| 323 | + >>> repetition_color_code = stim.Circuit(''' |
| 324 | + ... # Apply noise. |
| 325 | + ... X_ERROR(0.1) 0 1 2 3 4 5 6 7 |
| 326 | + ... # Measure three-body stabilizers to catch errors. |
| 327 | + ... MPP Z0*Z1*Z2 Z1*Z2*Z3 Z2*Z3*Z4 Z3*Z4*Z5 Z4*Z5*Z6 Z5*Z6*Z7 |
| 328 | + ... |
| 329 | + ... # Annotate detectors, with a coloring in the 4th coordinate. |
| 330 | + ... DETECTOR(0, 0, 0, 2) rec[-6] |
| 331 | + ... DETECTOR(1, 0, 0, 0) rec[-5] |
| 332 | + ... DETECTOR(2, 0, 0, 1) rec[-4] |
| 333 | + ... DETECTOR(3, 0, 0, 2) rec[-3] |
| 334 | + ... DETECTOR(4, 0, 0, 0) rec[-2] |
| 335 | + ... DETECTOR(5, 0, 0, 1) rec[-1] |
| 336 | + ... |
| 337 | + ... # Check on the message. |
| 338 | + ... M 0 |
| 339 | + ... OBSERVABLE_INCLUDE(0) rec[-1] |
| 340 | + ... ''') |
| 341 | +
|
| 342 | + >>> # Sample the circuit. |
| 343 | + >>> shots = 4096 |
| 344 | + >>> sampler = repetition_color_code.compile_detector_sampler() |
| 345 | + >>> dets, actual_obs_flips = sampler.sample( |
| 346 | + ... shots=shots, |
| 347 | + ... separate_observables=True, |
| 348 | + ... bit_packed=True, |
| 349 | + ... ) |
| 350 | +
|
| 351 | + >>> # Decode with Chromobius. |
| 352 | + >>> dem = repetition_color_code.detector_error_model() |
| 353 | + >>> decoder = chromobius.compile_decoder_for_dem(dem) |
| 354 | + >>> result = decoder.predict_weighted_obs_flips_from_dets_bit_packed(dets) |
| 355 | + >>> pred, weights = result |
| 356 | + """ |
| 357 | +``` |
0 commit comments