Repository navigation
Expand file tree
/
Copy pathextract_fill_steps.py
More file actions
51 lines (44 loc) · 1.62 KB
/
Copy pathextract_fill_steps.py
File metadata and controls
51 lines (44 loc) · 1.62 KB
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
#!/usr/bin/env python3
"""Print each matrix's recorded squaring count from measure_fill_in.py logs.
Counts mark the first density upper bound reaching the target, not measured
density. ``never`` means the bound stays below the target; ``-`` means no result.
"""
import argparse
import re
from pathlib import Path
RESULT = re.compile(
r"^\s*(\S+/\S+)\s+(\d+|never|-)\s+(?:max_degree=|missing\b|error\b)"
)
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"logs",
nargs="*",
type=Path,
default=[Path(__file__).with_name("fill-log")],
help="fill logs (default: scripts/fill-log)",
)
args = parser.parse_args()
steps: dict[str, str] = {}
for path in args.logs:
try:
with path.open(encoding="utf-8") as log:
for line_number, line in enumerate(log, 1):
match = RESULT.match(line)
if match is None:
continue
matrix, count = match.groups()
if matrix in steps and steps[matrix] != count:
parser.error(
f"{path}:{line_number}: conflicting counts for {matrix}: "
f"{steps[matrix]} and {count}"
)
steps[matrix] = count
except OSError as error:
parser.error(str(error))
if not steps:
parser.error("no fill-in summary rows found")
for matrix, count in sorted(steps.items()):
print(f"{matrix}\t{count}")
if __name__ == "__main__":
main()