@@ -22,25 +22,24 @@ def parse_logfile(filepath):
2222 i = 0
2323 while i < len (lines ):
2424 line = lines [i ].strip ()
25+
2526 if not any (line .startswith (s ) for s in ['Error' , 'Detector' , 'activated_errors' , 'activated_dets' ]):
2627 continue
27- # Parse detector coordinates
28+
2829 if line .startswith ("Detector D" ):
2930 match = re .match (r'Detector D(\d+) coordinate \(([-\d.]+), ([-\d.]+), ([-\d.]+)\)' , line )
3031 if match :
3132 idx = int (match .group (1 ))
3233 coord = tuple (float (match .group (j )) for j in range (2 , 5 ))
3334 detector_coords [idx ] = coord
3435
35- # Parse error lines
3636 elif line .startswith ("Error{" ):
3737 match = re .search (r'Symptom\{([^\}]+)\}' , line )
3838 if match :
3939 dets = match .group (1 ).split ()
4040 det_indices = [int (d [1 :]) for d in dets if d .startswith ('D' )]
4141 error_to_detectors .append (det_indices )
4242
43- # Parse animation frames
4443 elif line .startswith ("activated_errors" ):
4544 try :
4645 error_line = lines [i ].strip ()
@@ -64,13 +63,11 @@ def parse_logfile(filepath):
6463 if not detector_coords :
6564 raise RuntimeError ("No detectors parsed!" )
6665
67- # Mean-center detector coordinates
6866 coords_array = np .array (list (detector_coords .values ()))
6967 mean_coord = coords_array .mean (axis = 0 )
7068 for k in detector_coords :
7169 detector_coords [k ] = (np .array (detector_coords [k ]) - mean_coord ).tolist ()
7270
73- # Compute error coordinates
7471 error_coords = {}
7572 for i , det_list in enumerate (error_to_detectors ):
7673 try :
@@ -80,9 +77,12 @@ def parse_logfile(filepath):
8077 except KeyError as e :
8178 print (f"⚠️ Skipping error { i } : unknown detector { e } " )
8279
80+ error_to_detectors_dict = {str (i ): dets for i , dets in enumerate (error_to_detectors )}
81+
8382 return {
8483 "detectorCoords" : {str (k ): v for k , v in detector_coords .items ()},
8584 "errorCoords" : {str (k ): v for k , v in error_coords .items ()},
85+ "errorToDetectors" : error_to_detectors_dict ,
8686 "frames" : frames
8787 }
8888
0 commit comments