@@ -48,9 +48,48 @@ def test_create_decoder():
4848 decoder = tesseract_decoder .tesseract .TesseractDecoder (config )
4949 decoder .decode_to_errors ([0 ])
5050 decoder .decode_to_errors (detections = [0 ], det_order = 0 , det_beam = 0 )
51- assert decoder .mask_from_errors ([1 ]) == 0
51+ assert decoder .get_observables_from_errors ([1 ]) == []
5252 assert decoder .cost_from_errors ([1 ]) == pytest .approx (0.5108256237659907 )
53- assert decoder .decode ([0 ]) == 0
53+ assert decoder .decode ([0 ]) == []
54+
55+ def test_tesseract_decoder_predicts_various_observable_flips ():
56+ """
57+ Tests that the Tesseract decoder correctly predicts a logical observable
58+ flip when a specific detector is triggered by an error that explicitly
59+ flips that logical observable.
60+
61+ This test iterates through various observable IDs to ensure the backend logic
62+ correctly handles different positions.
63+ """
64+ # Iterate through observable IDs from 0 to 63 (inclusive)
65+ for observable_id in range (64 ):
66+ # Create a simple DetectorErrorModel where an error on D0 also flips L{observable_id}
67+ dem_string = f'''
68+ error(0.01) D0 L{ observable_id }
69+ '''
70+ dem = stim .DetectorErrorModel (dem_string )
71+
72+ # Initialize TesseractConfig and TesseractDecoder with the generated DEM
73+ config = tesseract_decoder .tesseract .TesseractConfig (dem )
74+ decoder = tesseract_decoder .tesseract .TesseractDecoder (config )
75+
76+ # Simulate a detection event on D0.
77+ # The decoder should identify the most likely error causing D0,
78+ # which in this DEM is the error that also flips L{observable_id}.
79+ # The decode method is expected to return an array where array[i] is True if observable i is flipped.
80+ predicted_logical_flips_array = decoder .decode (detections = [0 ])
81+
82+ # Convert the boolean array/list to a list of flipped observable IDs
83+ actual_flipped_observables = [
84+ idx for idx , is_flipped in enumerate (predicted_logical_flips_array ) if is_flipped
85+ ]
86+
87+ # Assert that the list of actual flipped observables matches the single expected observable_id.
88+ assert actual_flipped_observables == [observable_id ], \
89+ (f"For observable L{ observable_id } : "
90+ f"Expected predicted logical flips: [{ observable_id } ], "
91+ f"but got: { actual_flipped_observables } (from raw: { predicted_logical_flips_array } )" )
92+
5493
5594
5695if __name__ == "__main__" :
0 commit comments