Repository navigation
coph_golden: the C2 cases (G2 plant, G3 potential and command, G11 allocation) - #170
Merged
Merged
Conversation
…location) The golden libcvc's C++ twin reproduces gains the three FLOAT64 cases C2 needs: - G2: model.flow and model.balance over 40 (x, u, d, dt), d from 1e-8 to 10 and the profile's damping bounds. - G3: model.potential, its gradient and model.command at 25 points on five scenes (the crossing's doors, doors with disks, a hazard bump, disks alone, a fresh stage), each under legacy and progress shaping, both sides of the force limit and of progress's alpha clip. - G11: the new grl_snam.coph.allocation (NAV-COPH-ROADMAP 3.3.2, the Ackermann allocation T4 and C5 share) over 60 cases, at rest, in reverse and at the steer lock among them. Each has a rules text, and the test rebuilds every output from the file's inputs and that text in plain Python. G1, G4 and every input stay exact; the FLOAT64 outputs are compared at their tier (rtol 1e-12, atol 1e-12) when another platform regenerates the file.
transfix
added a commit
to transfix/libcvc
that referenced
this pull request
Nov 16, 2026
#1228) 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.
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.
This adds the golden cases libcvc's C2 needs (
docs/roadmap/NAV-COPH-ROADMAP.md§5): G2, G3 and G11. It extendspython -m grl_snam.tools.coph_goldenfrom CoPH T5 (#168), and addsgrl_snam.coph.allocation, which G11 pins.What lands
G2, the plant (
plant):model.flowandmodel.balanceover 40(x, u, d, dt)cases. That is 10 dampings, each under 4(x, u, dt):dfrom 1e-8 to 10, including the profile's bounds (0.15, 1.5), its initial 0.6 and the demos' world's 0.85;dtof 0.12 (the profile), 0.6 (the Humvee step, §3.3.1), 0.05 and 1.G3, the potential and command (
potential):model.potential, its gradient (torch autograd) andmodel.commandat 25 points on five scenes. Each point is evaluated under legacy shaping (Learner.actand replay callcommandwithoutcfg) and progress shaping (the profile's routed controller), so 50 cases. The scenes are:crossing: the two door slabs;crossing_with_disks: doors and disks, which takessurface_distance's path;hazard: a risk bump and no obstacles;disks: disks only, which takes the disk branch, as the cars' obstacles (§3.3.3) will;fresh_alpha_1: a fresh stage with the box (0, 2), where alpha is 1.The forces fall on both sides of the limit in both modes, and alpha is both clipped and 1. The barrier is active at 10 or more points. No point sits where V is not smooth: a slab's segment ends or core, or a disk's centre.
G11, the allocation (
allocation): 60 cases, 10 speeds by 6 forces, over three cars (a RoboRacer, a Humvee, and a RoboRacer with a lower lock and clip). Among them:grl_snam/coph/allocation.py(new, GRL-SNAM code, listed inVENDORED.md). It is §3.3.2 as written, and returns the acceleration, the steer,kappa*,u_usedand the unallocated forcee. Its conventions are those ofsim_world::override_command: the steer is the bicycle angle (rad, + left), and the acceleration is along the heading.Each section carries a rules text (
plant_rules,potential_rules,allocation_rules), as G4 carriesstage_rules. G1 and G4 are unchanged.The test
rtol1e-12,atol1e-12. On the platform that wrote the fixture, it is still byte for byte. A new test checks that 2-ulp nudges pass and that real changes, to an output or an input, fail.coph_grad_potentialwill take.ddown to 1e-8, both sides of each clip, both modes per point).tests/test_coph_allocation.py. This checks what the allocation means:e= 0);ebooks the rest.Findings for C2
expm1is not correctly rounded. At smalld, the vendored closed forms are ill-conditioned:dt − Icancels to aboutd dt²/2, andheatsums terms of size|u|²/d. Soq_after,heatandresidualhold to the tier only with a correctly roundedexpm1. torch'sexpm1is correctly rounded at all 40 G2 arguments, and a test pins that. The Windows CRT's (CPython'smath.expm1, and MSVC'sstd::expm1) is not correctly rounded at most of them. C2 needs its own correctly roundedexpm1at small arguments, notstd::expm1as §4.2 says. The plant replay here uses mpmath's.balancelosesheatat tiny damping. Atd= 1e-8,heatcomes out exactly 0.0, against a true value near 6e-8, and the residual is about 1e-7. The golden pins the vendored result. This never arises in the profile, where the damping stays in [0.15, 1.5].Stage.local_residual:receiver_localization_modestays'global'. So the compact-feature term that §4.2 lists is outside the demos' profile (D7).v_flooris new. §3.3.2 leavesv_minopen.allocation.SPEED_FLOORis 0.5 m/s, and G11 varies it (0.25, 0.5, 1).libcvc's copy of the golden (transfix/libcvc#1210, C1) is the G1/G4 file. C2 copies this one when it lands.
Checks
tests/test_coph_golden.pyandtests/test_coph_allocation.pypass, 26 tests.