Skip to content

nav: CoPH's plant, potential, command and allocation (C2; G2, G3, G11) - #1228

Merged
transfix merged 6 commits into
masterfrom
nav/coph-c2
Nov 16, 2026
Merged

transfix merged 6 commits into
masterfrom
nav/coph-c2

Conversation

@transfix

@transfix transfix commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

C2 of docs/roadmap/NAV-COPH-ROADMAP.md: CoPH's plant, potential, command and allocation in C++, the twin of GRL-SNAM's grl_snam.coph.model and grl_snam.coph.allocation. They are checked against GRL-SNAM's golden cases G2, G3 and G11 (CVC-Lab/GRL-SNAM#170).

C1 landed first as #1210 (squash 5b5b3bf). Master is merged in (1975173), so this diff is C2's alone. The merge's conflicts (the roadmap, coph_golden.json, both CMakeLists.txt) each take C2's side, which already held C1's lines.

What lands

  • inc/cvc/nav/coph_model.h (coph_model.cpp, built with -ffp-contract=off):
    • coph_flow, coph_balance. The exact held-force flow and its energy balance, in the Python's order.
    • coph_exp, coph_expm1. Correctly rounded: evaluated in double-double, rounded once, using only IEEE operations, so they give the same bits on every platform. The plant needs them (below).
    • coph_risk, coph_potential<T>, coph_grad_potential<T>.
      • The gradient is analytic, replacing autograd.
      • Both shapings: legacy, and progress (coph_shaping_parameters computes alpha and its bound once per stage; coph_shaping_for picks by shaping_mode).
      • The barrier covers disks and slabs.
      • The templates are instantiated in coph_model.cpp, so they compile under its flags. Only double here; C3 adds its duals.
    • coph_command<T>. −∇V − 1.4 v, scaled to the limit; it returns the applied force and the proposed one.
    • coph_energy. Per agent:
      • the work, heat, kinetic change and residual, summed step by step;
      • the shaping jumps;
      • the unallocated work, e · Δq.
  • inc/cvc/nav/coph_allocation.h. coph_allocate, §3.3.2's Ackermann allocation, which C5 will use. The speed floor is 0.5 m/s, as GRL-SNAM's SPEED_FLOOR.
  • src/cvc/tests/data/coph_golden.json. Now GRL-SNAM main's (blob b96cc0c1), which adds G2, G3 and G11 to C1's G1 and G4.
  • nav_coph_model_test. New; see Checks.
  • The roadmap:
    • §3.3.2: the speed floor;
    • §3.4: the tiered golden;
    • §4.1, §4.2 and §5: what landed, G3's scenes, atol.

Decisions in it

  • Correctly rounded expm1, not std::expm1. At small damping the closed forms are ill-conditioned:

    • dt − I cancels to about d dt²/2;
    • the heat sums terms of size |u|²/d.

    One ULP of expm1 moves q_after by about 1e-8 at d = 1e-8, a thousand times the tier; a test pins that. torch's expm1 is correctly rounded at all of G2's arguments; MSVC's CRT misses at most of them. §4.2 said std::expm1, and now says this.

  • No Wendland term. The demos never set Stage.local_residual, so the local residual is outside the profile (D7).

  • The potential's transcendentals are cvc::algo::det's, which give the same bits on every platform. log1p is built on det::log (Goldberg's form).

  • coph_energy's plant_ledger items come with C5, which attaches CoPH to a vehicle (D11). This PR has only the account.

Checks

  • Local, Windows (MSVC 19.44, Release, this worktree's own build): nav_coph_model_test passes all 10 tests.
    • G2: bit for bit in all 320 values.
    • G3: 290 of 450 values bit for bit; the worst is 2.2e-4 of the tier's allowance.
    • G11: 373 of 420 bit for bit; the worst is 8.9e-4.
    • coph_exp and coph_expm1: bit for bit against mpmath at 198 arguments, G2's 71 among them, plus the special values.
    • The analytic gradient matches central differences of V on all five scenes, in both modes.
    • The energy account closes over 2,000 steps: the summed residual is 2e-16 against 3.8 of work.
  • C1's nav_coph_test: passes its 12 tests on the new golden.
  • clang-format 18 (from cvcpkg): clean.
  • CI on ea10ccc (before the last master merge): all 27 checks passed, Linux, macOS (arm64, where the build would contract into FMAs without -ffp-contract=off) and Windows among them. CI re-runs on 1975173; the merged tree also passes both test binaries locally.

C1 of docs/roadmap/NAV-COPH-ROADMAP.md: the C++ twin of GRL-SNAM's
grl_snam.coph (CoPH-Stagewise, vendored at c1f1ff3), up to the stage ledger.

inc/cvc/nav/coph_config.h:
- coph_config and coph_communication_config: every field of Config and
  CommunicationConfig, with Python's defaults; modes are strings, as in
  Python. validate() is __post_init__: the same refusals with the same
  messages, in the same order, and it fills replay_update_cap the same way.
  Python's min() is mirrored, so NaN scales pass where upstream's do.
- outside_profile() and require_profile(): the mode fields that differ from
  the demos' profile, which the twin refuses (D7). coph_profile() and
  coph_communication_profile() are the demos' configurations.

inc/cvc/nav/coph_ledger.h (built with -ffp-contract=off):
- coph_shape (disk or slab), coph_reading, coph_transition, coph_footprint,
  coph_observation, coph_stage (new_stage, contains) and coph_intersects.
- coph_ledger: the current stage and the previous cfg.previous, with observe,
  advance and set_geometry. The geometry store comes from the navigation
  layer.

The demos' learner is crossing_demo.CrossingLearner, a MazeLearner, and its
rule is not Learner.advance's, which the roadmap first described. It advances
along whichever axis left the inner box, in either direction (y steps are
2.8 m), pools the readings and footprints of every kept stage, and never sets
Stage.anchors, so _field_fit's overlap continuity rows are always empty in
the demos. The ledger implements that rule; the roadmap's §1, §4.1, §4.3 and
G4 now say so.

The golden is written by GRL-SNAM (grl_snam.tools.coph_golden,
CVC-Lab/GRL-SNAM#168) and committed in src/cvc/tests/data, the same blob as
GRL-SNAM's tests/fixtures copy. nav_coph_test reproduces it bit for bit:
- G1: all 74 Config and 5 CommunicationConfig cases (acceptance, Python's
  message, every value, the fields outside the profile, and that the ledger
  refuses those);
- G4: every tick of the 360-tick script under its three configurations:
  each advance and its axis, each new stage's fixed fields, and each kept
  stage's readings, transitions, footprints and obstacles.
C++-only tests cover upstream's NaN behaviour, require_profile's message, a
sensor-less observation and a repeated uid across stages.
The function-local static in coph_profile_modes() is process-wide state, which libcvc does not keep; package-linux's singleton scan refused it.
C2 of docs/roadmap/NAV-COPH-ROADMAP.md: the C++ twin of GRL-SNAM's
grl_snam.coph.model and grl_snam.coph.allocation.

inc/cvc/nav/coph_model.h (coph_model.cpp, built with -ffp-contract=off):
- coph_flow and coph_balance: the exact held-force flow and its energy
  balance, in the Python's order. At small damping the closed forms are
  ill-conditioned (dt - I cancels to about d dt^2 / 2; the heat sums terms
  of size |u|^2 / d), and one ULP of expm1 moves q_after by about 1e-8. So
  the plant uses coph_exp and coph_expm1, correctly rounded (double-double,
  rounded once), not std::expm1, which MSVC's CRT misses at most of G2's
  arguments.
- coph_risk, coph_potential and coph_grad_potential (analytic, replacing
  autograd), legacy and progress shaping, the barrier over disks and slabs;
  coph_shaping_parameters and coph_shaping_for (alpha and its bound, once per
  stage); coph_command (-grad V - 1.4 v, scaled to the limit, applied and
  proposed). Templated on the scalar and instantiated in coph_model.cpp
  (double here; C3 adds its duals). No Wendland term: the demos never set
  Stage.local_residual (D7). Transcendentals are cvc::algo::det's.
- coph_energy: work, heat, kinetic change and residual summed by step, the
  shaping jumps, and the unallocated work e . dq. Its plant_ledger items come
  with C5, which attaches CoPH to a vehicle (D11).

inc/cvc/nav/coph_allocation.h: coph_allocate, the Ackermann allocation of
§3.3.2 (speed floor 0.5 m/s, as GRL-SNAM's SPEED_FLOOR), which C5 will use.

The golden in src/cvc/tests/data is now GRL-SNAM main's (CVC-Lab/GRL-SNAM#170,
blob b96cc0c), with G2, G3 and G11 beside C1's G1 and G4. nav_coph_model_test
reproduces them at the FLOAT64 tier (rtol 1e-12, atol 1e-12): on Windows, G2
bit for bit in all 320 values, G3 and G11 within 0.1 % of the allowance. It
also checks coph_exp and coph_expm1 bit for bit against mpmath at 198
arguments (G2's 71 among them), the analytic gradient against central
differences, and that the energy account closes over 2,000 steps (summed
residual 2e-16 against 3.8 of work). nav_coph_test passes on the new golden.

The roadmap's §3.3.2 (the speed floor), §3.4 (the tiered golden), §4.1, §4.2
and §5 (G3's scenes, atol) now say what landed.
Conflicts: the roadmap, coph_golden.json and both CMakeLists.txt; each takes C2's side, which already held C1's lines. The diff from master is C2's own.
@transfix
transfix enabled auto-merge (squash) November 15, 2026 20:36
@transfix
transfix merged commit e432d44 into master Nov 16, 2026
30 checks passed
@transfix
transfix deleted the nav/coph-c2 branch November 16, 2026 02:27
transfix added a commit that referenced this pull request Nov 16, 2026
- script_engine.cpp: #1283 factors the sliced form's process lookup into calling_process,
  which run_as_program_work (a client's WebAssembly guest, run as its client's program) shares.
  The lookup keeps this branch's group: the calling process is on the group whose pump runs the
  call (an isolated document's), else on group 0.
- STATE_EXEC_THREADED.md: notes that run_as_program_work shares the lookup.
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