Skip to content

nav: evaluate U_nav along the rollouts, and gradcheck F = -grad U at every call site - #747

Merged
transfix merged 4 commits into
masterfrom
feat/nav-potential-eval
Oct 21, 2026
Merged

transfix merged 4 commits into
masterfrom
feat/nav-potential-eval

Conversation

@transfix

@transfix transfix commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

The navigator's forces are written as closed-form derivatives of an energy that was never computed. This evaluates it as a number along every rollout and checks, at every call site, that the conservative force is its negative gradient (the first rung of the port-Hamiltonian ladder):

U_nav = beta/2 |o - g|^2 + sum_j alpha_j b_IPC(d_j) + lam_soft r~ + lam_hard b_sp(phi)
        (+ the terrain's grade cost and slope barrier)

The coefficients are held fixed. Damping is dissipation and the external force is a port, so neither is part of U.

What changes

Nothing that runs today changes: every new output is optional and write-only.

  • detail/nav_potential.h: potential_terms and the barrier potentials, each the one whose derivative its force primitive returns:
    • ipc_b: diff::ipc_ / drive.cpp's ipc_dbdd, continued linearly below the 1e-6 floor;
    • ipc_b_pw: ipc_dbdd_pw, continued with slope -200 below the clamp's knee;
    • sdf_barrier_b: the softplus hazard barrier.
  • Outputs:
    • coef_train: diff::surr_potential; coef_trainer::loss_and_grad(..., potential), per step with that step's coefficients; bike_control's optional force out.
    • material rollouts: rollout_energy (potential, terms and force per step), an optional last argument of integrate_surrogate_material, integrate_bicycle_material and integrate_dynamic_material.
    • deployed drive: drive_telemetry gains potential, terms and force_x/force_y at the tick's start pose. sim_world's telemetry capture therefore logs U along kinematic and Jolt runs. drive_potential() evaluates U at any pose.
  • One finding the gradcheck forced into the open. The material and terrain hard forces read grad phi per metre while positions are normalized. Their potential in the drive frame is therefore lam_hard * S * b_sp(phi_m), with S the stack's normalized units per metre. Dropping S makes the check fail by 34-45x.

Measured (nav_potential_test, 10 tests)

  • Barrier potentials: they differentiate to the force primitives across their domain, including the clamp and the floor.
  • Every call site on exact planes. The sites are the coef_train surrogate and bicycle, the three material rollouts, and the drive (plain, material, terrain, footprint, plant arm, all together). At each, the site's own force equals -grad U by central differences. Worst relative residual: 7.9e-4.
  • City scene with planes from material_build. Here the residual is the grid's (stored normals and gradient planes against the bilinear values): p50 1.2e-4, p90 3.4e-4, max 8.7e-3 over 483 poses (145 inside the barrier).
  • Byte-identical: every rollout and the drive (plain, plant arm) match with and without the record, bit for bit.
  • Point-mass material surrogate. KE + U falls by the damping's work, with an O(dt) error: 1.4e-2, 8.2e-3 and 4.3e-3 at dt 0.02, 0.01 and 0.005.
  • Golden: NavPotential.Golden pins tests/data/nav_potential_golden.json for the torch twin, nav_potential: U_nav evaluated, the torch twin of libcvc's, held to its golden CVC-Lab/GRL-SNAM#133 (the barrier sweep, U along a material rollout, drive_potential with and without a footprint).

Locally (Linux, Jolt 5.6.0 from cvcpkg): nav_potential_test 10/10, and every nav/physics ctest case passes (408/408).

CI note (macOS arm64)

  • nav_potential_test: its material checks compare the U a rollout logs with the same inline evaluator called in the test, bit for bit. The first macOS run failed by a few ULPs, because clang contracted the test file's copy into FMAs while the material rollouts build with -ffp-contract=off.
    • 529ed98 builds the test with the same flag. The rollouts themselves were byte-identical with and without the record on macOS too.
  • NavMaterialExt.ACallbackGivingThePatchIsThePatch (dynamic case) also failed there, and not because of this PR.

…every call site

The navigator's forces are written as closed-form derivatives of an energy that was never
computed. This evaluates it (doc 20's rung 1):

  U_nav = beta/2 |o - g|^2 + sum_j alpha_j b_IPC(d_j) + lam_soft r~ + lam_hard b_sp(phi)
          (+ the terrain's grade cost and slope barrier)

with the coefficients held fixed. Damping is dissipation and the external force a port, so
neither is part of U.

- detail/nav_potential.h: potential_terms and the barrier potentials, each the one whose
  derivative its force primitive returns: ipc_b (diff::ipc_, drive.cpp's ipc_dbdd, continued
  linearly below the 1e-6 floor), ipc_b_pw (ipc_dbdd_pw, continued with slope -200 below the
  clamp's knee) and sdf_barrier_b (the softplus hazard barrier).
- Exposed without changing any output:
  - diff::surr_potential; coef_trainer::loss_and_grad's optional `potential` (per step, with
    the step's coefficients); bike_control's optional `force` out.
  - material.h rollout_energy (potential, terms, force per step), an optional last argument
    of integrate_surrogate_material, integrate_bicycle_material and
    integrate_dynamic_material.
  - drive_telemetry gains potential, terms and force_x/force_y at the tick's start pose, and
    drive_potential() evaluates U at any pose. The material and terrain hard forces read
    grad phi per metre in the normalized frame, so their potential is lam_hard S b_sp(phi).
- nav_potential_test (10): the barrier potentials differentiate to the force primitives; at
  every call site (coef_train surrogate and bicycle, the three material rollouts, the drive
  plain / material / terrain / footprint / plant arm) the site's own force is -grad U by
  central differences on exact planes (worst 7.9e-4 relative); on the city scene with built
  material planes the grid's residual is p50 1.2e-4, max 8.7e-3; every rollout is
  byte-identical with and without the record; on the point mass KE + U falls by the damping's
  work with an O(dt) error (1.4e-2, 8.2e-3, 4.3e-3 at dt 0.02, 0.01, 0.005); and
  NavPotential.Golden pins tests/data/nav_potential_golden.json for the torch twin.
…rollouts are

Its material checks compare the U a rollout logged with the same inline evaluator called in the
test, bit for bit. The rollouts' TUs are built without FMA contraction; on aarch64 clang
contracted the test's copy, and the last bits differed (macOS CI).
@transfix
transfix enabled auto-merge (squash) October 21, 2026 18:41
@transfix
transfix merged commit 7d47b98 into master Oct 21, 2026
24 checks passed
transfix added a commit that referenced this pull request Oct 27, 2026
…k at the tick (#832)

The white paper's navigator energy ledger (Eq. 38) was specified but not
built: the rollouts evaluate U_nav (#747), but nothing booked a step's energy
or checked it.

- rollout_energy gains per-step books for the point-mass material surrogate:
  kinetic energy, damping work, port work, clamp loss, clamp cross term, the
  residual r_E, its cheap bound (every step) and the sharp check r_hat_E (two
  extra force evaluations a step, when asked). They are the books of the step
  taken from the rollout's state, evaluated in double, so they resolve
  r_E - r_hat_E = O(dt^3), which is below float round-off on U. The bicycle
  and dynamic rollouts throw when asked for them.
- book_step() books any semi-implicit point-mass step from its quantities;
  energy_residual_bound() is the cheap bound with the secant Lipschitz
  estimate and kappa_H = 2.
- The barrier potentials and force primitives become *_t<T> templates; the
  float functions are their float instantiations, op for op.
  detail::material_energy<T> evaluates U and the force the surrogate applies.
- sim_world fills three new drive_telemetry fields while it captures:
  potential_end, projection_work (override_command and min_gap) and
  context_work (this tick's U at its start pose minus U at the same pose with
  last tick's context, evaluated before the sense and the field rebuild). The
  vehicle-params block moves unchanged into sim_world::drive_vehicle() so both
  evaluations read the same vehicle. The drive leaves the three fields zero.

nav_potential_test, 10 -> 16 tests: as dt halves 0.02 -> 0.0025 the measured
order of r_E is 1.99/2.00/2.00 and of r_E - r_hat_E 2.99/2.94/2.93. The cheap
bound catches an unlogged force and an unbooked clamp cross term; explicit
Euler passes it (its residual is second order too) and fails the sharp check.
@transfix
transfix deleted the feat/nav-potential-eval branch October 29, 2026 20:52
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