Skip to content

swarm: collect base NavStats on the vectorized fast path (PR3, first slice) - #84

Merged
transfix merged 1 commit into
mainfrom
feat/swarm-base-navstats
Sep 22, 2026
Merged

transfix merged 1 commit into
mainfrom
feat/swarm-base-navstats

Conversation

@transfix

Copy link
Copy Markdown
Contributor

The base navigation stats were collected only on the pure-Python SdfNavigator path; the vectorized Swarm returned raw columns and aggregated nothing (design §1c). This makes the Swarm collect per-vehicle base NavStats each episode and reduce to an EpisodeStats via the scorecard we already landed — reusing metrics.NavStats.update + scorecard.from_nav_stats verbatim, with zero change to the drive/physics.

What

  • Swarm(collect_stats=False, contact_radius_m=0.0) — opt-in, default-off, so the render / thousands-of-agents hot path and every existing parity test stay byte-identical (verified: test_swarm_matches_serial_navigators_to_float32 unchanged).
  • _collect_step() — the batched twin of SdfNavigator._metrics, folded once per tick after the drive and before parking (arriving tick counts once). Re-samples phi post-rollout at the center (clearance_m=(phi-rr)/S, inside_building=phi<0) — not the rollout's discarded footprint minclr — for exact parity, and converts every metre field via n2w / /S (closing the normalized-vs-metres trap the C++ /sc seam hit).
  • episode_stats() — reduces the per-agent NavStats to an EpisodeStats via from_nav_stats, sourcing straights_m/arrival_times_s/veh_contacts/min_sep_m from the run.

Tests (18 passed locally, torch 2.12 via the cvcpkg .venv)

  • Exact parity vs N serial SdfNavigators (float32 tier, the same drift band the position-parity test accepts) — the collector is a faithful vectorization of _metrics.
  • The episode_stats → aggregate_nav corpus reduction.
  • The default-off inert invariant (no _sc_* state, drive path byte-identical, episode_stats raises).
  • Pairwise contacts / min-sep.

Reviewed adversarially across three lenses (parity correctness, test validity, safety/edge-cases); the collector logic was confirmed correct and the test-robustness findings (boundary-tick gating, path-ratio aggregate, penetration ±2) are folded in.

Deferred (design DEFERRALS — not this PR)

Native sim_world path (needs a libcvc-side collector), retiring the squad_record/fog_record manifests, wiring into the eval/training loop, the grl-snam-dbg harness.py recompute removal, and fully-vectorized accumulation for large N. Separately, a known parity gap (out of scope): Python NavStats.update drops the first path segment while the C++ collector includes it — reconcile in a follow-up.

…slice)

The base navigation stats were collected only on the pure-Python SdfNavigator path;
the vectorized Swarm returned raw columns and aggregated nothing (design §1c). Make the
Swarm collect per-vehicle base NavStats each episode and reduce to an EpisodeStats via
the scorecard we already landed — reusing metrics.NavStats.update +
scorecard.from_nav_stats verbatim, with ZERO change to the drive/physics.

- Swarm(collect_stats=False, contact_radius_m=0.0): both opt-in and default-off, so the
  render / thousands-of-agents hot path and every existing parity test stay
  byte-identical (verified: test_swarm_matches_serial_navigators_to_float32 unchanged).
- _collect_step(): the batched twin of SdfNavigator._metrics, folded once per tick after
  the drive and before parking (so the arriving tick counts once). Re-samples phi
  post-rollout at the CENTER (clearance_m=(phi-rr)/S, inside_building=phi<0) — NOT the
  rollout's discarded footprint minclr — for exact parity, and converts every metre field
  via n2w / /S (closing the normalized-vs-metres trap the C++ /sc seam hit).
- episode_stats(): reduces the per-agent NavStats to an EpisodeStats via from_nav_stats,
  sourcing straights_m/arrival_times_s/veh_contacts/min_sep_m (the fields NavStats does
  not carry) from the run.
- tests: exact parity vs N serial SdfNavigators (float32 tier), the episode_stats ->
  scorecard reduction, the default-off inert invariant, and pairwise contacts/min-sep.
  18 passed locally (torch 2.12 via the cvcpkg .venv).

Deferred (design DEFERRALS): the native sim_world path (needs a libcvc-side collector),
retiring the squad_record/fog_record manifests, wiring into the eval/training loop,
grl_snam_dbg harness.py recompute removal, and fully-vectorized accumulation for large N.
A separate known parity gap (out of scope): the Python NavStats.update drops the first
path segment while the C++ collector includes it — reconcile in a follow-up.
@transfix
transfix merged commit 1e1046a into main Sep 22, 2026
3 checks passed
@transfix
transfix deleted the feat/swarm-base-navstats branch September 22, 2026 17:53
transfix added a commit that referenced this pull request Sep 22, 2026
…umer (#87)

The base nav_stats collectors (Swarm #84, native #86) and the scorecard (#82) had no
production consumer — the corpus aggregation was demonstrated only in tests. Add a
scorecard eval CLI that runs a CoefMLP checkpoint over a scene corpus with the Swarm's
base collector and aggregates one NavScorecard: the RF-free fitness row grl-snam uses to
rank its own base-policy checkpoints (design §7, PR5 training bridge).

- grl_snam/tools/scorecard_eval.py: load_model (a grl-snam train .pt or the bias net) +
  scene_specs (city corpus) + evaluate(scenes/agents/steps/grid/contact_r) ->
  Swarm(collect_stats=True) per scene -> episode_stats() -> aggregate_nav -> NavScorecard.
  Prints a compact row + the full JSON (the record a campaign ranks on), optional --json.
  Convention matches the other `python -m grl_snam.tools.X` tools (coef_eval/coef_train).
- tests/test_scorecard_eval.py: a tiny corpus reduces to a well-formed, in-range card;
  seeds give distinct corpora; the default (no checkpoint) is the bias net. 3 pass, and
  the CLI runs end-to-end locally (torch 2.12 via the cvcpkg .venv).

The scorecard field-mirrors the C++ nav_scorecard + the native collector, so a checkpoint
scores identically whichever path evaluates it. Follow-up (optional): register as a
`grl-snam scorecard-eval` Click subcommand; a --native flag to score via NativeSimWorld.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant