File size: 2,913 Bytes
6e03b1a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Run the full ST-GFN vs baselines experiment suite.

Parallelises independent (env, method, seed) runs across worker processes; the
models are tiny so a single GPU is heavily under-utilised by one run.
"""
from __future__ import annotations

import argparse
import itertools
import json
import os
import subprocess
import sys
import time
from concurrent.futures import ProcessPoolExecutor

HERE = os.path.dirname(os.path.abspath(__file__))

ALL_METHODS = ["stgfn", "tb", "fm", "subtb", "db", "eflownet", "stochastic_gfn",
               "tb_rnd", "tb_novelty", "tb_icm", "tb_cv"]
ABLATIONS = ["stgfn_no_spectral", "stgfn_no_intrinsic"]


def one(job):
    env, method, seed, iters, out_dir, extra = job
    cmd = [sys.executable, os.path.join(HERE, "train.py"),
           "--env", env, "--methods", method, "--seeds", str(seed),
           "--iters", str(iters), "--out", out_dir]
    if extra:
        cmd += ["--set"] + extra
    t0 = time.time()
    r = subprocess.run(cmd, capture_output=True, text=True, cwd=HERE)
    ok = r.returncode == 0
    return {
        "env": env, "method": method, "seed": seed, "ok": ok,
        "secs": time.time() - t0,
        "tail": (r.stdout or "")[-300:] if ok else (r.stderr or "")[-800:],
    }


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("--envs", default="bitsequence,hypergrid,tictactoe,singlecell_proxy")
    ap.add_argument("--methods", default="all")
    ap.add_argument("--seeds", default="0,1,2,3,4")
    ap.add_argument("--iters", type=int, default=2000)
    ap.add_argument("--out", default="../outputs/main")
    ap.add_argument("--workers", type=int, default=5)
    ap.add_argument("--ablations", action="store_true")
    ap.add_argument("--set", nargs="*", default=[])
    args = ap.parse_args()

    methods = ALL_METHODS if args.methods == "all" else args.methods.split(",")
    if args.ablations:
        methods = methods + ABLATIONS
    envs = args.envs.split(",")
    seeds = [int(s) for s in args.seeds.split(",")]

    jobs = [(e, m, s, args.iters, args.out, args.set)
            for e, m, s in itertools.product(envs, methods, seeds)]
    # skip already-completed runs so the suite is resumable
    jobs = [j for j in jobs
            if not os.path.exists(os.path.join(HERE, j[4], f"{j[0]}__{j[1]}__seed{j[2]}.json"))]
    print(f"{len(jobs)} runs to do, {args.workers} workers", flush=True)

    t0 = time.time()
    done = 0
    with ProcessPoolExecutor(max_workers=args.workers) as ex:
        for res in ex.map(one, jobs):
            done += 1
            status = "ok " if res["ok"] else "FAIL"
            print(f"[{done}/{len(jobs)} {time.time()-t0:6.0f}s] {status} "
                  f"{res['env']}/{res['method']}/s{res['seed']} ({res['secs']:.0f}s) "
                  f"{res['tail'].strip()[:160]}", flush=True)
    print(f"suite finished in {time.time()-t0:.0f}s")


if __name__ == "__main__":
    main()