Repository navigation
nav: per-step energy books, the explicit-Euler alarm, and context work at the tick - #832
Merged
Merged
Conversation
…k at the tick 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
enabled auto-merge (squash)
October 27, 2026 01:20
transfix
added a commit
that referenced
this pull request
Oct 27, 2026
The project version and the cvcpkg recipe family move to 3.7.1. The recipes that carried 3.7.0-lineage revisions (libcvc, cvcgl, libcvc-examples-web, pycvc-gl-cp312) restart at cvc_revision 1, since a version bump restarts it. 3.7.1 carries dyn_bike's port-Hamiltonian form and per-step energy books (#831), the navigator's per-step energy identity and context work (#832), and the dynamic single-track plant for plant_host (#833).
This was referenced Oct 28, 2026
transfix
added a commit
to CVC-Lab/GRL-SNAM
that referenced
this pull request
Oct 28, 2026
…he sharp check (#139) The torch twin of libcvc's per-step energy books for the navigator's point-mass surrogate (the white paper's Eq. 38; transfix/libcvc#832), held to libcvc's nav_energy_books_golden.json (transfix/libcvc#849). - nav_potential.book_step (StepBooks) and energy_residual_bound: libcvc's book_step, with the cheap bound and, given vHv, the sharp check r_hat_E. - nav_potential.material_energy: U and the material surrogate's conservative force in any dtype, libcvc's detail::material_energy<double>. - integrate_surrogate_material: energy={"books": True} (or "sharp": True) also fills kinetic, w_damp, w_port, w_clamp, w_cross, residual, bound (and residual_sharp), float64 and detached, booked from the rollout's state in float64 as libcvc does. The rollout's outputs are unchanged. tests/test_nav_energy_books_parity.py: book_step and the bound bit for bit on libcvc's arguments (DOUBLE tier); the clamped surr_step rollout's books to 2e-5 of the step's bound (measured 1.1e-6), and the material surrogate's to 1e-5 (measured 8.3e-8) (FLOAT tier); the unlogged port raises the alarm at every step, as in libcvc; r_E is second order, and the sharp check meets r_E on a quadratic potential.
transfix
added a commit
that referenced
this pull request
Oct 28, 2026
…av (#857) nav_sim_world_set_capture_drive_telemetry and nav_sim_world_drive_telemetry read sim_world::drive_telemetry_data from Python. The second returns the last captured tick as a dict of (N,) arrays named as drive_telemetry's fields, with the books only a world fills (#832): potential_end, projection_work and context_work. It returns None while capture is off. The dict is built by one helper (pycvc_telemetry::to_dict), which nav_drive_step_material_cuda's telemetry now uses too. That dict gains the three keys, which the bare drive step leaves zero; test_pycvc_nav_cuda checks both. test_pycvc_nav_telemetry.py (ctest pycvc_nav_telemetry) is NavPotential.SimWorldBooksTheContextWorkOfAGoalChange through Python. It checks: - capture changes no pose; - context_work is zero on the first captured tick, and projection_work is zero without an override or min_gap; - context_work equals potential minus last tick's potential_end, bit for bit; - the two retargeted agents book -3.353 of context work, against +0.007 without the goal change. Locally (MSVC, Python 3.11) it passes 23 checks, and the nav routes and belief scripts pass unchanged. sim_world.h: drive_telemetry_data() returns the defaults, not null, from turning capture on until the first captured step; its comment now says so.
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.
The DBG white paper's navigator energy ledger (Eq. 38, the explicit-Euler alarm, and context work at tick boundaries; companion Part V §3.3) was specified but not built. #747 evaluates U_nav along every rollout, but nothing booked a step's energy or checked it. This adds the books, their two checks, and context work in the live drive.
The per-step books
For one semi-implicit step of a point mass,
v' = v + dt/m (-g - γv + F),vt = clamp_vmax(v'),x' = x + dt vt, withg = ∇U(x):W_γ = dt/2 γ v·(v+v'),W_port = dt/2 F·(v+v'),W_clamp = m/2(|v'|²-|vt|²),W_× = dt g·(vt-v');r_E = ΔH + W_γ + W_clamp - W_port - W_×, which is exactlydt²/2 [vtᵀH̄vt - g·(g+γv-F)/m].Two checks:
|r_E| ≤ κ_H dt²/2 [|g|(|g|+γ|v|+|F|)/m + L̂|vt|²], withL̂the secant Lipschitz estimate andκ_H = 2. It catches work of order dt left out of the books: an unlogged force, a stale field, an unbooked clamp.r̂_E = dt²/2 [vtᵀ∇²U(x)vt - g·(g+γv-F)/m], with|r_E - r̂_E| = O(dt³). The Hessian-vector product is a central difference of the force along vt (two extra force evaluations, only when asked for).Where it lives:
rollout_energy(material.h) gains optional per-step arrays:kinetic,w_damp,w_port,w_clamp,w_cross,residual,residual_sharpandbound, plus asharpflag.integrate_surrogate_materialfills them. It has no speed clamp, so W_clamp and W_× are zero there.detail::material_energy<double>).r_E - r̂_Eis O(dt³), about 1e-8 at dt = 0.0025, which is below float round-off on U (about 1e-6). So the books leave out the rollout's own float rounding, which is O(eps) a step.integrate_bicycle_materialandintegrate_dynamic_materialthrowstd::invalid_argumentif asked for the books, because they are not point masses.book_step()books any such step from its quantities, andenergy_residual_bound()is the cheap bound from norms.ipc_b_pw,sdf_barrier_b,ipc_dbdd_pw,sdf_barrier_dbandpatch_sample_channelbecome*_t<T>templates. The float functions are their float instantiations, op for op. Outputs, the byte-identity tests andnav_potential_golden.jsonare unchanged.Explicit Euler and the cheap bound. The cheap bound cannot see explicit Euler. Its per-step residual,
dt²/2(|g|² + vᵀH̄v)on a goal spring, is second order like the bound itself, and is about half of it. The sharp check does see it: the explicit step sitsdt² g·(g+γv-F)/moffr̂_E, while a semi-implicit step on a quadratic potential meetsr̂_Eexactly. SoExplicitEulerRaisesTheAlarmasserts the sharp check.Context work in sim_world
While drive-telemetry capture is on (
set_capture_drive_telemetry),sim_world::stepfills three newdrive_telemetryfields. They are zero from thedrive_step*entry points and on the CUDA drive. All three usedrive_potentialwith the tick's coefficients and carrot.potential_end: U where the tick ends, after the drive,override_commandandmin_gap.projection_work: U's change acrossoverride_commandandmin_gap, measured from where the drive (or the plant) left the agent.context_work: this tick'spotential, at substep 0 in the new context, minus U at the same pose with last tick's context (coefficients, carrot, field, material planes).step()begins, before the sense and the field rebuild.potential - last potential_endunless the agent was moved, or the scene edited, between ticks.To make both evaluations use the same vehicle, the existing vehicle-params block moves into a private
sim_world::drive_vehicle()unchanged. With capture off nothing else runs, so outputs are byte-identical (checked).Tests (
nav_potential_test, 10 → 16)SurrogateEnergyIdentityPerStep: the material fixture, one step from a moving start, with damping and a port, at dt 0.02 / 0.01 / 0.005 / 0.0025.ClampWorkClosesTheBooks:diff::surr_stepwith vmax cutting v' to a third. Every step closes within the bound once W_× is booked, and all 213 fail it without W_×. |r_E - r̂_E|/bound is at most 0.037.UnloggedForceRaisesTheAlarm: on the surrogate with a port, every step closes with F_ext booked. With it left out (r_E + W_port), 229 of 240 steps fail the bound.ExplicitEulerRaisesTheAlarm:integrate_surrogate_v2on circular orbits of a goal spring, for one period.SimWorldBooksTheContextWorkOfAGoalChange: a goal changed between two ticks.context_work == potential - last potential_endbit for bit,projection_workis 0, and capture-on positions are byte-identical to capture-off. The retargeted agents book -1.63 and -3.27; the others book the same value as in the run without the change.SimWorldBooksTheMinGapPushAsProjectionWork: the pushed pair books +0.18 and +0.59, and the others book exactly 0.MaterialRolloutsAreByteIdenticalWithTheRecordalso covers the books with the sharp check on, and the vehicles' refusal.Verified locally on Windows (MSVC 14.44, Release, cvcpkg prefix), before the rebase onto 4cd69ad (master's two new commits touch volume, LBIE and app.h only):
nav_potential_test16/16,nav_test62/62 (its drive-telemetry capture test is the byte-identity check),nav_sim_world_test3/3,nav_material_test33/33,nav_material_rollout_grad_test2/2,nav_material_bike_rollout_test12/12,nav_material_ext_test11/11,nav_geom_rollout_grad_test15/15,nav_terrain_test10/10, plusnav_coef_train_test,nav_drive_refinements_testandnav_stats_test.Notes:
sim_world.cppinset_terrainand the binding; this touchesstep().drive.cuonly gains the three zero assignments, and the templatedCVC_MR_HD/CVC_NP_HDprimitives keep their float callers' signatures.