"""Robustness sweep: does ST-GFN degrade more gracefully than baselines as environment stochasticity increases? This is the most direct test of the paper's central robustness claim (Sec 4.2: "ST-GFN maintains stable training under extreme stochasticity"). We sweep the BitSequence action-failure rate and the TicTacToe opponent-optimality rate. """ 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__)) METHODS = ["stgfn", "tb", "stochastic_gfn", "eflownet", "subtb", "tb_novelty"] def one(job): env, method, seed, setting, iters, out_dir = job key, val = setting tag = f"{key}{val}" out_sub = os.path.join(out_dir, tag) os.makedirs(os.path.join(HERE, out_sub), exist_ok=True) cmd = [sys.executable, os.path.join(HERE, "train.py"), "--env", env, "--methods", method, "--seeds", str(seed), "--iters", str(iters), "--out", out_sub, "--set", f"{key}={val}"] t0 = time.time() r = subprocess.run(cmd, capture_output=True, text=True, cwd=HERE) return (f"{'ok ' if r.returncode==0 else 'FAIL'} {env}/{method}/s{seed} {tag} " f"({time.time()-t0:.0f}s) " + ((r.stdout or "").strip().split("\n")[-1][:120] if r.returncode == 0 else (r.stderr or "")[-300:])) if __name__ == "__main__": ap = argparse.ArgumentParser() ap.add_argument("--out", default="../outputs/sweep") ap.add_argument("--seeds", default="0,1,2") ap.add_argument("--workers", type=int, default=6) args = ap.parse_args() seeds = [int(s) for s in args.seeds.split(",")] jobs = [] for pf in [0.0, 0.3, 0.5, 0.7, 0.9]: for m, s in itertools.product(METHODS, seeds): jobs.append(("bitsequence", m, s, ("p_fail", pf), 4000, args.out)) for op in [0.0, 0.5, 0.9, 1.0]: for m, s in itertools.product(METHODS, seeds): jobs.append(("tictactoe", m, s, ("opp_optimal", op), 2500, args.out)) jobs = [j for j in jobs if not os.path.exists(os.path.join( HERE, j[5], f"{j[3][0]}{j[3][1]}", f"{j[0]}__{j[1]}__seed{j[2]}.json"))] print(f"{len(jobs)} sweep runs, {args.workers} workers", flush=True) t0 = time.time() with ProcessPoolExecutor(max_workers=args.workers) as ex: for i, line in enumerate(ex.map(one, jobs), 1): print(f"[{i}/{len(jobs)} {time.time()-t0:.0f}s] {line}", flush=True) print("SWEEP FINISHED", flush=True)