File size: 3,728 Bytes
fd5366a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# Copyright (c) 2026 CLSA contributors
# SPDX-License-Identifier: MIT
"""Run E1-E9 and write results/INDEX.md linking result, config, seed and commit."""
from __future__ import annotations

import json
import sys
import traceback
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))

from clsa.eval.experiments import e1_main, e2_world_model, e3_budget, e4_calibration
from clsa.eval.experiments import e5_causality, e6_transfer, e7_multimodal, e9_efficiency
from clsa.eval.multiagent import e8_multiagent
from clsa.util import RESULTS, git_commit, load_config, utc_now, write_result

EXPERIMENTS = {
    "e1_main": ("E1 main comparison", e1_main),
    "e2_world_model": ("E2 world-model quality", e2_world_model),
    "e3_budget": ("E3 budget and Pareto", e3_budget),
    "e4_calibration": ("E4 calibration", e4_calibration),
    "e5_causality": ("E5 Tiwari dissociation", e5_causality),
    "e6_transfer": ("E6 held-out transfer", e6_transfer),
    "e7_multimodal": ("E7 multimodal / GUI split", e7_multimodal),
    "e8_multiagent": ("E8 multi-agent divergence", e8_multiagent),
    "e9_efficiency": ("E9 efficiency and distillation", e9_efficiency),
}


def main() -> None:
    cfg = load_config("controller")
    seed = int(cfg.get("seed", 0))
    status = []
    for name, (title, fn) in EXPERIMENTS.items():
        try:
            payload = fn()
            payload.pop("raw_rows", None)
            write_result(name, payload, config=cfg, seed=seed, notes=title)
            status.append((name, title, "ok", ""))
            print(f"[ok] {name}")
        except Exception as exc:  # noqa: BLE001
            write_result(
                name,
                {
                    "blocked": True,
                    "error": f"{type(exc).__name__}: {exc}",
                    "traceback": traceback.format_exc()[-2000:],
                },
                config=cfg,
                seed=seed,
                notes=f"BLOCKED: {title}",
            )
            status.append((name, title, "blocked", f"{type(exc).__name__}: {exc}"))
            print(f"[blocked] {name}: {exc}")

    lines = [
        "# Results index",
        "",
        f"Generated {utc_now()} at commit `{git_commit()}`.",
        "",
        "Every row links a result file to its config, seed and commit. Blocked",
        "experiments are listed with their reason; they are never silently dropped.",
        "",
        "| Experiment | Result file | Config | Seed | Commit | Status |",
        "|---|---|---|---|---|---|",
    ]
    for name, title, st, err in status:
        path = RESULTS / f"{name}.json"
        rec = json.loads(path.read_text()) if path.exists() else {}
        lines.append(
            f"| {title} | `results/{name}.json` | `{rec.get('config_path', '')}` | "
            f"{rec.get('seed')} | `{(rec.get('git_commit') or '')[:8]}` | "
            f"{st}{(' - ' + err) if err else ''} |"
        )
    lines += [
        "",
        "## Reproduction notes",
        "",
        "- `make bench` rebuilds PreAct-Bench and audits it (schema + fork replay).",
        "- `make train` harvests activations, then trains the transcoder, probes,",
        "  world model and risk head.",
        "- `make experiments` runs E1-E9 and rewrites this file.",
        "- `make figures` regenerates every figure from `results/`.",
        "",
        "## Pre-registration",
        "",
        "Committed at `7d3946a` before the main runs; see `PRE_REGISTRATION.md`.",
        "Deviations are recorded inside that file.",
    ]
    (RESULTS / "INDEX.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
    print("wrote results/INDEX.md")


if __name__ == "__main__":
    main()