RoboRACE-Bench / src /robotics /bench /planbench_eval.py
Nabidnur's picture
RoboRACE: code, cached agent outputs, results, media, SO-101 renders (part 5)
99e41a8 verified
Raw History Blame Contribute Delete
3.29 kB
"""PlanBench Blocksworld (task 1, plan generation) analysis: single agents, LLM-Modulo, and swarms.
Every number is computed from results/planbench/*.jsonl (cached attempts + validator verdicts).
Swarm strategies use only the domain validator (never the ground truth):
plurality majority vote over the agents' one-shot plans (exact action sequence)
verify-select run every agent once, return any plan the validator accepts
cascade-Modulo agents in a fixed cheap-to-expensive order, each with its LLM-Modulo budget,
stop at the first validated plan (cost = calls actually spent)
"""
from __future__ import annotations
import json
from collections import Counter
from pathlib import Path
import numpy as np
from robotics.eval.stats import wilson
CASCADE = ["qwen3.8-27b@cerebras", "gemini-3.1-flash-lite", "qwen3.8-27b@groq", "gpt-oss-120b@groq", "gemma-4-31b"]
def load(dirpath="results/planbench"):
out = {}
for f in sorted(Path(dirpath).glob("*.jsonl")):
recs = {}
for line in open(f):
r = json.loads(line)
if not r.get("error_api") and r["attempts"]:
recs[r["instance_id"]] = r
out[f.stem] = recs
return out
def _row(name, ok, calls, extra=None):
k, n = int(sum(ok)), len(ok)
lo, hi = wilson(k, n)
return {"system": name, "acc": k / n, "lo": lo, "hi": hi, "calls": float(np.mean(calls)), "n": n, **(extra or {})}
def evaluate(min_cov=60, dirpath="results/planbench"):
data = load(dirpath)
agents = [a for a in data if len(data[a]) >= min_cov]
ids = sorted(set.intersection(*(set(data[a]) for a in agents)), key=int)
table = []
for a in agents:
rs = [data[a][i] for i in ids]
opt = [len(r["attempts"][-1]["plan"]) / r["gt_len"] for r in rs if r["modulo"]]
table.append(_row(f"{a} · one-shot", [r["oneshot"] for r in rs], [1] * len(rs)))
table.append(_row(f"{a} · LLM-Modulo (≤3 repairs)", [r["modulo"] for r in rs], [r["calls"] for r in rs],
{"plan_len_ratio": float(np.mean(opt)) if opt else float("nan")}))
plur, vsel, casc, casc_calls = [], [], [], []
for i in ids:
firsts = {a: tuple(data[a][i]["attempts"][0]["plan"]) for a in agents}
reached = {a: data[a][i]["attempts"][0]["reached"] for a in agents}
c = Counter(firsts.values())
top = max(c.values())
win = sorted(k for k, v in c.items() if v == top)[0]
plur.append(any(reached[a] for a in agents if firsts[a] == win))
vsel.append(any(reached.values()))
spent, ok = 0, False
for a in [x for x in CASCADE if x in agents]:
spent += data[a][i]["calls"]
if data[a][i]["modulo"]:
ok = True
break
casc.append(ok)
casc_calls.append(spent)
table.append(_row(f"swarm plurality (one-shot, {len(agents)} agents)", plur, [len(agents)] * len(ids)))
table.append(_row(f"swarm verify-select (one-shot, {len(agents)} agents)", vsel, [len(agents)] * len(ids)))
table.append(_row("swarm cascade-Modulo (cheap → expensive)", casc, casc_calls))
table.sort(key=lambda r: (-r["acc"], r["calls"]))
return {"agents": agents, "n_instances": len(ids), "table": table}