Datasets:
sync scripts: Track D, Panda env, RACE-Net, text mazes
Browse files- scripts/make_gifs.py +1 -0
- scripts/make_videos.py +127 -1
- scripts/maze_llm_agents.py +75 -0
- scripts/run_benchmark.py +56 -9
- scripts/so101_generate.py +7 -3
- scripts/so101_score_views.py +7 -3
- scripts/train_racenet.py +80 -0
scripts/make_gifs.py
CHANGED
|
@@ -15,6 +15,7 @@ SPEC = { # name: (start s, duration s or None, width px, fps)
|
|
| 15 |
"robot_rollouts": (4.0, 12.3, 960, 10),
|
| 16 |
"swarm_rendezvous": (0.0, None, 960, 12),
|
| 17 |
"planbench_modulo": (0.0, None, 720, 10),
|
|
|
|
| 18 |
}
|
| 19 |
|
| 20 |
|
|
|
|
| 15 |
"robot_rollouts": (4.0, 12.3, 960, 10),
|
| 16 |
"swarm_rendezvous": (0.0, None, 960, 12),
|
| 17 |
"planbench_modulo": (0.0, None, 720, 10),
|
| 18 |
+
"maze_swarm": (4.0, None, 960, 10),
|
| 19 |
}
|
| 20 |
|
| 21 |
|
scripts/make_videos.py
CHANGED
|
@@ -384,8 +384,134 @@ def planbench_modulo():
|
|
| 384 |
return OUT / "planbench_modulo.mp4"
|
| 385 |
|
| 386 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 387 |
if __name__ == "__main__":
|
| 388 |
-
which = sys.argv[1:] or ["swarm_rendezvous", "planbench_modulo", "robot_rollouts"]
|
| 389 |
for name in which:
|
| 390 |
p = globals()[name]()
|
| 391 |
print(p, f"{p.stat().st_size / 1e6:.1f} MB (README GIFs: python scripts/make_gifs.py)", flush=True)
|
|
|
|
| 384 |
return OUT / "planbench_modulo.mp4"
|
| 385 |
|
| 386 |
|
| 387 |
+
# ============================================================================ Track D maze swarm
|
| 388 |
+
def _maze_xml(G, goal, n, byz, cell=0.2):
|
| 389 |
+
H, W = G.shape
|
| 390 |
+
walls = "".join(f'<geom type="box" size="{cell / 2} {cell / 2} 0.07" pos="{c * cell:.2f} {-(r * cell):.2f} 0.07" material="wall"/>'
|
| 391 |
+
for r in range(H) for c in range(W) if G[r, c])
|
| 392 |
+
bots = ""
|
| 393 |
+
for i in range(n):
|
| 394 |
+
col = "0.86 0.15 0.15 1" if byz[i] else "0.06 0.46 0.43 1"
|
| 395 |
+
bots += (f'<body name="bot{i}" mocap="true" pos="0 0 0.05"><geom type="cylinder" size="0.065 0.035" rgba="{col}"/>'
|
| 396 |
+
f'<geom type="sphere" size="0.03" pos="0 0 0.05" rgba="0.95 0.95 0.95 1"/>'
|
| 397 |
+
f'<geom type="cylinder" size="0.03 0.012" pos="0 0.07 -0.01" euler="1.5708 0 0" rgba="0.1 0.1 0.1 1"/>'
|
| 398 |
+
f'<geom type="cylinder" size="0.03 0.012" pos="0 -0.07 -0.01" euler="1.5708 0 0" rgba="0.1 0.1 0.1 1"/></body>')
|
| 399 |
+
cx, cy = (W - 1) * cell / 2, -(H - 1) * cell / 2
|
| 400 |
+
return f"""<mujoco><visual><global offwidth="1280" offheight="960"/><quality shadowsize="4096"/>
|
| 401 |
+
<headlight ambient="0.5 0.5 0.5" diffuse="0.4 0.4 0.4" specular="0 0 0"/></visual>
|
| 402 |
+
<asset><material name="wall" rgba="0.35 0.38 0.45 1"/>
|
| 403 |
+
<texture name="fl" type="2d" builtin="checker" rgb1="0.93 0.92 0.9" rgb2="0.88 0.87 0.85" width="128" height="128"/>
|
| 404 |
+
<material name="floor" texture="fl" texrepeat="{W} {H}"/>
|
| 405 |
+
<texture type="skybox" builtin="gradient" rgb1="0.96 0.96 0.97" rgb2="0.8 0.83 0.88" width="64" height="128"/></asset>
|
| 406 |
+
<worldbody><light pos="{cx} {cy - 2} 6" dir="0 0.25 -1" diffuse="0.6 0.6 0.6" castshadow="true"/>
|
| 407 |
+
<geom type="plane" size="{W * cell} {H * cell} 0.01" pos="{cx} {cy} 0" material="floor"/>
|
| 408 |
+
<geom type="cylinder" size="{cell * 0.42} 0.004" pos="{goal[1] * cell:.2f} {-(goal[0] * cell):.2f} 0.004" rgba="0.96 0.62 0.04 1"/>
|
| 409 |
+
<body name="look" pos="{cx} {cy + 0.25} 0"/>
|
| 410 |
+
<camera name="iso" mode="targetbody" target="look" pos="{cx} {cy - 4.1} 5.2"/>
|
| 411 |
+
{walls}{bots}</worldbody></mujoco>"""
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def _belief_panel(G, B, pos, byz, goal, recv, title, stats, size=300):
|
| 415 |
+
H, W = G.shape
|
| 416 |
+
k = size // H
|
| 417 |
+
im = Image.new("RGB", (400, H * k + 54), BG)
|
| 418 |
+
d = ImageDraw.Draw(im)
|
| 419 |
+
col = {"free": (243, 244, 246), "wall": (75, 85, 99), "unknown": (209, 213, 219), "false_wall": (220, 38, 38),
|
| 420 |
+
"missed_wall": (251, 191, 36)}
|
| 421 |
+
for r in range(H):
|
| 422 |
+
for c in range(W):
|
| 423 |
+
b, g = (B[r, c] if B is not None else -1), G[r, c]
|
| 424 |
+
key = "unknown" if b < 0 else ("wall" if g else "false_wall") if b == 1 else ("missed_wall" if g else "free")
|
| 425 |
+
d.rectangle([c * k, 54 + r * k, c * k + k - 1, 54 + r * k + k - 1], fill=col[key])
|
| 426 |
+
d.ellipse([goal[1] * k - 2, 54 + goal[0] * k - 2, goal[1] * k + k + 1, 54 + goal[0] * k + k + 1], outline=(217, 119, 6), width=3)
|
| 427 |
+
for i, (r, c) in enumerate(pos):
|
| 428 |
+
fill = (220, 38, 38) if byz[i] else (15, 118, 110)
|
| 429 |
+
d.ellipse([c * k + 1, 54 + r * k + 1, c * k + k - 2, 54 + r * k + k - 2], fill=fill,
|
| 430 |
+
outline=(0, 0, 0) if i == recv else None, width=2)
|
| 431 |
+
d.text((2, 2), title, font=font(16, True), fill=INK)
|
| 432 |
+
d.text((2, 26), stats, font=font(13), fill=(75, 85, 99))
|
| 433 |
+
return im
|
| 434 |
+
|
| 435 |
+
|
| 436 |
+
def maze_swarm(attack="invert", F=3):
|
| 437 |
+
import mujoco
|
| 438 |
+
from robotics.bench import trackD
|
| 439 |
+
rows = json.loads(Path("results/trackD/rows.json").read_text())
|
| 440 |
+
gap = {}
|
| 441 |
+
for r in rows:
|
| 442 |
+
if r["attack"] == attack and r["liars"] == F and r["method"] in ("race_map", "majority"):
|
| 443 |
+
gap.setdefault(r["subset"], {})[r["method"]] = r["acc"]
|
| 444 |
+
seed = max(gap, key=lambda k: gap[k]["race_map"] - gap[k]["majority"])
|
| 445 |
+
runs = {}
|
| 446 |
+
for m in ("majority", "race_map"):
|
| 447 |
+
tr = []
|
| 448 |
+
res = trackD.episode(seed, attack, F, m, trace=tr)
|
| 449 |
+
runs[m] = (tr, res)
|
| 450 |
+
G, goal, byz = runs["race_map"][1]["G"], runs["race_map"][1]["goal"], runs["race_map"][1]["byz"]
|
| 451 |
+
n = len(byz)
|
| 452 |
+
recv = int(np.flatnonzero(~byz)[0])
|
| 453 |
+
model = mujoco.MjModel.from_xml_string(_maze_xml(G, goal, n, byz))
|
| 454 |
+
data = mujoco.MjData(model)
|
| 455 |
+
ren = mujoco.Renderer(model, 640, 760)
|
| 456 |
+
mids = [model.body_mocapid[model.body(f"bot{i}").id] for i in range(n)]
|
| 457 |
+
Tm = max(len(runs[m][0]) for m in runs)
|
| 458 |
+
wr = Writer(OUT / "maze_swarm.mp4")
|
| 459 |
+
wr.add(card("RoboRACE · Track D · maze swarm", [
|
| 460 |
+
f"6 mobile robots explore an unknown maze and share what they sense. {F} of them lie:",
|
| 461 |
+
"they report every wall as free and every free cell as a wall.",
|
| 462 |
+
"Majority map fusion vs RACE map fusion: each robot verifies peers against the cells it sensed",
|
| 463 |
+
"itself, then INVERTS consistent liars and uses their reports."], accent=(124, 58, 237)), FPS * 4)
|
| 464 |
+
last_B = {m: None for m in runs}
|
| 465 |
+
sub = 5
|
| 466 |
+
for t in range(Tm + 6):
|
| 467 |
+
frames = {}
|
| 468 |
+
for m, (tr, res) in runs.items():
|
| 469 |
+
st = tr[min(t, len(tr) - 1)]
|
| 470 |
+
prev = tr[min(max(t - 1, 0), len(tr) - 1)]
|
| 471 |
+
if recv in st["beliefs"]:
|
| 472 |
+
last_B[m] = st["beliefs"][recv]
|
| 473 |
+
frames[m] = (st, prev)
|
| 474 |
+
for k in range(sub):
|
| 475 |
+
a = (k + 1) / sub
|
| 476 |
+
st, prev = frames["race_map"]
|
| 477 |
+
for i in range(n):
|
| 478 |
+
r = prev["pos"][i][0] + (st["pos"][i][0] - prev["pos"][i][0]) * a
|
| 479 |
+
c = prev["pos"][i][1] + (st["pos"][i][1] - prev["pos"][i][1]) * a
|
| 480 |
+
data.mocap_pos[mids[i]] = [c * 0.2, -r * 0.2, 0.05]
|
| 481 |
+
mujoco.mj_forward(model, data)
|
| 482 |
+
ren.update_scene(data, camera="iso")
|
| 483 |
+
im = Image.new("RGB", (W, H), BG)
|
| 484 |
+
d = ImageDraw.Draw(im)
|
| 485 |
+
d.text((16, 8), f"Track D · cooperative maze exploration · {F} of {n} robots invert their reports", font=font(19, True), fill=INK)
|
| 486 |
+
im.paste(Image.fromarray(ren.render()).resize((606, 720 - 44 - 8)), (8, 44))
|
| 487 |
+
d.text((20, 52), "RACE map run (3-D view): teal = honest, red = liar, gold = goal", font=font(13, True), fill=INK)
|
| 488 |
+
for row, m in enumerate(("majority", "race_map")):
|
| 489 |
+
tr, res = runs[m]
|
| 490 |
+
st = frames[m][0]
|
| 491 |
+
honest_done = int(st["done"][~byz].sum())
|
| 492 |
+
B = last_B[m]
|
| 493 |
+
wrong = int(((B == 1) & (G == 0)).sum()) if B is not None else 0
|
| 494 |
+
finished = t >= len(tr) - 1
|
| 495 |
+
stats = (f"step {min(t + 1, len(tr))} · at goal {honest_done}/{int((~byz).sum())} · false walls {wrong}"
|
| 496 |
+
+ (f" · SPL {res['spl']:.2f}" if finished else ""))
|
| 497 |
+
title = "Majority map fusion" if m == "majority" else "RACE map fusion (ours)"
|
| 498 |
+
panel = _belief_panel(G, B, st["pos"], byz, goal, recv, title, stats, size=280)
|
| 499 |
+
im.paste(panel, (628, 44 + row * 338))
|
| 500 |
+
d.rectangle([1040, 60, 1270, 300], fill=(255, 255, 255), outline=(229, 231, 235), width=2)
|
| 501 |
+
d.text((1052, 252), "maps = belief of the\nrobot circled in black", font=font(13), fill=(75, 85, 99), spacing=4)
|
| 502 |
+
for j, (cc, lab) in enumerate((((75, 85, 99), "wall (correct)"), ((243, 244, 246), "free (correct)"), ((209, 213, 219), "unknown"),
|
| 503 |
+
((220, 38, 38), "FALSE wall (lie believed)"), ((251, 191, 36), "missed wall"))):
|
| 504 |
+
d.rectangle([1052, 74 + 34 * j, 1070, 92 + 34 * j], fill=cc, outline=(156, 163, 175))
|
| 505 |
+
d.text((1080, 74 + 34 * j), lab, font=font(13), fill=INK)
|
| 506 |
+
wr.add(im)
|
| 507 |
+
ren.close()
|
| 508 |
+
wr.add(im, FPS * 3)
|
| 509 |
+
wr.close()
|
| 510 |
+
return OUT / "maze_swarm.mp4"
|
| 511 |
+
|
| 512 |
+
|
| 513 |
if __name__ == "__main__":
|
| 514 |
+
which = sys.argv[1:] or ["swarm_rendezvous", "planbench_modulo", "robot_rollouts", "maze_swarm"]
|
| 515 |
for name in which:
|
| 516 |
p = globals()[name]()
|
| 517 |
print(p, f"{p.stat().st_size / 1e6:.1f} MB (README GIFs: python scripts/make_gifs.py)", flush=True)
|
scripts/maze_llm_agents.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""LLM agents on procedural text mazes: one-shot answer, then LLM-Modulo repair with exact validator feedback.
|
| 3 |
+
|
| 4 |
+
GROQ_API_KEY=... CEREBRAS_API_KEY=... GEMINI_API_KEY=... python scripts/maze_llm_agents.py [agent ...]
|
| 5 |
+
Resumable: results/maze_llm/<agent>.jsonl
|
| 6 |
+
"""
|
| 7 |
+
import json
|
| 8 |
+
import re
|
| 9 |
+
import sys
|
| 10 |
+
import threading
|
| 11 |
+
import time
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 15 |
+
from robotics.benchmarks import maze_text as mt # noqa: E402
|
| 16 |
+
from robotics.llm.providers import LLMError, chat # noqa: E402
|
| 17 |
+
|
| 18 |
+
AGENTS = {
|
| 19 |
+
"gpt-oss-120b@groq": ("groq", "openai/gpt-oss-120b", 3.0),
|
| 20 |
+
"qwen3.8-27b@groq": ("groq", "qwen/qwen3.8-27b", 2.0),
|
| 21 |
+
"qwen3.8-27b@cerebras": ("cerebras", "qwen-3.8-27b", 2.0),
|
| 22 |
+
"gemini-3.1-flash-lite": ("gemini", "gemini-3.1-flash-lite", 4.5),
|
| 23 |
+
}
|
| 24 |
+
REPAIRS = 3
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def run_agent(name, insts, outdir):
|
| 28 |
+
prov, model, pace = AGENTS[name]
|
| 29 |
+
path = Path(outdir) / (re.sub(r"[^A-Za-z0-9.@-]+", "_", name) + ".jsonl")
|
| 30 |
+
done = set()
|
| 31 |
+
if path.exists():
|
| 32 |
+
done = {json.loads(line)["id"] for line in open(path) if not json.loads(line).get("error_api")}
|
| 33 |
+
for inst in insts:
|
| 34 |
+
if inst["id"] in done:
|
| 35 |
+
continue
|
| 36 |
+
msgs = [{"role": "user", "content": mt.prompt(inst)}]
|
| 37 |
+
attempts, err_api, t = [], None, time.perf_counter()
|
| 38 |
+
for _ in range(REPAIRS + 1):
|
| 39 |
+
try:
|
| 40 |
+
text, _ = chat(msgs, providers=[prov], model=model, max_tokens=8000, retries_per_provider=6,
|
| 41 |
+
backoff=8.0, timeout=240)
|
| 42 |
+
except LLMError as e:
|
| 43 |
+
err_api = str(e)[:150]
|
| 44 |
+
break
|
| 45 |
+
p = mt.parse(text)
|
| 46 |
+
v = mt.validate(inst, p)
|
| 47 |
+
attempts.append({"path": p, "solved": v["solved"], "error": v["error"], "n_moves": v["n_moves"]})
|
| 48 |
+
if v["solved"]:
|
| 49 |
+
break
|
| 50 |
+
msgs += [{"role": "assistant", "content": text[-1500:]},
|
| 51 |
+
{"role": "user", "content": f"That path is wrong: {v['error']}. Give a corrected complete path "
|
| 52 |
+
"from S, ending with a line 'PATH: <moves>'."}]
|
| 53 |
+
time.sleep(pace)
|
| 54 |
+
rec = {"id": inst["id"], "agent": name, "cells": inst["cells"], "optimal": inst["optimal"], "attempts": attempts,
|
| 55 |
+
"oneshot": bool(attempts and attempts[0]["solved"]), "modulo": bool(attempts and attempts[-1]["solved"]),
|
| 56 |
+
"calls": len(attempts), "latency_s": round(time.perf_counter() - t, 1), "error_api": err_api}
|
| 57 |
+
with path.open("a") as f:
|
| 58 |
+
f.write(json.dumps(rec) + "\n")
|
| 59 |
+
time.sleep(pace)
|
| 60 |
+
print("done", name, flush=True)
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def main():
|
| 64 |
+
names = sys.argv[1:] or list(AGENTS)
|
| 65 |
+
insts = mt.suite()
|
| 66 |
+
Path("results/maze_llm").mkdir(parents=True, exist_ok=True)
|
| 67 |
+
ths = [threading.Thread(target=run_agent, args=(n, insts, "results/maze_llm")) for n in names]
|
| 68 |
+
for t in ths:
|
| 69 |
+
t.start()
|
| 70 |
+
for t in ths:
|
| 71 |
+
t.join()
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
main()
|
scripts/run_benchmark.py
CHANGED
|
@@ -9,7 +9,7 @@ import time
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 12 |
-
from robotics.bench import erqa_swarm, leaderboard, planbench_eval, trackA, trackB, trackC # noqa: E402
|
| 13 |
|
| 14 |
OUT = Path("results")
|
| 15 |
|
|
@@ -22,6 +22,20 @@ def _save(rows, path):
|
|
| 22 |
REUSE = "--reuse-tracks" in sys.argv # load saved Track A/A0/B/C rows instead of recomputing them
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def _rows_or(path, compute):
|
| 26 |
if REUSE and path.exists():
|
| 27 |
return json.loads(path.read_text())
|
|
@@ -108,22 +122,30 @@ def main():
|
|
| 108 |
md += [""]
|
| 109 |
# ------------------------------------------------------------------ RoboRACE tracks
|
| 110 |
md += ["## Part II — RoboRACE-Bench tracks", ""]
|
| 111 |
-
for key,
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
| 115 |
if not path.exists():
|
| 116 |
continue
|
| 117 |
hist, ev = trackA.load_scores(path)
|
| 118 |
-
if len(ev[1]) <
|
| 119 |
continue
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
text, tab = leaderboard.markdown(title, rows, f"History {len(hist[1])} unlabelled episodes, evaluation "
|
| 123 |
f"{len(ev[1])} episodes, 5 camera agents; every camera takes a turn as the receiver.")
|
| 124 |
md += [text, ""]
|
| 125 |
summary[key] = tab
|
| 126 |
-
_save(rows,
|
| 127 |
rows = _rows_or(OUT / "trackB/rows.json", lambda: trackB.run(n_missions=40, Fs=(1, 2, 3, 4, 5)))
|
| 128 |
text, tab = leaderboard.markdown("Track B — Byzantine-resilient cooperative localization + rendezvous (12 robots)",
|
| 129 |
rows, "Score = mission success rate (all honest robots within 0.5 m of target).")
|
|
@@ -141,6 +163,31 @@ def main():
|
|
| 141 |
_save(rows, OUT / "trackC/rows.json")
|
| 142 |
summary["C"] = tab
|
| 143 |
summary["C_systems"] = sys_rows
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
(OUT / "LEADERBOARD.md").write_text("\n".join(md))
|
| 145 |
(OUT / "leaderboard.json").write_text(json.dumps(summary, indent=1, default=float))
|
| 146 |
print("\n".join(md))
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 12 |
+
from robotics.bench import erqa_swarm, leaderboard, planbench_eval, trackA, trackB, trackC, trackD # noqa: E402
|
| 13 |
|
| 14 |
OUT = Path("results")
|
| 15 |
|
|
|
|
| 22 |
REUSE = "--reuse-tracks" in sys.argv # load saved Track A/A0/B/C rows instead of recomputing them
|
| 23 |
|
| 24 |
|
| 25 |
+
def maze_llm_table(d):
|
| 26 |
+
out = []
|
| 27 |
+
for f in sorted(Path(d).glob("*.jsonl")):
|
| 28 |
+
rs = [r for r in map(json.loads, open(f)) if not r.get("error_api") and r["attempts"]]
|
| 29 |
+
rs = list({r["id"]: r for r in rs}.values())
|
| 30 |
+
if len(rs) < 10:
|
| 31 |
+
continue
|
| 32 |
+
m = lambda xs: sum(xs) / len(xs) if xs else float("nan") # noqa: E731
|
| 33 |
+
out.append({"agent": f.stem, "n": len(rs), "oneshot": m([r["oneshot"] for r in rs]), "modulo": m([r["modulo"] for r in rs]),
|
| 34 |
+
"modulo_4": m([r["modulo"] for r in rs if r["cells"] == 4]),
|
| 35 |
+
"modulo_6": m([r["modulo"] for r in rs if r["cells"] == 6]), "calls": m([r["calls"] for r in rs])})
|
| 36 |
+
return sorted(out, key=lambda r: -r["modulo"])
|
| 37 |
+
|
| 38 |
+
|
| 39 |
def _rows_or(path, compute):
|
| 40 |
if REUSE and path.exists():
|
| 41 |
return json.loads(path.read_text())
|
|
|
|
| 122 |
md += [""]
|
| 123 |
# ------------------------------------------------------------------ RoboRACE tracks
|
| 124 |
md += ["## Part II — RoboRACE-Bench tracks", ""]
|
| 125 |
+
for key, name, title in (("A", "so101", "Track A — SO-101 physics rollouts, 5-camera success verification (Cosmos-Reason2-2B)"),
|
| 126 |
+
("AP", "panda", "Track A-Panda — cross-embodiment replication on a Franka Panda (all methods and "
|
| 127 |
+
"hyper-parameters frozen before this data existed)"),
|
| 128 |
+
("A0", "trackA", "Track A0 — procedural tabletop scenes (first iteration; development set for RACE-Net)")):
|
| 129 |
+
path, rows_path = OUT / name / "vlm_scores.jsonl", OUT / name / "rows.json"
|
| 130 |
if not path.exists():
|
| 131 |
continue
|
| 132 |
hist, ev = trackA.load_scores(path)
|
| 133 |
+
if len(ev[1]) < 100:
|
| 134 |
continue
|
| 135 |
+
run = lambda only=None: trackA.run(hist, ev, max_subsets=3, receivers=range(len(trackA.CAMS)), only=only) # noqa: E731
|
| 136 |
+
if REUSE and rows_path.exists():
|
| 137 |
+
rows = json.loads(rows_path.read_text())
|
| 138 |
+
missing = set(trackA.methods()) - {r["method"] for r in rows}
|
| 139 |
+
if missing: # cells are deterministic: add only the new methods
|
| 140 |
+
print(f"[{name}] adding methods: {sorted(missing)}", flush=True)
|
| 141 |
+
rows += run(missing)
|
| 142 |
+
else:
|
| 143 |
+
rows = run()
|
| 144 |
text, tab = leaderboard.markdown(title, rows, f"History {len(hist[1])} unlabelled episodes, evaluation "
|
| 145 |
f"{len(ev[1])} episodes, 5 camera agents; every camera takes a turn as the receiver.")
|
| 146 |
md += [text, ""]
|
| 147 |
summary[key] = tab
|
| 148 |
+
_save(rows, rows_path)
|
| 149 |
rows = _rows_or(OUT / "trackB/rows.json", lambda: trackB.run(n_missions=40, Fs=(1, 2, 3, 4, 5)))
|
| 150 |
text, tab = leaderboard.markdown("Track B — Byzantine-resilient cooperative localization + rendezvous (12 robots)",
|
| 151 |
rows, "Score = mission success rate (all honest robots within 0.5 m of target).")
|
|
|
|
| 163 |
_save(rows, OUT / "trackC/rows.json")
|
| 164 |
summary["C"] = tab
|
| 165 |
summary["C_systems"] = sys_rows
|
| 166 |
+
d_path = OUT / "trackD/rows.json"
|
| 167 |
+
rows = json.loads(d_path.read_text()) if (REUSE and d_path.exists()) else trackD.run(n_mazes=20, procs=2)
|
| 168 |
+
text, tab = leaderboard.markdown("Track D — Byzantine cooperative maze exploration (6 mobile robots, 20 mazes)", rows,
|
| 169 |
+
"Score = SPL (success weighted by path length) of honest robots; a robot fails beyond "
|
| 170 |
+
"2.5x its optimal path + 10 steps.")
|
| 171 |
+
succ = {}
|
| 172 |
+
for r in rows:
|
| 173 |
+
succ.setdefault(r["method"], []).append(r["success"])
|
| 174 |
+
md += [text, "", "Goal-reaching rate of honest robots (all cells): "
|
| 175 |
+
+ ", ".join(f"{m} {100 * sum(v) / len(v):.1f}%" for m, v in sorted(succ.items(), key=lambda kv: -sum(kv[1]) / len(kv[1]))) + ".", ""]
|
| 176 |
+
summary["D"] = tab
|
| 177 |
+
summary["D_success"] = {m: sum(v) / len(v) for m, v in succ.items()}
|
| 178 |
+
_save(rows, d_path)
|
| 179 |
+
if (OUT / "maze_llm").exists():
|
| 180 |
+
mz = maze_llm_table(OUT / "maze_llm")
|
| 181 |
+
if mz:
|
| 182 |
+
summary["maze_llm"] = mz
|
| 183 |
+
md += ["### LLM agents on procedural text mazes (exact validator, LLM-Modulo ≤3 repairs)", "",
|
| 184 |
+
"| agent | n | one-shot | LLM-Modulo | 4x4 mazes (Modulo) | 6x6 mazes (Modulo) | calls / maze |", "|---|---:|---:|---:|---:|---:|---:|"]
|
| 185 |
+
md += [f"| {r['agent']} | {r['n']} | {pct(r['oneshot'])} | **{pct(r['modulo'])}** | {pct(r['modulo_4'])} | "
|
| 186 |
+
f"{pct(r['modulo_6'])} | {r['calls']:.2f} |" for r in mz]
|
| 187 |
+
md += [""]
|
| 188 |
+
ref = OUT / "published/reference_numbers.json"
|
| 189 |
+
if ref.exists():
|
| 190 |
+
summary["published"] = json.loads(ref.read_text())
|
| 191 |
(OUT / "LEADERBOARD.md").write_text("\n".join(md))
|
| 192 |
(OUT / "leaderboard.json").write_text(json.dumps(summary, indent=1, default=float))
|
| 193 |
print("\n".join(md))
|
scripts/so101_generate.py
CHANGED
|
@@ -11,18 +11,22 @@ from pathlib import Path
|
|
| 11 |
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 12 |
from PIL import Image # noqa: E402
|
| 13 |
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
|
| 17 |
def main(n=110):
|
| 18 |
-
out = Path("data/
|
| 19 |
out.mkdir(parents=True, exist_ok=True)
|
| 20 |
meta = out / "episodes.jsonl"
|
| 21 |
done = set()
|
| 22 |
if meta.exists():
|
| 23 |
done = {json.loads(line)["seed"] for line in open(meta)}
|
| 24 |
with meta.open("a") as f:
|
| 25 |
-
for split, base in (("hist", 1000), ("eval", 2000)):
|
| 26 |
for i in range(n):
|
| 27 |
seed = base + i
|
| 28 |
if seed in done:
|
|
|
|
| 11 |
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 12 |
from PIL import Image # noqa: E402
|
| 13 |
|
| 14 |
+
ROBOT = sys.argv[1] if len(sys.argv) > 1 else "so101" # so101 | panda
|
| 15 |
+
if ROBOT == "panda":
|
| 16 |
+
from robotics.sim.panda_env import CAMERAS, rollout # noqa: E402
|
| 17 |
+
else:
|
| 18 |
+
from robotics.sim.so101_env import CAMERAS, rollout # noqa: E402
|
| 19 |
|
| 20 |
|
| 21 |
def main(n=110):
|
| 22 |
+
out = Path(f"data/{ROBOT}")
|
| 23 |
out.mkdir(parents=True, exist_ok=True)
|
| 24 |
meta = out / "episodes.jsonl"
|
| 25 |
done = set()
|
| 26 |
if meta.exists():
|
| 27 |
done = {json.loads(line)["seed"] for line in open(meta)}
|
| 28 |
with meta.open("a") as f:
|
| 29 |
+
for split, base in (("hist", 1000 if ROBOT == "so101" else 5000), ("eval", 2000 if ROBOT == "so101" else 6000)):
|
| 30 |
for i in range(n):
|
| 31 |
seed = base + i
|
| 32 |
if seed in done:
|
scripts/so101_score_views.py
CHANGED
|
@@ -14,8 +14,12 @@ from robotics.sim.so101_env import CAMERAS # noqa: E402
|
|
| 14 |
from robotics.vlm.cosmos_reason import CosmosVerifier # noqa: E402
|
| 15 |
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
Path(out).parent.mkdir(parents=True, exist_ok=True)
|
| 20 |
done = set()
|
| 21 |
if Path(out).exists():
|
|
@@ -27,7 +31,7 @@ def main(out="results/so101/vlm_scores.jsonl"):
|
|
| 27 |
if (e["seed"], c) in done:
|
| 28 |
continue
|
| 29 |
t = time.perf_counter()
|
| 30 |
-
p = v.score(Image.open(f"data/
|
| 31 |
f.write(json.dumps({"seed": 100 if e["split"] == "hist" else 200, "scene": e["seed"], "camera": c,
|
| 32 |
"task": e["task"], "kind": e["mode"], "family": e["family"], "gt": e["success"],
|
| 33 |
"p": round(p, 5), "latency_s": round(time.perf_counter() - t, 3)}) + "\n")
|
|
|
|
| 14 |
from robotics.vlm.cosmos_reason import CosmosVerifier # noqa: E402
|
| 15 |
|
| 16 |
|
| 17 |
+
ROBOT = sys.argv[1] if len(sys.argv) > 1 else "so101" # so101 | panda
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def main():
|
| 21 |
+
out = f"results/{ROBOT}/vlm_scores.jsonl"
|
| 22 |
+
eps = [json.loads(line) for line in open(f"data/{ROBOT}/episodes.jsonl")]
|
| 23 |
Path(out).parent.mkdir(parents=True, exist_ok=True)
|
| 24 |
done = set()
|
| 25 |
if Path(out).exists():
|
|
|
|
| 31 |
if (e["seed"], c) in done:
|
| 32 |
continue
|
| 33 |
t = time.perf_counter()
|
| 34 |
+
p = v.score(Image.open(f"data/{ROBOT}/{e['split']}/{e['seed']}/{c}.png").convert("RGB"), e["task"])
|
| 35 |
f.write(json.dumps({"seed": 100 if e["split"] == "hist" else 200, "scene": e["seed"], "camera": c,
|
| 36 |
"task": e["task"], "kind": e["mode"], "family": e["family"], "gt": e["success"],
|
| 37 |
"p": round(p, 5), "latency_s": round(time.perf_counter() - t, 3)}) + "\n")
|
scripts/train_racenet.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Train RACE-Net on synthetic swarms only (CPU). No benchmark data is touched.
|
| 3 |
+
|
| 4 |
+
python scripts/train_racenet.py [--steps 6000] [--threads 4]
|
| 5 |
+
Writes models/racenet/{model.safetensors, config.json, training_log.json}.
|
| 6 |
+
Validation = fresh synthetic swarms (fixed seed), reported next to an online RACE-S baseline on the same windows.
|
| 7 |
+
"""
|
| 8 |
+
import argparse
|
| 9 |
+
import json
|
| 10 |
+
import sys
|
| 11 |
+
import time
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
import numpy as np
|
| 15 |
+
import torch
|
| 16 |
+
|
| 17 |
+
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
|
| 18 |
+
from robotics.swarm import racenet # noqa: E402
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def synthetic_val(net, n_batches=30, seed=10_000):
|
| 22 |
+
rng = np.random.default_rng(seed)
|
| 23 |
+
acc, n = 0.0, 0
|
| 24 |
+
net.eval()
|
| 25 |
+
with torch.inference_mode():
|
| 26 |
+
for _ in range(n_batches):
|
| 27 |
+
z, y = racenet.sample_batch(rng, B=16)
|
| 28 |
+
pred = net(torch.from_numpy(z)).numpy() > 0
|
| 29 |
+
acc += float((pred == (y > 0.5)).mean())
|
| 30 |
+
n += 1
|
| 31 |
+
net.train()
|
| 32 |
+
return acc / n
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def main():
|
| 36 |
+
ap = argparse.ArgumentParser()
|
| 37 |
+
ap.add_argument("--steps", type=int, default=6000)
|
| 38 |
+
ap.add_argument("--batch", type=int, default=24)
|
| 39 |
+
ap.add_argument("--lr", type=float, default=2e-3)
|
| 40 |
+
ap.add_argument("--threads", type=int, default=4)
|
| 41 |
+
ap.add_argument("--seed", type=int, default=0)
|
| 42 |
+
ap.add_argument("--out", default="models/racenet")
|
| 43 |
+
a = ap.parse_args()
|
| 44 |
+
torch.set_num_threads(a.threads)
|
| 45 |
+
torch.manual_seed(a.seed)
|
| 46 |
+
rng = np.random.default_rng(a.seed)
|
| 47 |
+
net = racenet.RaceNet(**racenet.CONFIG)
|
| 48 |
+
n_params = sum(p.numel() for p in net.parameters())
|
| 49 |
+
opt = torch.optim.AdamW(net.parameters(), lr=a.lr, weight_decay=0.01)
|
| 50 |
+
sched = torch.optim.lr_scheduler.OneCycleLR(opt, max_lr=a.lr, total_steps=a.steps, pct_start=0.05)
|
| 51 |
+
log, t0, run = [], time.time(), 0.0
|
| 52 |
+
for step in range(1, a.steps + 1):
|
| 53 |
+
z, y = racenet.sample_batch(rng, B=a.batch)
|
| 54 |
+
loss = torch.nn.functional.binary_cross_entropy_with_logits(net(torch.from_numpy(z)), torch.from_numpy(y))
|
| 55 |
+
opt.zero_grad()
|
| 56 |
+
loss.backward()
|
| 57 |
+
torch.nn.utils.clip_grad_norm_(net.parameters(), 1.0)
|
| 58 |
+
opt.step()
|
| 59 |
+
sched.step()
|
| 60 |
+
run = 0.98 * run + 0.02 * loss.item() if step > 1 else loss.item()
|
| 61 |
+
if step % 500 == 0 or step == a.steps:
|
| 62 |
+
val = synthetic_val(net)
|
| 63 |
+
log.append({"step": step, "train_bce": round(run, 4), "val_acc_synthetic": round(val, 4),
|
| 64 |
+
"minutes": round((time.time() - t0) / 60, 1)})
|
| 65 |
+
print(log[-1], flush=True)
|
| 66 |
+
out = Path(a.out)
|
| 67 |
+
out.mkdir(parents=True, exist_ok=True)
|
| 68 |
+
from safetensors.torch import save_file
|
| 69 |
+
save_file(net.state_dict(), str(out / "model.safetensors"))
|
| 70 |
+
(out / "config.json").write_text(json.dumps({**racenet.CONFIG, "n_params": n_params, "architecture": "RaceNet (axial set transformer)",
|
| 71 |
+
"input": "rank-Gaussianized swarm reports [T episodes, J agents], receiver first",
|
| 72 |
+
"output": "log-odds of success per episode",
|
| 73 |
+
"training": {"data": "synthetic swarms only (robotics.swarm.racenet.sample_batch)",
|
| 74 |
+
"steps": a.steps, "batch": a.batch, "lr": a.lr, "seed": a.seed}}, indent=1))
|
| 75 |
+
(out / "training_log.json").write_text(json.dumps(log, indent=1))
|
| 76 |
+
print("saved", out, "params", n_params)
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
if __name__ == "__main__":
|
| 80 |
+
main()
|