Skip to content

scorecard: collect discrete per-material nav-stats buckets (C++ parity) - #90

Merged
transfix merged 2 commits into
mainfrom
feat/nav-material-buckets
Sep 23, 2026
Merged

transfix merged 2 commits into
mainfrom
feat/nav-material-buckets

Conversation

@transfix

Copy link
Copy Markdown
Contributor

PR1 of the terrain-risk training program. Closes the material-stats gap: the scorecard reserved a 13-class material dimension (time_over_material_s / material_time_share) mirroring cvc::nav veh_nav_stats, but nothing ever populated it in Python — NavStats never read material, from_nav_stats never set the buckets, and no collector supplied a material id. So material_time_share was structurally always [0.0]*13 and "how often the rollout spends time in terrain-risk areas" had no answer.

This wires the discrete buckets end-to-end, matching the C++ design (nav_stats.cpp:153-157: the id at the current pose takes the step dt into time and the step segment into dist), with a hand-computed parity test mirroring nav_stats_test.cpp.

What changed

  • grl_snam/material_palette.py — the single shared 13-class palette (positional with cvc::nav::kNumMaterials + cvc::dbg MATERIAL_TABLE), RISK_MATERIAL_IDS, and terrain_risk_share(). Terrain-risk time is derived from the parity buckets, deliberately kept OUT of the scorecard schema so NavScorecard stays field-for-field with C++.
  • NavStats gains time_over_material_s + dist_over_material_m; update(m, dt=None) accumulates by m.material_id. Default id -1 ⇒ byte-identical (no bucket moves).
  • MaterialIdRaster — a nearest-cell per-agent id sampler, the twin of C++ nav_samplers.material_id(x,y). Stats-only: decoupled from the drive's material force, so attaching it changes telemetry only, never navigation. city_material_ids() builds a corpus raster (buildings→concrete, free→open_air, deterministic terrain-risk disks).
  • Swarm(..., material_ids=) and SdfNavigator.material_ids sample the id each step; from_nav_stats threads both buckets into VehStats (dist too, matching C++ veh_nav_stats).
  • scorecard_eval attaches a per-scene raster by default (material=False opts out) and prints risk-time%.

Verified

  • E2E: risk-time%=16.0 with material, 0.0 without, and arrival/path_ratio bit-identical either way (drive provably unaffected by the stats-only material).
  • tests/test_material_buckets.py: hand-computed buckets (the nav_stats_test.cpp time/dist contract), the id sampler + coordinate chain, the corpus builder, the Swarm path, and the byte-identical no-material default. Full suite (331 tests) collects; scorecard/swarm/nav/material parity suites green locally.

Next in the program: PR2 adds the steering lever (a risk-lookahead feature) + an opt-in w_risk loss term + the measurement study; PR3 the scorecard-driven curriculum; a cross-repo PR wires the native sim_world path + a C++/Python parity gate.

The scorecard reserved a 13-class material dimension (time_over_material_s /
material_time_share) mirroring cvc::nav veh_nav_stats, but nothing ever filled it
in Python: NavStats never read material, from_nav_stats never set the buckets, and
no collector supplied a material id — so material_time_share was structurally always
zero and "time in terrain-risk areas" had no answer. This wires the discrete buckets
end-to-end, matching the C++ design (nav_stats.cpp: id at the current pose takes the
step dt into time and the step segment into dist).

- grl_snam/material_palette.py: the single shared 13-class palette (positional with
  cvc::nav kNumMaterials + cvc::dbg MATERIAL_TABLE), RISK_MATERIAL_IDS, and
  terrain_risk_share() — "time in terrain-risk areas" derived from the parity buckets
  (kept OUT of the scorecard schema so it stays field-for-field with C++).
- NavStats gains time_over_material_s + dist_over_material_m; update(m, dt=None)
  accumulates by m.material_id. Default id -1 => byte-identical (no bucket moves).
- MaterialIdRaster: a nearest-cell per-agent id sampler, the twin of C++
  nav_samplers.material_id(x,y). STATS-ONLY — decoupled from the drive's material
  force, so attaching it changes telemetry only, never navigation. city_material_ids()
  builds a corpus raster with deterministic terrain-risk disks.
- Swarm(..., material_ids=) and SdfNavigator.material_ids sample the id each step;
  from_nav_stats threads both buckets into VehStats (dist too, matching C++).
- scorecard_eval attaches a per-scene raster by default (material=False opts out) and
  prints risk-time%. Verified: risk-time%=16 with material, 0 without, and
  arrival/path_ratio bit-identical either way (drive unaffected).
- tests/test_material_buckets.py: hand-computed buckets (nav_stats_test.cpp contract),
  the id sampler + coordinate chain, the corpus builder, the Swarm path, and the
  byte-identical no-material default.
Two review-driven guards (no feature change): a same-scene/specs/seed run with vs
without a MaterialIdRaster asserts byte-identical per-vehicle trajectories while the
buckets differ (proving the stats-only invariant at the drive level), and an
end-to-end scorecard_eval guard asserts the corpus actually surfaces non-zero
terrain-risk time (against the silent-no-op failure mode).
@transfix
transfix merged commit 753d4ea into main Sep 23, 2026
3 checks passed
@transfix
transfix deleted the feat/nav-material-buckets branch September 23, 2026 05:17
transfix added a commit that referenced this pull request Sep 23, 2026
…#91)

* coef_train: terrain-risk steering lever + opt-in w_risk exposure loss

Make the policy learn to spend less time in terrain-risk areas — the "act on the
signal" half of the material nav-stats work (buckets landed in #90). Three pieces,
all default-off so a plain call is byte-identical to the geometry-only trainer:

- sdf_nav.coef_feats(material=): appends the WORST terrain risk between the vehicle
  and its carrot (the terrain twin of the mu-probe, MAX not MIN), differentiable
  through the trajectory. add_risk_feature(model) widens a trained net to see it,
  output-identical at init (the widen-basin trick, like widen_coef_mlp for grip);
  CoefMLP grows use_mu/use_risk flags to disambiguate a 6-in net's optional column.
- train_bicycle(material=, w_risk=, lam_soft=, lam_hard=): the material reroute force
  (F_soft = -lam_soft*grad risk) steers around risk, and a w_risk*Sum(risk) term
  penalizes dwelling in it (reported as the 3rd last_loss_terms summand). Only the
  bicycle rollout can learn this; a risk net without material= is rejected.
- material.city_material_grid(): a matched (MaterialGrid, MaterialIdRaster) pair so the
  differentiable risk force/feature/loss and the reported buckets see the SAME terrain.
- CLI: --w-risk/--lam-soft/--lam-hard/--risk-lookahead + --grid. A risk .cvcnav is a
  torch research artifact (the C++ coef_feats has no risk column yet) — the CLI warns,
  and --score skips widened nets (the Swarm drive is base-5-feature).

Smoke measurement (grid 64, 40 steps, lam_soft 0.4, 2 seeds): w_risk=8 cuts terrain-risk
exposure ~24% (0.108->0.082) with reach unhurt (0.166->0.172) on both seeds — a Pareto
improvement, and evidence the additive feature + fixed reroute already work (a learned
lam head is an enhancement, not a prerequisite). Full 3-seed study documented as follow-up.

tests/test_risk_lever.py pins the feature append + byte-identical default, MAX-ahead +
differentiability, add_risk_feature identity/flags/stacking, the w_risk loss wiring, and
the risk-needs-material guard. Updated two train_bicycle tests for the new error message
and the 3-tuple last_loss_terms.

* review: ship a reproducible risk-exposure eval + harden the max-ahead test + temper the smoke claim

Three review-driven improvements (no behavior change to the lever):
- eval_risk_exposure(model): the direct bicycle-rollout harness behind the smoke table,
  so the numbers are one-command reproducible and a widened net has a real eval path
  (feeds the risk column automatically; Swarm/scorecard_eval stay base-5-feature).
- test_risk_feature_is_max_ahead: was fwd>=here (a tautology since the probe set includes
  o); now a hand-built clear-underfoot / risky-ahead scene asserts fwd > here strictly, so
  a degenerate lookahead (reach=0 / o-only) fails it. Adds an eval_risk_exposure smoke test.
- docs: temper 'reach not hurt / Pareto improvement' to 'exposure down, reach not measurably
  changed' (the +0.006 reach delta is within 2-seed noise) and point at eval_risk_exposure.
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