Download code/run_rulebook.py from lewtun/gitswarm-ablation-replication: direct link, hf CLI and curl.
- Browser
- Download file 2.85 kB
-
https://huggingface.co/datasets/lewtun/gitswarm-ablation-replication/resolve/main/code/run_rulebook.py
- Command line
-
hf download hf://datasets/lewtun/gitswarm-ablation-replication/code/run_rulebook.py
-
curl -L -o run_rulebook.py https://huggingface.co/datasets/lewtun/gitswarm-ablation-replication/resolve/main/code/run_rulebook.py
2.85 kB
| """Sweep driver for the Hidden Rulebook persistence test (paper Appendix C.1). | |
| Usage: | |
| python run_rulebook.py --out results/rulebook.jsonl [--seeds 0 1 2] | |
| [--psweep 2 4 8 16] [--dsweep 2 4 8] | |
| [--treatments shared indep_B2 indep_k4] [--concurrency 4] | |
| """ | |
| 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 rulebook import run_condition # noqa: E402 | |
| LOCK = threading.Lock() | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--out", default="results/rulebook.jsonl") | |
| ap.add_argument("--seeds", type=int, nargs="+", default=[0, 1, 2]) | |
| ap.add_argument("--psweep", type=int, nargs="+", default=[2, 4, 8, 16]) | |
| ap.add_argument("--dsweep", type=int, nargs="+", default=[2, 4, 8]) | |
| ap.add_argument("--d-for-psweep", type=int, default=4) | |
| ap.add_argument("--p-for-dsweep", type=int, default=4) | |
| ap.add_argument("--treatments", nargs="+", | |
| default=["shared", "indep_B2", "indep_k4"]) | |
| ap.add_argument("--concurrency", type=int, default=4) | |
| ap.add_argument("--root", default="runs") | |
| args = ap.parse_args() | |
| os.makedirs(os.path.dirname(args.out) or ".", exist_ok=True) | |
| client = make_client() | |
| usage = Usage() | |
| conditions = [] | |
| for P in args.psweep: | |
| for t in args.treatments: | |
| for s in args.seeds: | |
| conditions.append((P, args.d_for_psweep, t, s)) | |
| for D in args.dsweep: | |
| for t in args.treatments: | |
| for s in args.seeds: | |
| conditions.append((args.p_for_dsweep, D, t, s)) | |
| conditions = sorted(set(conditions)) | |
| print(f"{len(conditions)} condition-runs, concurrency {args.concurrency}", | |
| flush=True) | |
| def one(c): | |
| P, D, t, s = c | |
| try: | |
| res = run_condition(client, args.root, s, P, D, t, usage=usage) | |
| res["status"] = "ok" | |
| except Exception as e: | |
| res = {"task": "rulebook", "P": P, "D": D, "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"coverage={res.get('coverage')}", 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() |