#!/usr/bin/env python3 """RACE-Net-M scaling study: swarm sizes and map sizes it was never trained on. The model was trained on 6 robots in 12x12-cell mazes. Here it runs, unchanged, on 4 robots in 8x8 mazes, on 8 and 10 robots, and on 16x16 mazes, with half of the robots lying. Mazes use seeds 2000+ (not used anywhere else). Writes results/racenet_m/scaling.json. """ import json import sys from multiprocessing import Pool from pathlib import Path import numpy as np sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src")) from robotics.bench import trackD # noqa: E402 CONFIGS = (("4 robots · 8×8", 4, 8), ("6 robots · 12×12 (training size)", 6, 12), ("10 robots · 12×12", 10, 12), ("8 robots · 16×16", 8, 16)) METHODS = ("solo", "majority", "wmsr_trim", "reputation", "race_map", "race_net_m", "race_net_m" + trackD.MV, "REF oracle") ATTACKS = ("invert", "false_walls", "random", "sleeper", "collude") MAZES = 10 def _job(args): seed, attack, F, method, n, w = args r = trackD.episode(seed, attack, F, method, n=n, w=w, h=w) return r["spl"], r["success"] def main(): out = {"mazes": MAZES, "attacks": list(ATTACKS), "liar_fraction": 0.5, "configs": []} with Pool(4) as pool: for label, n, w in CONFIGS: jobs = [(2000 + s, a, n // 2, m, n, w) for m in METHODS for a in ATTACKS for s in range(MAZES)] res = np.array(pool.map(_job, jobs, chunksize=4)).reshape(len(METHODS), len(ATTACKS) * MAZES, 2) row = {"label": label, "robots": n, "cells": w, "liars": n // 2, "spl": {m: float(res[k, :, 0].mean()) for k, m in enumerate(METHODS)}, "se": {m: float(res[k, :, 0].std() / np.sqrt(res.shape[1])) for k, m in enumerate(METHODS)}, "success": {m: float(res[k, :, 1].mean()) for k, m in enumerate(METHODS)}} out["configs"].append(row) print(label, {m: round(100 * v, 1) for m, v in row["spl"].items()}, flush=True) Path("results/racenet_m/scaling.json").write_text(json.dumps(out, indent=1)) if __name__ == "__main__": main()