File size: 1,823 Bytes
314ecfb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Extract recorder kinematics for every finished, failed route of a (possibly still running) eval.

Usage: python extract_failed.py RESULT_ROOT --ports 2000,2010,...
"""
import argparse
import glob
import json
import subprocess
import sys
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path

from failure_report import is_success

HERE = Path(__file__).resolve().parent


def finished_records(root):
    recs = {}
    for f in glob.glob(f"{root}/bench2drive220_*.json"):
        try:
            data = json.load(open(f))
        except json.JSONDecodeError:
            continue
        for r in data.get("_checkpoint", {}).get("records", []):
            if r.get("status") and r["status"] != "Started":
                recs[r["route_id"]] = r
    return recs


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("root")
    ap.add_argument("--ports", default="2000")
    args = ap.parse_args()
    root = Path(args.root)
    out_dir = root / "analysis" / "npz"
    recs = finished_records(root)
    todo = []
    for rid, r in recs.items():
        log = root / "recorder" / f"{rid}.log"
        if not is_success(r) and log.exists() and not (out_dir / f"{rid}.npz").exists():
            todo.append(str(log))
    ports = [int(p) for p in args.ports.split(",")]
    print(f"{len(recs)} finished, {len(todo)} failed logs to extract", flush=True)
    chunks = [todo[k::len(ports)] for k in range(len(ports))]

    def run(k):
        if not chunks[k]:
            return
        subprocess.run([sys.executable, str(HERE / "recorder_extract.py"), "--port", str(ports[k]),
                        "--out-dir", str(out_dir), *chunks[k]], check=False)

    with ThreadPoolExecutor(len(ports)) as ex:
        list(ex.map(run, range(len(ports))))


if __name__ == "__main__":
    main()