Repository navigation
nav: the material trainer on the kinematic bicycle (P8b, first item) - #642
Merged
Merged
Conversation
The material trainer (CoefEnergyNetMaterial) only ever differentiated a point
mass. This adds a rollout that keeps its force law but drives the deployed
kinematic bicycle, so training sees the vehicle it deploys on.
- The force law kept from the trainer: per-obstacle IPC barriers on the discs,
the goal spring, damping, and the soft/hard material forces from the
6-channel patch.
- integrate_bicycle_material: drive.cpp's bicycle_rollout_material controller,
one substep per step:
- pure pursuit with the (F_rep + F_mat) steering bias;
- the corner, stop, creep and reverse governors;
- d_cap and the kinematic update.
The governor reads the nearest disc's clearance and normal, the role the SDF
sample plays in the deployed drive.
- integrate_bicycle_material_vjp: a hand-written adjoint over a per-step
record of every intermediate and every branch taken. Gradient flows through
the taken branch, as autograd treats min/max/where.
- material_loss_config::integrator (surrogate | bicycle; default unchanged)
and bicycle_material_params, in the batch's length units, with validate().
material_batch gains an optional th0/sp0 (default: speed |v0| along v0).
L_vel compares sp * (cos th, sin th). L_multi stays a point-mass geometry
rollout. The bicycle runs on the CPU even with use_cuda (no device twin
yet).
- pycvc:
- nav_material_trainer_set_bicycle / nav_material_trainer_integrator on
the trainer handle;
- nav_integrate_bicycle_material and its _vjp, for a torch twin's
forward and gradient parity.
Tests:
- nav_material_bike_rollout_test:
- kink-aware finite-difference gradchecks of the adjoint: 33 coefficients,
worst 0.4%; and 33 with 2 skipped where the nudge straddled a controller
discontinuity, worst 1.2%;
- 1 vs 8 threads bit-identical;
- drives to its goal within its speed range;
- keeps clear of an obstacle in the way;
- the soft material force cuts collected risk.
- nav_material_train_test: the full loss -> weights gradcheck through the
bicycle (dir_rel 7e-4, worst 0.6%, 64 weights).
- nav_material_optim_test and test_pycvc_nav_train.py: Adam descends through
the bicycle.
Measured: gradients through the bicycle are sparse. A saturated acceleration
limit, steering tanh or speed limit passes none, so the fixture's gradient
norm is 2.8 against 242 on the point mass, and its loss falls 5% against 74%
over 70 steps. The P8a design should take that into account.
This was referenced Oct 17, 2026
With material_integrator::bicycle, the multi-start robustness term now rolls its short rollouts out on the bicycle instead of the point mass. - multi_start_penalty_bicycle (material.h) uses the same starts and the same softplus(-min_clear / tau) score, with each agent keeping its heading and speed. As before it is geometry only (lam = 0), and its gradient comes from integrate_bicycle_material_vjp. - The start construction moves out of multi_start_penalty into multi_start_origins (geom_rollout.h), unchanged. nav_geom_rollout_grad_test, with its Python goldens, still passes. - Test: MultiStartPenaltyGradcheck: three sampled starts, 9 coefficients checked, worst 4e-4, 1 skipped at a controller discontinuity. The full loss -> weights gradcheck through the bicycle, now including this term, passes.
transfix
added a commit
to CVC-Lab/GRL-SNAM
that referenced
this pull request
Oct 17, 2026
…cvc; trainer on the bicycle (#118) libcvc P8b moves the material trainer off the point mass: integrate_bicycle_material keeps the surrogate's force law and drives the deployed kinematic bicycle (transfix/libcvc#642). - grl_snam/material_bike.py: integrate_bicycle_material in torch, the same controller with every branch a torch.where. Autograd follows the branch each step took, as the C++ adjoint does. Guarded sqrt/norm keep an unselected zero from producing NaN gradients. - nav_native: integrate_bicycle_material / _vjp wrappers over the new pycvc entry points, gated by HAS_BICYCLE_MATERIAL_ROLLOUT. - MaterialTrainer(bicycle=BicycleParams(...)) takes the loss through the bicycle, gated by HAS_MATERIAL_TRAINER_BICYCLE; .integrator reports which. The module still imports without torch. - tests/test_material_bike_parity.py: - forward (rtol 1e-4) and gradient (rtol 1e-3) parity against libcvc; - a pure-torch check that the twin drives to its goal. Measured against a local libcvc build: forward within 5e-7 relative, gradient within 3e-6, so two independent derivations agree. - tests/test_material_train_native.py: the trainer descends on the bicycle, and a zero wheelbase is refused. The native tests skip until a pycvc with the bindings is installed.
transfix
added a commit
that referenced
this pull request
Oct 17, 2026
Minor release. It carries: - the world clock: lockstep and batch, followers, the sim.* binding, and nav on the clock (#629, #630, #631, #640); - the units registry with SI <-> normalized-frame conversions (#632); - cvc::physics with the Jolt backend (#641); - the material trainer on the kinematic bicycle and its pycvc bindings (#642). Bumps project(VERSION) 3.5.1 -> 3.6.0 and every cvcpkg recipe's upstream_version to match. cvc_revision stays 1, per the recipe-version gate.
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 first step of moving training off the point mass (vehicle-physics roadmap P8b). The material trainer (CoefEnergyNetMaterial) differentiated only
integrate_surrogate_material, a point mass. This adds a rollout with the same force law, driven through the deployed kinematic bicycle.What
integrate_bicycle_material(src/cvc/nav/material_bike_rollout.cpp)drive.cpp'sbicycle_rollout_material, one substep per step, indrive.cpp's op order:a = (F·heading − γ·sp)/mass, clamped;k_steer·tanh((F_rep + F_mat)·left)steering bias;d_capand the kinematic update.integrate_bicycle_material_vjpTrainer
material_loss_config::integratorissurrogate(the default, so nothing changes) orbicycle, withbicycle_material_paramsin the batch's length units andvalidate().material_batchgains optionalth0/sp0; by default the bicycle starts at speed |v0| along v0.L_velcomparessp·(cos θ, sin θ).L_multistays a point-mass geometry rollout.use_cuda; it has no device twin yet.pycvc
nav_material_trainer_set_bicycle/nav_material_trainer_integratoron the trainer handle, so GRL-SNAM campaigns can switch.nav_integrate_bicycle_materialand_vjp, for a torch twin's forward and gradient parity.Verification (Windows, MSVC 2022, local cvcpkg prefix)
nav_material_bike_rollout_test, 6/6:nav_material_train_test: the full loss → weights gradcheck through the bicycle passes (dir_rel 7e-4, worst 0.6%, 64 weights). The existing gradchecks are unchanged.nav_material_optim_testandtest_pycvc_nav_train.pyshow Adam reducing the loss through the bicycle.Measured, and worth knowing for P8a
Gradients through the bicycle are sparse. A saturated acceleration limit, steering tanh or speed limit passes no gradient, as autograd would. On the shared fixture:
That matches
coef_train's note that the bicycle holds the basin rather than beating it. Learning rate and force scales matter more here. The dynamic model (P8a) may want smooth or straight-through clamps in training.Not in this PR: the GRL-SNAM torch twin and parity test (next, using the new bindings), and a CUDA twin.