Repository navigation
scorecard: collect discrete per-material nav-stats buckets (C++ parity) - #90
Merged
Merged
Conversation
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
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.
This was referenced Sep 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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) mirroringcvc::navveh_nav_stats, but nothing ever populated it in Python —NavStatsnever read material,from_nav_statsnever set the buckets, and no collector supplied a material id. Somaterial_time_sharewas structurally always[0.0]*13and "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 stepdtinto time and the step segment into dist), with a hand-computed parity test mirroringnav_stats_test.cpp.What changed
grl_snam/material_palette.py— the single shared 13-class palette (positional withcvc::nav::kNumMaterials+cvc::dbgMATERIAL_TABLE),RISK_MATERIAL_IDS, andterrain_risk_share(). Terrain-risk time is derived from the parity buckets, deliberately kept OUT of the scorecard schema soNavScorecardstays field-for-field with C++.NavStatsgainstime_over_material_s+dist_over_material_m;update(m, dt=None)accumulates bym.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=)andSdfNavigator.material_idssample the id each step;from_nav_statsthreads both buckets intoVehStats(dist too, matching C++veh_nav_stats).scorecard_evalattaches a per-scene raster by default (material=Falseopts out) and printsrisk-time%.Verified
risk-time%=16.0with material,0.0without, and arrival/path_ratio bit-identical either way (drive provably unaffected by the stats-only material).tests/test_material_buckets.py: hand-computed buckets (thenav_stats_test.cpptime/dist contract), the id sampler + coordinate chain, the corpus builder, theSwarmpath, 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_riskloss term + the measurement study; PR3 the scorecard-driven curriculum; a cross-repo PR wires the nativesim_worldpath + a C++/Python parity gate.