File size: 1,546 Bytes
bce3b06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Checks a generated dataset by replaying it: applies each recorded solution to its
recorded state and confirms the cube ends solved.

This is the one check worth running on every dataset before training on it. A
generator bug that corrupts states or mislabels them is silent otherwise -- the
model simply learns the wrong function and the failure only surfaces much later,
as a bad benchmark number that looks like a modelling problem.
"""
import argparse, json, sys
from gen_data import SOLVED, apply_sequence


def main():
    p = argparse.ArgumentParser(description=__doc__)
    p.add_argument("path")
    p.add_argument("--limit", type=int, default=0, help="Check only the first N rows (0 = all).")
    args = p.parse_args()

    checked = failed = 0
    lengths = []
    with open(args.path) as fh:
        for line in fh:
            if args.limit and checked >= args.limit:
                break
            row = json.loads(line)
            if len(row["state"]) != 54:
                failed += 1
                continue
            moves = row["solution"].split()
            lengths.append(len(moves))
            if apply_sequence(row["state"], moves) != SOLVED:
                failed += 1
            checked += 1

    mean = sum(lengths) / len(lengths) if lengths else 0
    print(f"checked {checked}, solved {checked - failed}, FAILED {failed}")
    print(f"solution length: mean {mean:.2f} min {min(lengths, default=0)} max {max(lengths, default=0)}")
    sys.exit(1 if failed else 0)


if __name__ == "__main__":
    main()