Skip to content

coph_golden: G5-G8, the learner's field fit, damping fit, replay and update (C3, part 1) - #195

Merged
transfix merged 1 commit into
mainfrom
feat/coph-golden-c3
Nov 20, 2026
Merged

transfix merged 1 commit into
mainfrom
feat/coph-golden-c3

Conversation

@transfix

Copy link
Copy Markdown
Contributor

C3, part 1, of libcvc's docs/roadmap/NAV-COPH-ROADMAP.md (§4.3, §5): the generator for G5–G8. grl_snam.tools.coph_golden_learner adds the learner's cases to coph_golden.json, which libcvc's C3 will consume:

  • G5, the field fit;
  • G6, the damping fit;
  • G7, the replay;
  • G8, the update.

The run and its three snapshots

One CrossingLearner (the demos' learner: MazeLearner on TerrainLearner on CooperativeLearner on Learner) runs in the demos' profile and tick order. A script drives it east along the middle row to the door and back. Each case is the update at one tick:

snapshot tick kept stages what it shows
near_the_bump 64 1, 2, 3 accepted; the largest replay gradient (2.9e-3)
door_in_view_rejected 96 2, 3, 4 door in the geometry store and on stage 4; rejected (validation_or_feasibility): the field validation worsens by 0.0092, against a slack of 0.003
back_west_unsupported_entry 112 3, 4, 5 accepted; stage 3's entry unsupported_entry; stage 4's supported_boundary horizon of 18, with a handoff to stage 5 at step 14

Per case, the file holds:

  • The snapshot: everything update reads. The rules text learner_rules lists it, and coph_golden_learner.rebuild turns it back into a learner.
  • G5: each stage's normal equations, weights and covariance.
  • G6: the 8 Newton iterates and the clipped proposal.
  • G7: retained_replay for six policies on the fitted weights and damping. It records the cost and gradient, the plan, the eligibility, the handoffs, every routed control (reason, route, guard steps, applied force) and the paths.
  • G8: the validation numbers and their margins from the slack, the policy step and its attempts, accept or reject with its reason, and what is committed or rolled back.

Same bytes on every OS

  • Inputs. The plant is the exact flow at the world's damping, evaluated in plain Python with exp and expm1 as fixed Taylor sums. The force and the readings use only + - * / and sqrt. After each update the script rounds the committed weights, damping, policy and terrain anchors to multiples of 2^-24.
  • Decisions. Generation checks every update's and every replay's decisions against copies nudged by 1e-12 relative, and fails if any decision changes (--no-check skips this; the file is the same). Observe's BLAS-dot geometry decisions stay more than 1e-9 from their thresholds, as in G4.
  • Comparison. Values under an out key are compared at rtol 1e-9, atol 1e-12. Everything else is compared exactly.

Tests (tests/test_coph_golden.py, 22 pass locally)

  • G5, G6 and G8 are rebuilt from the rules in plain Python. G6 uses the loss's closed-form first and second derivatives.
  • G7's cost is rebuilt from its own trace (states, forces, handoffs, fitted fields). Its gradient at the committed policy matches G8's.
  • Snapshot completeness: the learner rebuilt from each snapshot's inputs alone reproduces G5–G8 when the vendored update runs.
  • Coverage, and another platform's last bits: pass at tier; a decision change fails.

Where the spec met the profile

  • The routed controller is the maze router. The roadmap's §4.3 says the C++ takes "the route field's anchors". In the demos' profile, a replay step actually runs:

    • maze_learning.maze_route: Dijkstra on the crossing's surveyed network, with edge costs from terrain_values over the terrain anchors and closures from the reported geometry;
    • navigation.project with fast=True;
    • the guard, which checks the corridor with maze_geometry.corridor_clear.

    So C3 needs those pieces, and their inputs (the network, the reported geometry, the anchors) are in each snapshot.

  • The design matrix is given as normal equations. With no continuity rows in the profile, the system is block diagonal, so G5 gives each stage's AᵀA + ridge·I and Aᵀy + ridge·w with every row's target, not the rows themselves. That keeps the file small.

  • G8 never halves. The replay barely depends on the policy here (|∂cost/∂π| ≤ 2.9e-3), so every update accepts its first candidate. No case halves, exhausts the budget or is policy-independent.

  • The nonfinite path can't be reached. MazeLearner.update(x) takes no force_invalid.

  • No replay control is projected or braked. Once the door is known the maze route turns the replay away before any constraint binds. I also tried sending the carrot to x = 9.1; nothing changed. A direct case set for navigation.project and the guard would cover them if C3 wants it.

  • G3 is unchanged in the fixture. On Windows, main's own generator now writes one G3 bound 1 ulp off the committed value (within tier), so this PR keeps the committed G3 bits.

Cost

  • Fixture size: 521 KB → 931 KB.
  • Generation time: about 76 s with the decision checks, against 10 s before.
  • Test time: the golden tests take 44 s locally (regeneration without the checks, plus the rebuilds).

Merge is left to Joe. Next: libcvc's C3 (§4.3) consumes this file. It needs the same blob in src/cvc/tests/data.

…update (C3)

grl_snam.tools.coph_golden_learner adds libcvc C3's cases (NAV-COPH-ROADMAP §4.3, §5) to
coph_golden.json, at three update snapshots of a scripted crossing run of the demos' learner
(CrossingLearner):

- G5: Learner._field_fit's normal equations, block by block, its weights and covariance.
- G6: _fit_damping's Newton iterates and update's clipped proposal.
- G7: stage_prediction.retained_replay for 6 policies per snapshot on the fitted weights and
  damping: cost, gradient, the plan, eligibility, handoffs, each routed control and the paths.
- G8: the update's validation numbers and margins, the policy step and its attempts, accept or
  reject and its reason, and what is committed or rolled back.

The run is scripted so its inputs are the same bytes on every OS: the plant is the exact flow in
plain Python, and each update's committed values are rounded to 2^-24. Every update's and
replay's decisions are checked against copies nudged by 1e-12 relative, and observe's
geometry decisions are kept away from their thresholds, as in G4. One update is rejected
(validation_or_feasibility, 0.0062 beyond the slack) and two are accepted.

The tests rebuild G5, G6 and G8 from the rules in plain Python and G7's cost from its trace, and
check that the learner rebuilt from a snapshot's inputs alone reproduces G5-G8. The committed G3
bits are kept: main's own generator now writes one bound 1 ulp off them on Windows, within tier.
@transfix
transfix merged commit 19eb4b1 into main Nov 20, 2026
5 checks passed
transfix added a commit to transfix/libcvc that referenced this pull request Nov 20, 2026
…pdate (C3; G5-G8) (#1386)

C3 of docs/roadmap/NAV-COPH-ROADMAP.md (§4.3): the update of the demos' own learner
(crossing_demo.CrossingLearner) in the profile, in inc/cvc/nav/coph_learner.h.

- coph_field_fit: each kept stage's ridge fit (Cholesky on its 16 x 16 system).
- coph_fit_damping: Newton steps on the plant loss, on hyper-duals (coph_dual.h).
- coph_maze_route and coph_control: the profile's routed controller is MazeLearner's maze
  router on the surveyed corridor network, then the CBF projection and the corridor guard.
- coph_prepare and coph_replay: the supported_boundary plan and budget, and retained_replay;
  on coph_dual2 one pass gives the cost and d cost / d policy.
- coph_update: the fits, the policy step and its halvings, validation, then commit or rollback.

coph_model.cpp gains scalar traits for the duals and instantiates the plant, potential and
command on them. The golden (data/coph_golden.json) is CVC-Lab/GRL-SNAM#195's, with G5-G8
added; G1-G4 and G11 are unchanged. On Windows nav_coph_learner_test matches every decision,
with values within 0.0069 of the tier's allowance (rtol 1e-9, atol 1e-12). nav_coph_test and
nav_coph_model_test still pass. The roadmap's §4.3 records what landed, and corrects its
routed-controller text: the profile never reaches the route field's anchors.
transfix added a commit that referenced this pull request Nov 21, 2026
… (C4) (#201)

grl_snam.tools.coph_golden_packets adds libcvc C4's cases (NAV-COPH-ROADMAP §4.4, §5) to
coph_golden.json, on G5-G8's scripted crossing run:

- G9: CrossingLearner.export at the three snapshots, with both block bootstraps' resample
  indices recorded from the learner's own generators and injected (D8). CooperativeLearner's
  candidate anchors and TerrainLearner's risk-ordered anchors, each with its ensemble and
  covariance; H and V_task; and the packet.
- bytes() is BIT on each export's wire form: the anchors' values and gradients, the covariance,
  H and V_task rounded to 2^-24, so the count is the same on every OS. export 0's JSON text is
  pinned in full, and repr cases pin the float rule.
- G10: a receiver (the last snapshot's learner as agent '1') assimilates 37 packets through
  MazeLearner, TerrainLearner and CooperativeLearner: every reason the three layers give, route
  evidence only, evictions past the received cap of 8. Then its field fit with the received
  packets (the whitened Gauss-Newton step) and its update, which accepts with 8 messages.

As in G4-G8, generation keeps every norm decision more than 1e-9 from its threshold and checks
the receiver's update against nudged copies. The tests rebuild the bootstraps, anchors,
covariances and the Gauss-Newton step from the rules in plain numpy, and the sender and receiver
from the file's inputs. The committed G3 bits are kept, as in #195.
transfix added a commit that referenced this pull request Nov 22, 2026
… part 1) (#202)

* coph_golden: G9-G10, packets, their byte count and their assimilation (C4)

grl_snam.tools.coph_golden_packets adds libcvc C4's cases (NAV-COPH-ROADMAP §4.4, §5) to
coph_golden.json, on G5-G8's scripted crossing run:

- G9: CrossingLearner.export at the three snapshots, with both block bootstraps' resample
  indices recorded from the learner's own generators and injected (D8). CooperativeLearner's
  candidate anchors and TerrainLearner's risk-ordered anchors, each with its ensemble and
  covariance; H and V_task; and the packet.
- bytes() is BIT on each export's wire form: the anchors' values and gradients, the covariance,
  H and V_task rounded to 2^-24, so the count is the same on every OS. export 0's JSON text is
  pinned in full, and repr cases pin the float rule.
- G10: a receiver (the last snapshot's learner as agent '1') assimilates 37 packets through
  MazeLearner, TerrainLearner and CooperativeLearner: every reason the three layers give, route
  evidence only, evictions past the received cap of 8. Then its field fit with the received
  packets (the whitened Gauss-Newton step) and its update, which accepts with 8 messages.

As in G4-G8, generation keeps every norm decision more than 1e-9 from its threshold and checks
the receiver's update against nudged copies. The tests rebuild the bootstraps, anchors,
covariances and the Gauss-Newton step from the rules in plain numpy, and the sender and receiver
from the file's inputs. The committed G3 bits are kept, as in #195.

* coph_golden: G12, an episode of two agents with communication on (C5)

grl_snam.tools.coph_golden_episode adds libcvc C5's case (NAV-COPH-ROADMAP section 4.5, 5) to
coph_golden.json: the demos' runner (staggered_demo.execute, arm reciprocal_fixed) with two
CrossingLearner agents for 60 ticks of the crossing.

- The world is CrossingWorld with a fixed rational sensor-noise pattern in place of numpy's
  draws, so the C++ senses the same readings at its own positions.
- In the episode, agent 1 senses the middle door at tick 33 and turns north. Agent 0 learns of
  it from agent 1's packet at tick 40 and reroutes through the north row. Every update takes the
  other's packet and accepts.
- Decisions are BIT: per tick the stage, version and routed control (reason, route, waypoint,
  guard steps, route change); per update the packets, attempts and verdict; every send and
  delivery; and the geometry events.
- Positions and forces are FLOAT64 at atol 1e-6.
- Each sent packet's bootstrap draws are recorded for the C++ to inject (D8).

Generation checks that no decision changes when the world's damping is nudged by 1e-9 relative
each way; the decisions hold at 1e-6 too. The tests rebuild each agent's positions from its
forces with G2's closed form. The committed G3 bits are kept, as in #195.

* coph_golden: G12 traces each update's policy attempts

The episode's learners now set decision_tracing, so G12's updates record their policy attempts
(power, reason, accepted) as G8's do. Tracing only records: every other decision and value is
unchanged.
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