"""Give ST-GFN its best shot: sweep its own hyperparameters. A negative reproduction result is only meaningful if the proposed method was not simply under-tuned. We grid-search the three ST-GFN-specific knobs (spectral regularization weight lambda, consistency weight w_c, intrinsic coefficient beta) plus RFF dimension, on HyperGrid mode discovery -- the benchmark where the paper reports its largest margin (58.2 vs 14.3 modes) -- and compare the BEST ST-GFN configuration against a plain TB baseline. """ 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__)) def one(job): env, method, seed, overrides, iters, out_dir = job tag = "_".join(f"{k}{v}" for k, v in overrides) sub = os.path.join(out_dir, tag or "default") os.makedirs(os.path.join(HERE, sub), exist_ok=True) cmd = [sys.executable, os.path.join(HERE, "train.py"), "--env", env, "--methods", method, "--seeds", str(seed), "--iters", str(iters), "--out", sub] if overrides: cmd += ["--set"] + [f"{k}={v}" for k, v in overrides] t0 = time.time() r = subprocess.run(cmd, capture_output=True, text=True, cwd=HERE) ok = r.returncode == 0 return f"{'ok ' if ok else 'FAIL'} {method} {tag or 'default'} s{seed} ({time.time()-t0:.0f}s) " + \ ((r.stdout or "").strip().split("\n")[-1][:110] if ok else (r.stderr or "")[-250:]) if __name__ == "__main__": ap = argparse.ArgumentParser() ap.add_argument("--env", default="hypergrid") ap.add_argument("--iters", type=int, default=3000) ap.add_argument("--seeds", default="0,1,2") ap.add_argument("--out", default="../outputs/tune") ap.add_argument("--workers", type=int, default=6) args = ap.parse_args() seeds = [int(s) for s in args.seeds.split(",")] grid = [] for lam in [0.01, 0.05, 0.5]: for wc in [0.1, 1.0, 10.0]: grid.append((("lambda_init", lam), ("w_consistency", wc))) for beta in [0.0, 0.1, 1.0, 2.0]: grid.append((("beta", beta),)) for d in [64, 512]: grid.append((("rff_dim", d),)) for kmax in [4, 16]: grid.append((("k_max", kmax),)) # the charitable reading of Fig. 9(d): concentrate the lag weights on the # detected ACF peak instead of the paper's stated uniform initialisation grid.append((("ac_weight_mode", "peak"),)) for beta in [1.0, 2.0]: grid.append((("ac_weight_mode", "peak"), ("beta", beta))) jobs = [(args.env, "stgfn", s, list(g), args.iters, args.out) for g in grid for s in seeds] # TB reference under the identical budget jobs += [(args.env, "tb", s, [], args.iters, args.out) for s in seeds] jobs = [j for j in jobs if not os.path.exists(os.path.join( HERE, j[5], "_".join(f"{k}{v}" for k, v in j[3]) or "default", f"{j[0]}__{j[1]}__seed{j[2]}.json"))] print(f"{len(jobs)} tuning 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("TUNING FINISHED", flush=True)