File size: 2,879 Bytes
726fc64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Smoke checks for the diagnostics-logging branch on a few OGA files.
Usage: python check_logging_smoke.py WORK_DIR NEW_OUT OLD_OUT"""
import collections, glob, os, re, sys
work, new, old = sys.argv[1:4]
ok = True
def check(cond, msg):
    global ok
    print(("PASS " if cond else "FAIL ") + msg); ok &= bool(cond)
stems = [os.path.basename(f)[:-5] for f in glob.glob(f"{new}/parts/*.done")]
same = all(open(f"{new}/parts/{s}.txt", encoding="utf-8").read() == open(f"{old}/parts/{s}.txt", encoding="utf-8").read() for s in stems)
check(same, f"output identical to the a949b76 run for {len(stems)} files")
def modcols(p):
    tot = collections.Counter()
    for row in open(p, encoding="utf-8"):
        cols = row.rstrip("\n").split("\t")
        if len(cols) >= 6 and cols[5]:
            for kv in cols[5].split(","):
                k, v = kv.split("="); tot[k] += int(v)
    return tot
check(all(modcols(f"{new}/parts/{s}.progress") == modcols(f"{old}/parts/{s}.progress") for s in stems), "module counts identical to the a949b76 run")
logs = glob.glob(f"{work}/diagnostics/logs/*.log")
pids = set()
bad_fmt = 0; starts = ends = 0
for lg in logs:
    for line in open(lg, encoding="utf-8", errors="replace"):
        m = re.match(r"^\d{4}-\d\d-\d\d [\d:,]+ - (\d+) - ", line)
        if m: pids.add(m.group(1))
        elif line.startswith("20"): bad_fmt += 1
        starts += "=== CHUNK START" in line; ends += "=== CHUNK END" in line
check(len(logs) >= 2 and bad_fmt == 0, f"{len(logs)} log files (one per process), every timestamped line has a pid ({len(pids)} pids)")
n_chunks = sum(1 for s in stems for _ in open(f"{new}/parts/{s}.progress"))
check(starts == ends == n_chunks, f"CHUNK START/END lines: {starts}/{ends} for {n_chunks} chunks")
traces = glob.glob(f"{work}/diagnostics/traces/*.tsv")
check(len(traces) == n_chunks and all(re.search(r"\.\d{5}\.tsv$", t) for t in traces), f"{len(traces)} traces named <stem>.<chunk>")
check(len(glob.glob(f"{work}/diagnostics/still_ambiguous/still_ambiguous_*.?????.tsv")) == n_chunks, "still_ambiguous files named by tag")
rows = match = 0; maxsent = 0; credit_tot = collections.Counter()
for t in traces:
    for i, line in enumerate(open(t, encoding="utf-8")):
        if i == 0: continue
        c = line.rstrip("\n").split("\t")
        rows += 1; maxsent = max(maxsent, int(c[0]))
        s = sum(int(kv.split("=")[1]) for kv in c[8].split(",") if kv)
        for kv in c[8].split(","):
            if kv: credit_tot[kv.split("=")[0]] += int(kv.split("=")[1])
        match += (s == int(c[5]) - int(c[6]))
check(rows > 0 and match / rows > 0.99, f"credits add up to before-after for {match}/{rows} tokens ({match/rows:.4%})")
check(maxsent < 500, f"sentence indices within a chunk (max {maxsent})")
print("credits:", credit_tot.most_common())
print("ALL OK" if ok else "SOME CHECKS FAILED")
sys.exit(0 if ok else 1)