Skip to content

Torch twin of libcvc's per-step energy books: book_step, the bound, the sharp check - #139

Merged
transfix merged 1 commit into
mainfrom
feat/nav-energy-books-twin
Oct 28, 2026
Merged

transfix merged 1 commit into
mainfrom
feat/nav-energy-books-twin

Conversation

@transfix

Copy link
Copy Markdown
Contributor

This is the torch twin of libcvc's per-step energy books for the navigator's point-mass surrogate: the white paper's Eq. 38, from transfix/libcvc#832. It is held to libcvc's new golden, nav_energy_books_golden.json from transfix/libcvc#849.

Changes

  • nav_potential.book_step (with StepBooks) is libcvc's book_step. From one semi-implicit step's states and forces it gives:
    • the books: kinetic energy, dH, w_damp, w_port, w_clamp, w_cross and the residual r_E;
    • the cheap bound (energy_residual_bound, kappa_H 2, using the secant Lipschitz estimate);
    • given vHv, the sharp check r_hat_E.
  • nav_potential.material_energy gives U and the conservative force of the material surrogate in any dtype. It is libcvc's detail::material_energy<double>: the parameters stay float32 until they meet the position, as libcvc takes its floats.
  • material_nav.integrate_surrogate_material gains a books hook. With energy={"books": True}, or "sharp": True for r_hat_E as well, the energy dict also receives kinetic, w_damp, w_port, w_clamp, w_cross, residual, bound and residual_sharp. These are float64 and detached, shaped as libcvc's rollout_energy books, and evaluated in float64 from the rollout's state as libcvc does. Steps past H book zero. Without the keys the rollout is unchanged, and with them its outputs are bit for bit the same (tested).

Parity

tests/test_nav_energy_books_parity.py checks the twin against the golden in two tiers.

DOUBLE: the books' arithmetic, to 1e-12.

  • energy_residual_bound on a sweep: bit for bit.
  • book_step on libcvc's own arguments for a diff::surr_step rollout whose vmax clamp cuts every step: bit for bit.

FLOAT: the rollouts. Each side books its own float32 rollout. Each book is compared relative to the larger of itself and the step's bound, since r_E nearly cancels.

case what gate measured
clamp sdf_rollout with vmax, booked as libcvc books it (U and forces in float32) 2e-5 1.1e-6
sharp the material surrogate, port force on, sharp check, a frozen agent 1e-5 8.3e-8
unlogged the same at dt 0.002 under a strong port force 1e-5 5.7e-8

States, potentials and kinetic energies are held to 5e-5, as the material parity is (measured 2.6e-7).

Besides the values, the tests check:

  • the clamp cuts every step, and with W_clamp and W_cross booked every step closes;
  • with the port booked, every step closes. Left out (r_E + W_port), every step raises the alarm, flag for flag as libcvc;
  • frozen steps book zero;
  • r_E / dt^2 holds its constant per agent as dt halves (within 1% measured, gate 5%);
  • on a quadratic potential the sharp check meets r_E to round-off.

Local run (Windows, torch 2.8 CPU): the full suite passes 552, with 55 skipped. The 6 failures also fail on main on this box: 5 in test_material_raster need imageio, which this environment lacks, and test_material_gate_sim's exact sin(pi/4) differs in the last bit with this host's libm. black and ruff are clean.

Merge order: the fixture is transfix/libcvc#849's file, byte for byte. Merge after #849 lands, or take the fixture from it.

Not in this PR:

  • drive_telemetry's potential_end, projection_work and context_work (#832) are still not readable from Python. pycvc does not bind sim_world's drive telemetry at all, so GRL-SNAM cannot read live context work yet.
  • The whitepaper's "What is not twinned yet" (docs/vehicle-ph-plant.tex §8.3) still lists the point-mass books.

…lden

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
transfix merged commit 136348e into main Oct 28, 2026
4 checks passed
transfix added a commit that referenced this pull request Oct 28, 2026
… tick telemetry (libcvc #857)

- Table 9 (the twins) gains the navigator's point-mass books: book_step,
  energy_residual_bound, material_energy and integrate_surrogate_material's
  books hook, held to libcvc's NavPotential.BooksGolden. book_step on
  libcvc's arguments is held to 1e-12 (double tier); the books are held to
  1e-5 of the step's bound, and 2e-5 on the clamped rollout (float tier).
- 8.3, "What is not twinned yet": the point-mass books are twinned. The tick
  telemetry is a running world's, so it has no twin; libcvc #857 binds it in
  pycvc (nav_sim_world_set_capture_drive_telemetry,
  nav_sim_world_drive_telemetry).
- 8.4 gains "Book the navigator's energy": how to ask for the books, the
  measured parity (1.1e-6 and 8.3e-8 of the bound), and the curved-patch
  caveat. On a patch whose gradient channels are not its values' gradients,
  each step books the force/-grad U gap, which fills 99.65% of the bound at
  h = 0.002. It also says where a live world's context work comes from.
- 10, "Python access", and the equation-to-code map: updated to match.

PDF rebuilt with TeX Live pdflatex, three passes: 28 pages, no warnings.
transfix added a commit that referenced this pull request Oct 28, 2026
… review fixes, links (#140)

* docs(vehicle-ph-plant): reproduce appendix, steering as a modulation, review fixes, links

- Appendix A: the exact setup behind every measured value (libcvc c1f104c0,
  MSVC 19.44, CMake 3.31.7, Ninja 1.12.1, cvcpkg 2.5.6, torch 2.8.0+cpu);
  the Windows commands that were run, with the extra CMake flags and why;
  the Linux/macOS equivalents (not run verbatim here; libcvc's CI runs the
  suites on every platform); each test's printed lines; GRL-SNAM's pytest
  line and its expected 53 passed, 2 skipped.
- Section 6.6 rewritten for the learned plant's steering: the reference
  form books power through steering (13.4% of |y.u| on the golden fit;
  5.6% on a fit to the analytic plant, which books none). The opt-in
  modulated form (transfix/libcvc#851) has D(v, delta) and G(v, delta), with
  the drive alone as the port. A new validation table holds its tests.
- The learned plant's provenance corrected: public CVC-Lab/LieSPHGP has no
  SE(2) vehicle; the port and its golden follow an SE(2) package built on it
  at 65db994. LieSPHGP's own trainers use the EKF ELBO.
- Review fixes:
  - the dynamic plant is 3.7.0 (#714), the learned plant 3.7.1 (#758);
  - psi for the kinematic heading (theta is the grade);
  - a "mixed" parity tier;
  - the sharp check's wording and its 3.5e-5;
  - the health-check range;
  - test totals, the CTest regex and NavPotential.DriveForce*;
  - the GRL-SNAM paper's full title.
- Links from README.md and the guide's "See also".

pdflatex: 26 pages, three passes, no warnings.

* docs(vehicle-ph-plant): the front slip in its wheel's frame (libcvc #852), and the pH twin (#138)

The plant's front slip is now measured in its wheel's frame, as the
four-wheel model's: alpha_w = -atan2(n_w.v, sqrt((t_w.v)^2 + eps^2)), each
rooted at n_w.v = 0 (transfix/libcvc#852). The paper follows:
- Section 3: the directions come first, then the slips in the wheels'
  frames; the old front slip is noted.
- Lemma 1 holds at every steering angle (the secant through w = 0, slope
  P C B u_w / (u_w^2 + w^2) at the root); f_eps is the root branch's
  rounding only.
- Section 4.2 and Proposition 1: R's front term is S_f n_f n_f^T, and the
  vehicle is passive from the drive port alone at every floor.
- Section 4.4: S_f ~ C_f / u_f; the front tire's power is exactly its
  dissipation but for the root branch's rounding.
- Section 4.5: the floor reaches only the slips' forward speeds;
  TheFloorTermIsRoundOff measures at most 2.2e-16 of the flow; the old
  remainder and its eps^2 numbers are kept as history.
- Section 4.7: k_f is the wheel-frame slip's exact sensitivity (eq. kf),
  checked by the new TheTangentIsTheTiresDerivative (1.4e-7).
- Section 5.2: braking limiter -358 J, residual 4e-6.
- Section 10: the four-wheel form now carries the single track's over.
- Tables: the plant table gains the renamed floor test and the tangent
  test, with #852's numbers; the live plant's rows move to their own table
  (the plant table no longer fit a page); the twins table and the GRL-SNAM
  validation rows gain #138's pH twin (test_dyn_bike_ph_parity, 18 passed,
  worst 7.1e-14).
- Section 8.2-8.3, Python access and the equation-to-code map: the pH
  form's parts, rates and books are twinned in GRL-SNAM #138.
- Appendix A: #852's and #138's branch commits, and the printed lines at
  1a0acc77 with the c1f104c0 values they replace.
- Versions: #852.

Built with TeX Live pdflatex, three passes: 27 pages, no warnings.

* docs(vehicle-ph-plant): cite #138's squash commit 2f76ab0

The #138 rows, the reproduction appendix and the versions table now cite main at 2f76ab0, where the dynamic twins' parity tests pass again (57 passed, 6 skipped for pycvc). The PDF is rebuilt: 27 pages, no warnings.

* docs(vehicle-ph-plant): the point-mass books' twin (#139) and pycvc's tick telemetry (libcvc #857)

- Table 9 (the twins) gains the navigator's point-mass books: book_step,
  energy_residual_bound, material_energy and integrate_surrogate_material's
  books hook, held to libcvc's NavPotential.BooksGolden. book_step on
  libcvc's arguments is held to 1e-12 (double tier); the books are held to
  1e-5 of the step's bound, and 2e-5 on the clamped rollout (float tier).
- 8.3, "What is not twinned yet": the point-mass books are twinned. The tick
  telemetry is a running world's, so it has no twin; libcvc #857 binds it in
  pycvc (nav_sim_world_set_capture_drive_telemetry,
  nav_sim_world_drive_telemetry).
- 8.4 gains "Book the navigator's energy": how to ask for the books, the
  measured parity (1.1e-6 and 8.3e-8 of the bound), and the curved-patch
  caveat. On a patch whose gradient channels are not its values' gradients,
  each step books the force/-grad U gap, which fills 99.65% of the bound at
  h = 0.002. It also says where a live world's context work comes from.
- 10, "Python access", and the equation-to-code map: updated to match.

PDF rebuilt with TeX Live pdflatex, three passes: 28 pages, no warnings.
transfix added a commit that referenced this pull request Nov 7, 2026
* release: 0.3.0

95 commits since v0.2.1 (PRs #66 to #158), with new features, so the
pre-1.0 minor version goes up. The main changes:

- Ariadne hosts: GRL-SNAM's demos run as Python hosts of Ariadne documents
  (#147, #149, #153). `grl-snam ariadne cars` runs libcvc's multi-car
  template (#155), and fleet and live take its settings, worlds, plants,
  panels and log (#157). These need pycvc-gl 3.7.12.
- Vehicle plants: capture, the demos, the fog-of-war stories and training
  run on kinematic, dynamic and Jolt plants (#119, #130, #143, #145, #154).
- Torch twins of libcvc, held to its goldens: the material rollout (#118),
  terrain (#120), dyn_bike and dyn4 (#121, #123, #134-#136), the external
  force (#122, #124), the material trainer (#125), belief material
  (#128, #129, #131), U_nav (#133), and the port-Hamiltonian form, its
  energy books, wheel spin and compliant contact (#138, #139, #146).
- The vehicle-plant port-Hamiltonian whitepaper (#137 to #158).
- Training and evaluation: the base scorecard and selection (#82-#98),
  `grl-snam coef-train` (#102), the learned lam head and .cvcnav v2
  (#94, #105), and the 2026-10 audit fixes (#113).
- Data: grl-snam-weights, plus the Austin scene and Humvee as runtime
  dependencies, so `grl-snam demo` runs from a bare install (#72-#77).
- The research core moves under grl_snam/ (#103). The world clock is
  shared with libcvc's (#116, #117).

The version lives in pyproject.toml. The three cvcpkg columns mirror it in
upstream_version and in the package.files dist-info path. cvc_revision goes
back to 1 for the new upstream version. The publish job asks the server for
the next revision in any case.

* material_train_native: pass semi_implicit=False explicitly (libcvc #981)

libcvc #981 (in 3.7.12) changed nav_material_trainer_create's
ms_semi_implicit default from 0 to 1. MaterialTrainer left the L_multi
sampling args out for the legacy single start, so on pycvc-gl 3.7.12
semi_implicit=False quietly ran semi-implicit Euler. #159's CI was the
first run on 3.7.12, and four tests failed on cp311, cp312 and cp313:

- test_sampled_multi_start_args: "semi_implicit did not reach the
  rollout", because the default and semi_implicit=True were now the same
  rollout;
- test_live_native_trainer_agrees[legacy] and [legacy+ext], and
  test_live_native_trainer_agrees_on_the_belief_net[surrogate]: the
  explicit torch trainer and the native one differed by 1.3e-3 to 1.5e-3
  (tolerance 1e-5).

Now a binding that takes the args always gets them, so the integrator is
the one asked for on any pycvc. An older binding still gets the legacy
start through the old signature. GRL-SNAM's default stays explicit Euler.

tests/test_material_train_native_args.py checks both bindings. Its new
case fails without this change.
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