"""Sweep driver for the Hidden Maze branchability test (paper Appendix C.2). Usage: python run_maze.py --out results/maze.jsonl [--seeds 0 1 2] [--concurrency 4] Depth sweep: N=4, D in {4,6,8,10}, (B,k) = (2,6),(3,9),(4,12),(4,15). Branching sweep: D=6, N in {2,4,6,8}, (B,k) = (3,9). """ import argparse import json import os import sys import threading from concurrent.futures import ThreadPoolExecutor, as_completed sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from agent import make_client, Usage # noqa: E402 from maze import run_condition # noqa: E402 LOCK = threading.Lock() def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default="results/maze.jsonl") ap.add_argument("--seeds", type=int, nargs="+", default=[0, 1, 2]) ap.add_argument("--concurrency", type=int, default=4) ap.add_argument("--root", default="runs") ap.add_argument("--treatments", nargs="+", default=["flat", "unstructured", "branch_native"]) args = ap.parse_args() os.makedirs(os.path.dirname(args.out) or ".", exist_ok=True) client = make_client() usage = Usage() depth_sweep = [(D, 4, B, k) for D, (B, k) in zip([4, 6, 8, 10], [(2, 6), (3, 9), (4, 12), (4, 15)])] branch_sweep = [(6, N, 3, 9) for N in [2, 4, 6, 8]] conditions = [] for D, N, B, k in depth_sweep + branch_sweep: for t in args.treatments: for s in args.seeds: conditions.append((D, N, B, k, t, s)) conditions = sorted(set(conditions)) print(f"{len(conditions)} condition-runs, concurrency {args.concurrency}", flush=True) def one(c): D, N, B, k, t, s = c try: res = run_condition(client, args.root, s, D, N, B, k, t, usage=usage) res["status"] = "ok" except Exception as e: res = {"task": "maze", "D": D, "N": N, "B": B, "k": k, "treatment": t, "seed": s, "status": "error", "error": repr(e)} with LOCK: with open(args.out, "a") as f: f.write(json.dumps(res) + "\n") print(f"done {c} -> {res.get('status')} " f"repfrac={res.get('repeated_fraction')}", flush=True) return res with ThreadPoolExecutor(max_workers=args.concurrency) as ex: futs = [ex.submit(one, c) for c in conditions] for f in as_completed(futs): f.result() print(json.dumps({"prompt_tokens": usage.prompt_tokens, "completion_tokens": usage.completion_tokens, "llm_calls": usage.calls}), flush=True) if __name__ == "__main__": main()