File size: 2,621 Bytes
be3b34d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Process AG4Masses stderr output files to create cleaner log files
#
# Usage: mklog.py [-h] [-o O] [-s S] errfiles [errfiles ...]
#
# positional arguments:
#   errfiles: stderr output files of AG4Masses
#
# options:
#   -h, --help  show this help message and exit
#   -o O        Output directory. Default: .
#   -s S        Log file suffix. Default: log

import os
import re
import sys
import argparse

def aglog(errfls, outdir, logfl_suffix):
  agfiles = {
    "alphageometry.py",
    "alphageometry_test.py",
    "ar.py",
    "ar_test.py",
    "beam_search.py",
    "dd.py",
    "dd_test.py",
    "ddar.py",
    "ddar_test.py",
    #"decoder_stack.py",
    "geometry.py",
    "geometry_test.py",
    "graph.py",
    "graph_test.py",
    "graph_utils.py",
    "graph_utils_test.py",
    "lm_inference.py",
    "lm_inference_test.py",
    "models.py",
    "numericals.py",
    "numericals_test.py",
    "pretty.py",
    "problem.py",
    "problem_test.py",
    "trace_back.py",
    "trace_back_test.py"
    #"transformer_layer.py" 
    }

  for errfl_path in errfls:
    fnbase = os.path.basename(errfl_path)
    if fnbase.endswith('.err'):
      fnbase = fnbase[:-4]
    logfl_path = f'{outdir}/{fnbase}.{logfl_suffix}'

    print(f'Processing {errfl_path}, writing log to {logfl_path}')

    with open(errfl_path, 'r') as errfl:
      with open(logfl_path, 'x') as logfl:
        for line in errfl:
          m = re.search('(\S+\.py):\d+', line)
          if m and os.path.basename(m.group(1)) not in agfiles:
            #print(f'Skipping log from {m.group(1)}')
            continue
          m = re.search('\S+\.cc:\d+|jax.tree_util.register_keypaths|' +
                        'ddar\.py:.+(Depth .+ time = |Nothing added, breaking)|' +
                        '!! try_translate_constrained_to_construct|warnings.warn|'+
                        'alphageometry.py:\d+] .*(LM output|Solving:|string=)',
                        line)
          if m:
            #print('Skipping ddar log')
            continue
          logfl.write(line)

def main():
  # Create the parser
  parser = argparse.ArgumentParser(description='Process AG4Masses stderr output files to create cleaner log files')
  # Add arguments
  parser.add_argument('errfiles', nargs='+', help='stderr output files of AG4Masses')
  parser.add_argument('-o', type=str, default='.',  help='Output directory. Default: .')
  parser.add_argument('-s', type=str, default='log',  help='Log file suffix. Default: log')
  # Execute the parse_args() method
  args = parser.parse_args()

  aglog(args.errfiles, args.o, args.s)

if __name__=='__main__':
   main()