11import stim
22
33
4+ def get_dets_logicals (error : stim .DemInstruction ):
5+ dets = set ()
6+ logicals = set ()
7+ for t in error .targets_copy ():
8+ if t .is_logical_observable_id ():
9+ logicals = logicals .symmetric_difference ({t .val })
10+ elif t .is_relative_detector_id ():
11+ dets = dets .symmetric_difference ({t .val })
12+ return dets , logicals
13+
14+
415def _decompose_by_detector_partition (dem , partition_func ):
516 detector_coords = {}
617
@@ -19,17 +30,13 @@ def _decompose_by_detector_partition(dem, partition_func):
1930 # Make a new instruction where the detectors are decomposed.
2031 targets_by_basis = [[], []]
2132 observables = []
22- for d in instruction .targets_copy ():
23- if d .is_separator ():
24- # Ignore the existing decomposition, if present.
25- continue
26- if d .is_relative_detector_id ():
27- coord = detector_coords [d .val ]
28- targets_by_basis [partition_func (coord )].append (d )
29- else :
30- # Logical observables are placed in component 0.
31- assert d .is_logical_observable_id ()
32- observables .append (d )
33+ dets , logicals = get_dets_logicals (instruction )
34+ for det in sorted (dets ):
35+ coord = detector_coords [det ]
36+ targets_by_basis [partition_func (coord )].append (stim .target_relative_detector_id (det ))
37+ for obs in sorted (logicals ):
38+ # Logical observables are placed in component 0.
39+ observables .append (stim .target_logical_observable_id (obs ))
3340
3441 all_targets = []
3542 for targets in targets_by_basis :
0 commit comments