Repository navigation
nav: an external-force port in the differentiable rollout, step and trajectory - #728
Merged
Merged
Conversation
…ed ext_force's twin) diff::ext_in carries a per-agent force for one step (fx, fy in the drive frame, an optional position Jacobian, and whether it steers) into bike_control, bike_step, bike_step_bwd, bike_control_bwd, dyn_bike_step and dyn_bike_step_bwd. It joins the barrier and goal forces in the longitudinal command and, when it steers, the steering bias, exactly as rollout_impl adds ext_force; the behind branch's barrier term stays barrier-only. The reverse returns dL/dF_ext and, given J, adds J^T dL/dF_ext into the position gradient. A null ext_in is the controller as it was. For cvcdbg's comm-network trainer; signatures agreed with the DBG session. DiffExtForce: a zero force is the controller without it, forward and backward; one step matches the deployed bicycle_rollout_ext exactly (worst 0.0, with and without steering); dL/dF_ext against central differences 9.4e-4 (kinematic) and 5.7e-5 (dynamic), and through a position-dependent force 1.6e-2.
…verse (ext_rollout.h) diff::bike_rollout_ext / bike_rollout_ext_bwd (inc/cvc/nav/ext_rollout.h), and the dynamic twin dyn_rollout_ext / dyn_rollout_ext_bwd: one agent's trajectory with per-step goals and coefficients (exogenous), a force sampled by callback at the step's pose every `hold` steps and held between, and a tape of every step's state, force and Jacobian. The reverse takes dL/dstate at every step and returns dL/dF_ext at every step, dL/dcoef (optional) and dL/d(initial state); a hold window's dL/dF goes through J at the step where F was sampled. A null callback is the plain rollout. Interface agreed with cvcdbg's DBG session for its comm-network trainer. DiffExtRollout: the trajectory is the steps with their held forces, bit for bit; the reverse against central differences over 10 steps, hold 1 / 3: kinematic dL/dinit 1.8e-3 / 1.7e-3, dL/dF 3.6e-3 / 4.8e-3, dL/dbeta 1.6e-2 / 9.7e-3; dynamic dL/dinit 1.5e-2 / 1.4e-2, dL/dF 1.1e-3 / 8.3e-4. Documented in NAV_TRAINING.md. 362/362 nav/physics/plant ctest cases outside the heavy suites.
bike_rollout_ext and its reverse on six fixed agents (12 steps, per-step goals and coefficients, an affine force each, hold 1 or 3, one that does not steer) with the field they sample, written to tests/data/ext_rollout_golden.json (CVC_EXT_ROLLOUT_GOLDEN_WRITE=1). GRL-SNAM's twin replays it in float64 and holds this float reverse to autograd; this build reproduces the file to 1e-4.
…ard library's draws #728's macOS Debug recipe failed DiffExtForce.GradientsMatchFiniteDifferences (0.148 through a position-dependent force) and DiffExtRollout.ReverseMatchesFiniteDifferences (dL/dF 0.38 at hold 1), which pass on MSVC and libstdc++. The scene's starts come from sample_starts_goals' uniform_int_distribution, so libc++ checks other cases, and an unfiltered sum over cases is only as good as its worst one. - ext_cases jitters the starts off the SDF's grid nodes (the bilinear field's kinks). - fd_sum takes each case's loss as a function of the offset and skips and counts a case whose difference measures no slope: forward and backward differences apart (a controller switch), or central differences at eps and eps / 2 apart (a slope peaked within the step: near a steep barrier 24.9 at 1e-3 against the reverse's 31.2, 31.3 at 1e-4). At most a quarter may skip. - dL/dbeta at one step is differenced at 1e-2: its effect is small enough that float noise was a fair share of the 1e-3 difference. - CVC_EXT_CASE_SEED replaces the draws: swept over 100 seeds, none fails; before, 2 of 40 did with jitter alone. Docs: the measured table updated, and the method described.
The comments and docs describe ext_force as a hook for a caller's own force, without naming a downstream user.
# Conflicts: # docs/NAV_TRAINING.md # inc/cvc/nav/detail/diff_rollout.h # src/cvc/tests/nav_dyn_bike_test.cpp
transfix
added a commit
that referenced
this pull request
Oct 24, 2026
transfix
added a commit
that referenced
this pull request
Oct 24, 2026
…dyn4_rollout_ext) (#780) * nav: an external-force port on the four-wheel plant (dyn4_bike_step, dyn4_rollout_ext) P8d's open item. The four-wheel vehicle (diff::dyn4_plant) takes the external force as the bicycle and P8a's dyn_bike_step do since #728: - dyn4_bike_step / dyn4_bike_step_bwd take an optional ext_in (the force joined to the controller's, steering or not) and return dL/dF_ext, adding J^T dL/dF_ext to the position's gradient; null is the step as it was. - ext_rollout.h: dyn4_rollout_ext<G> / dyn4_rollout_ext_bwd<G>, the trajectory on a ground sampler, with a force sampled every `hold` steps and held between (dyn4_tape). nav_dyn_4w_test: a zero force is the step bit for bit; one step's dL/dF (8.6e-5) and the position's gradient through J (3.6e-4) against central differences; the trajectory is its steps, a null sampler the plain rollout, and its reverse against central differences for hold 1 and 3, cases on a controller switch skipped and counted (fd_acc); none of CVC_EXT_CASE_SEED 1..100 fails. Dyn4ExtRollout.Golden writes tests/data/dyn4_ext_rollout_golden.json for GRL-SNAM's torch twin. * nav_dyn_4w_test: the four-wheel force port's golden as the test writes it (not reformatted) * docs: the external-force port is done on every plant (#728, #780); P8c is next
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 external-force port in the differentiable rollout: the deployed drive's
ext_force, differentiated, so a trainer can learn through a force a caller supplies. It is the roadmap's P8 item before P8d (Joe, 2026-10-19: "start the ext-force port"; "ext-force port before P8c is fine, P8c after P8d").One step:
diff::ext_in(inc/cvc/nav/detail/diff_rollout.h)fx, fy(the force at this step's pose, in the normalized drive frame), an optional position JacobianJ = dF_ext/do, andsteer.bike_control,bike_step,bike_step_bwd,bike_control_bwd,dyn_bike_stepanddyn_bike_step_bwd. Each takesconst ext_in *ext = nullptr; the reverses takefloat *g_fexttoo.rollout_impl: the force joins the barrier and goal forces in the longitudinal command, and the repulsive force in the steering bias when it steers. The behind branch's barrier term stays barrier-only.ext_inis the controller as it was. Every existing caller is unchanged.A trajectory:
inc/cvc/nav/ext_rollout.hdiff::bike_rollout_ext/bike_rollout_ext_bwd, and the dynamic twindyn_rollout_ext/dyn_rollout_ext_bwd.holdsteps, held between.hold = 1is the deployed drive's per-substep force;hold > 1is a harness's per-frame force.Tests (
nav_dyn_bike_test:DiffExtForce,DiffExtRollout)bicycle_rollout_ext, 64 agents, with and without steeringLocally: 362/362 nav/physics/plant ctest cases outside the heavy suites, plus the new tests. Documented in
docs/NAV_TRAINING.md("An external force in the differentiable rollout").Not in this PR