Skip to content

coph_golden: G12, an episode of two agents with communication on (C5, part 1) - #202

Merged
transfix merged 4 commits into
mainfrom
feat/coph-golden-c5
Nov 22, 2026
Merged

transfix merged 4 commits into
mainfrom
feat/coph-golden-c5

Conversation

@transfix

Copy link
Copy Markdown
Contributor

C5 part 1 of libcvc's docs/roadmap/NAV-COPH-ROADMAP.md: the G12 golden (§4.5, §5) that libcvc's C5 fleet will reproduce.

Stacked on #201 (G9–G10). Until #201 merges, this branch's first commit is #201's. Once #201 lands, I'll merge main in so the diff shows only G12. Merging this PR is Joe's call.

What lands

grl_snam.tools.coph_golden_episode writes an episode section and its episode_rules.

  • The run. The demos' own runner, staggered_demo.execute with arm reciprocal_fixed, drives two CrossingLearner agents for 60 ticks of the crossing. Agent 0 goes from (0, 4) to (12, 4) and agent 1 the other way, through the crossing's two doors. The runner's audits are off. At this byte budget its status replies never bind.
  • The world is CrossingWorld with one change: its sensor noise is a fixed rational pattern instead of numpy's normal draws. So the C++ can sense the same readings at its own positions.
  • What happens.
    • Agent 1 senses the middle door at tick 33 and turns north.
    • Agent 0 learns of the door from agent 1's packet at tick 40 and reroutes through the north row.
    • Both agents update every 8 ticks, each time with the other's packet. All 16 packets are eligible and every update accepts.
  • Decisions (BIT):
    • per tick, each agent's stage, version and routed control (reason, route reason, route nodes, waypoint, guard steps, route change);
    • per update, its packets, attempts and verdict;
    • the runner's events (activations, sends, deliveries with their reasons);
    • the geometry events.
  • Values (FLOAT64, atol 1e-6): each agent's state at every boundary, and its applied and nominal force at every step. The plant is the world's exact flow in torch, so these differ in their last bits between platforms.
  • Draws. Each sent packet's bootstrap draws are recorded from the learner's own generators, so the C++ can inject them (D8).

Determinism

Generation checks that no decision changes when the world's damping is nudged by 1e-9 relative each way. Positions then move by about 2.5e-10. A probe found the decisions hold at a 1e-6 nudge too, which moves positions by 2.5e-7.

Tests

tests/test_coph_golden.py adds 3 tests:

  • each agent's positions rebuild from its forces with G2's closed form;
  • coverage;
  • another platform's last bits pass and nothing else does.

The regenerate test now compares episode too. On Windows the golden and CoPH test files pass in full (38 tests), and black and ruff are clean.

The committed G3 bits are kept, as in #195. The fixture grows by 39 KB, to 1.27 MB.

… (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.
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.
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.
# Conflicts:
#	grl_snam/coph/VENDORED.md
#	grl_snam/tools/coph_golden.py
#	tests/fixtures/coph_golden/coph_golden.json
#	tests/test_coph_golden.py
@transfix
transfix merged commit aba8ecc into main Nov 22, 2026
5 checks passed
transfix added a commit to transfix/libcvc that referenced this pull request Nov 22, 2026
…1413)

* nav: CoPH's packets, their assimilation and the channel (C4; G9-G10)

C4 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.4), additive and default-off: nothing calls it
yet; C5's fleet driver will.

- coph_packet.h: the demos' packet (cooperative.Packet, then MazePacket's geometry), and bytes():
  the length of its compact, key-sorted JSON, with Python's repr for floats (coph_repr, from
  std::to_chars's shortest digits) (D9). coph_exchange_state holds the received packets, the
  route evidence and its cells, and the reported geometry.
- coph_exchange.h:
  - coph_export: CooperativeLearner's bootstrap and candidate anchors, TerrainLearner's
    risk-ordered anchors and second bootstrap, MazeLearner's geometry. The resample indices are
    injected, or drawn from a seeded std::mt19937 through detail::pick_below (D8).
  - coph_assimilate: MazeLearner's geometry checks; CooperativeLearner's schema, provenance, age,
    order, payload and received cap; TerrainLearner's route evidence.
  - coph_expire and the two refreshes.
  - coph_fit_messages: the legacy receiver's whitened Gauss-Newton step, which coph_update now
    commits when packets are held.
- coph_channel.h: the transport interface and coph_ideal_channel (seeded delay and jitter, drops,
  duplicates, an optional range).
- detail/coph_math.h: the features, Cholesky and slab distance that coph_learner.cpp and
  coph_exchange.cpp share (moved out of coph_learner.cpp unchanged).

nav_coph_exchange_test reproduces GRL-SNAM's G9 and G10 (CVC-Lab/GRL-SNAM#201;
data/coph_golden.json is its fixture). Every decision and byte count matches exactly, and the
values come within 0.074 of the tier's allowance on Windows. It also checks the channel's
statistics, production draws and JSON escapes.

* nav: CoPH's agent and fleet, and the crossing world (C5 part 1; G12)

C5 part 1 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off.

- coph_agent.h: the demos' whole learner (CrossingLearner) over C1-C4.
  - observe: CooperativeLearner's uids, navigation.observe_geometry's store, C1's ledger, the
    expiries, MazeLearner's geometry reports.
  - advance.
  - action: the routed control in the live navigation context.
  - update: CooperativeLearner's diagnostic controls around C3's update, then TerrainLearner's
    own anchors.
  - export and assimilate, with the received-geometry events.
- coph_fleet.h:
  - coph_fleet: the demos' runner (staggered_demo.execute) for agents that start together, over
    a coph_channel. Its boundaries observe and advance, export on the update cadence, deliver,
    update and act. It keeps records and each agent's energy account.
  - coph_crossing_world: the crossing demo's world, with its plant, its door and corridor hits
    and its sensing.
- C1-C3 gain the hooks it needs:
  - coph_ledger::commit;
  - the route change and the raw command in coph_control_meta;
  - coph_corridor_clear and coph_slab_sweep;
  - coph_field_vector;
  - TerrainLearner's local cells in the exchange state.

nav_coph_fleet_test reproduces GRL-SNAM's G12 (CVC-Lab/GRL-SNAM#202; data/coph_golden.json is its
fixture). Every decision matches, and positions and forces are within 2.8e-16 against an atol of
1e-6. The C++-only tests cover:
- refusals outside the profile;
- packets arriving after a channel's delay;
- a run of the whole crossing, which both agents finish (agent 0 in 92.0 s, the demo's
  reciprocal finish time) with each energy account's residual at 7e-15.

The vehicle driver and the plant_ledger items (D11) are part 2.
transfix added a commit to transfix/libcvc that referenced this pull request Nov 23, 2026
* nav: CoPH's packets, their assimilation and the channel (C4; G9-G10)

C4 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.4), additive and default-off: nothing calls it
yet; C5's fleet driver will.

- coph_packet.h: the demos' packet (cooperative.Packet, then MazePacket's geometry), and bytes():
  the length of its compact, key-sorted JSON, with Python's repr for floats (coph_repr, from
  std::to_chars's shortest digits) (D9). coph_exchange_state holds the received packets, the
  route evidence and its cells, and the reported geometry.
- coph_exchange.h:
  - coph_export: CooperativeLearner's bootstrap and candidate anchors, TerrainLearner's
    risk-ordered anchors and second bootstrap, MazeLearner's geometry. The resample indices are
    injected, or drawn from a seeded std::mt19937 through detail::pick_below (D8).
  - coph_assimilate: MazeLearner's geometry checks; CooperativeLearner's schema, provenance, age,
    order, payload and received cap; TerrainLearner's route evidence.
  - coph_expire and the two refreshes.
  - coph_fit_messages: the legacy receiver's whitened Gauss-Newton step, which coph_update now
    commits when packets are held.
- coph_channel.h: the transport interface and coph_ideal_channel (seeded delay and jitter, drops,
  duplicates, an optional range).
- detail/coph_math.h: the features, Cholesky and slab distance that coph_learner.cpp and
  coph_exchange.cpp share (moved out of coph_learner.cpp unchanged).

nav_coph_exchange_test reproduces GRL-SNAM's G9 and G10 (CVC-Lab/GRL-SNAM#201;
data/coph_golden.json is its fixture). Every decision and byte count matches exactly, and the
values come within 0.074 of the tier's allowance on Windows. It also checks the channel's
statistics, production draws and JSON escapes.

* nav: CoPH's agent and fleet, and the crossing world (C5 part 1; G12)

C5 part 1 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off.

- coph_agent.h: the demos' whole learner (CrossingLearner) over C1-C4.
  - observe: CooperativeLearner's uids, navigation.observe_geometry's store, C1's ledger, the
    expiries, MazeLearner's geometry reports.
  - advance.
  - action: the routed control in the live navigation context.
  - update: CooperativeLearner's diagnostic controls around C3's update, then TerrainLearner's
    own anchors.
  - export and assimilate, with the received-geometry events.
- coph_fleet.h:
  - coph_fleet: the demos' runner (staggered_demo.execute) for agents that start together, over
    a coph_channel. Its boundaries observe and advance, export on the update cadence, deliver,
    update and act. It keeps records and each agent's energy account.
  - coph_crossing_world: the crossing demo's world, with its plant, its door and corridor hits
    and its sensing.
- C1-C3 gain the hooks it needs:
  - coph_ledger::commit;
  - the route change and the raw command in coph_control_meta;
  - coph_corridor_clear and coph_slab_sweep;
  - coph_field_vector;
  - TerrainLearner's local cells in the exchange state.

nav_coph_fleet_test reproduces GRL-SNAM's G12 (CVC-Lab/GRL-SNAM#202; data/coph_golden.json is its
fixture). Every decision matches, and positions and forces are within 2.8e-16 against an atol of
1e-6. The C++-only tests cover:
- refusals outside the profile;
- packets arriving after a channel's delay;
- a run of the whole crossing, which both agents finish (agent 0 in 92.0 s, the demo's
  reciprocal finish time) with each energy account's residual at 7e-15.

The vehicle driver and the plant_ledger items (D11) are part 2.

* nav: CoPH's cars' learner, the profile's router (C5 part 2a; G13)

C5 part 2a of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off. A car carries
the cars controller's learner (GRL-SNAM's CarLearner, demo 2b), not the crossing's: a bare
CooperativeLearner whose stages advance by MazeLearner's rule, routing with the profile's own planner
since a car's world has no surveyed network, and sending packets without maze or terrain layers.

- coph_learner.h:
  - coph_profile_route and coph_edge_clear port navigation.route without a maze graph: A* through
    the sensor footprints on a 0.1 m grid, with edges priced by the stages' risk, replanning on
    stagnation, the update cadence, a blocked waypoint or a newly sensed disk.
  - coph_control dispatches on the learner's network: an empty one takes the profile's router
    and drops the guard's corridor checks.
  - Each kept stage keeps its entry context, from which the replay and the pilot start.
- coph_agent with an empty network runs CooperativeLearner on Learner: no geometry reports, no
  terrain anchors, and CooperativeLearner's packet (coph_packet::maze false: no geometry keys in
  its JSON).
- coph_can_export: whether an export makes a packet, so the fleet asks a draw source only then.
- coph_crossing_world with no network and risk patches is CooperativeWorld's open field.

nav_coph_cars_test reproduces GRL-SNAM's G13 (CVC-Lab/GRL-SNAM#203; data/coph_golden.json is its
fixture). Every decision matches, including each planned route and every delivery, and positions
are within 5.6e-16 against an atol of 1e-6. G1 to G12 are unchanged.

The vehicle driver on sim_world and the plant_ledger items (D11) are part 2b.

* nav: CoPH drives a sim_world's vehicles (C5 part 2b)

C5 part 2b of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off:
coph_driver, the twin of GRL-SNAM's cars controller (T4), outside sim_world as route_follower is
(D10).

- coph_driver.h: attach agents, then apply() before each sim step.
  - Every ticks_per_step() ticks (0.12 sqrt(s) over veh.dt; D6) a CoPH step: each car's state in
    CoPH's frame (Froude scaling, D4), its local goal 30 m along the line (D12), its readings of
    the material plane's risk at CoPH's 21 sensor points, and the occupied cells within the
    scaled sensor radius as disks (visible_obstacles). Then the fleet's boundary.
  - Every tick each car allocates its held force (coph_allocate) and drives through
    override_command; a car that has arrived brakes.
  - Each car's ledger in CoPH's frame: the work of the force it took, its own kinetic change, the
    closed-form heat, their residual, the unallocated work, the risk cost and the allocation
    residual.
- coph_fleet::input gains the force the plant took (the transition carries it, D5), the world's
  arrival, and a new goal; coph_agent and coph_ledger gain set_goal.

nav_coph_driver_test (C++ only):
- with nothing attached, a 400-tick run is byte-unchanged;
- CoPH's cadence under Froude scaling, and the refusals;
- two RoboRacer-sized cars (s = 1) pass each other across a 20 m field and both arrive in 29.1 s,
  with packets between them (allocation residuals 0.11 and 0.20);
- a car driving head-on at a block it senses late stops 0.21 m short and never touches it.

G1 to G13 are unchanged. The plant_ledger items (D11) are part 2c.

* CophDriver.ABlockSensedLateIsNeverHit ends once the car has stood still for 6 s

The car stops 0.21 m short of the block at about tick 250 and stays there, but the run went on to
its 1500-tick cap: 10.2 s in Release, about 3.2 times the two-car crossing. That was more than the
300 s a PR's Debug ctest allows on the slow runner of #1461's first run, and more than the 900 s
the executable now has.

The run now also ends after 100 ticks (6 s) with the car's speed under 1e-3. It ends at tick 347
with the same result as before: at (10.71, 5.85), 0.21 m from the block at its closest, the last
control brake (no_start_connector), allocation residual 0.557. 2.0 s in Release on Windows.
transfix added a commit to transfix/libcvc that referenced this pull request Nov 23, 2026
)

* nav: CoPH's packets, their assimilation and the channel (C4; G9-G10)

C4 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.4), additive and default-off: nothing calls it
yet; C5's fleet driver will.

- coph_packet.h: the demos' packet (cooperative.Packet, then MazePacket's geometry), and bytes():
  the length of its compact, key-sorted JSON, with Python's repr for floats (coph_repr, from
  std::to_chars's shortest digits) (D9). coph_exchange_state holds the received packets, the
  route evidence and its cells, and the reported geometry.
- coph_exchange.h:
  - coph_export: CooperativeLearner's bootstrap and candidate anchors, TerrainLearner's
    risk-ordered anchors and second bootstrap, MazeLearner's geometry. The resample indices are
    injected, or drawn from a seeded std::mt19937 through detail::pick_below (D8).
  - coph_assimilate: MazeLearner's geometry checks; CooperativeLearner's schema, provenance, age,
    order, payload and received cap; TerrainLearner's route evidence.
  - coph_expire and the two refreshes.
  - coph_fit_messages: the legacy receiver's whitened Gauss-Newton step, which coph_update now
    commits when packets are held.
- coph_channel.h: the transport interface and coph_ideal_channel (seeded delay and jitter, drops,
  duplicates, an optional range).
- detail/coph_math.h: the features, Cholesky and slab distance that coph_learner.cpp and
  coph_exchange.cpp share (moved out of coph_learner.cpp unchanged).

nav_coph_exchange_test reproduces GRL-SNAM's G9 and G10 (CVC-Lab/GRL-SNAM#201;
data/coph_golden.json is its fixture). Every decision and byte count matches exactly, and the
values come within 0.074 of the tier's allowance on Windows. It also checks the channel's
statistics, production draws and JSON escapes.

* nav: CoPH's agent and fleet, and the crossing world (C5 part 1; G12)

C5 part 1 of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off.

- coph_agent.h: the demos' whole learner (CrossingLearner) over C1-C4.
  - observe: CooperativeLearner's uids, navigation.observe_geometry's store, C1's ledger, the
    expiries, MazeLearner's geometry reports.
  - advance.
  - action: the routed control in the live navigation context.
  - update: CooperativeLearner's diagnostic controls around C3's update, then TerrainLearner's
    own anchors.
  - export and assimilate, with the received-geometry events.
- coph_fleet.h:
  - coph_fleet: the demos' runner (staggered_demo.execute) for agents that start together, over
    a coph_channel. Its boundaries observe and advance, export on the update cadence, deliver,
    update and act. It keeps records and each agent's energy account.
  - coph_crossing_world: the crossing demo's world, with its plant, its door and corridor hits
    and its sensing.
- C1-C3 gain the hooks it needs:
  - coph_ledger::commit;
  - the route change and the raw command in coph_control_meta;
  - coph_corridor_clear and coph_slab_sweep;
  - coph_field_vector;
  - TerrainLearner's local cells in the exchange state.

nav_coph_fleet_test reproduces GRL-SNAM's G12 (CVC-Lab/GRL-SNAM#202; data/coph_golden.json is its
fixture). Every decision matches, and positions and forces are within 2.8e-16 against an atol of
1e-6. The C++-only tests cover:
- refusals outside the profile;
- packets arriving after a channel's delay;
- a run of the whole crossing, which both agents finish (agent 0 in 92.0 s, the demo's
  reciprocal finish time) with each energy account's residual at 7e-15.

The vehicle driver and the plant_ledger items (D11) are part 2.

* nav: CoPH's cars' learner, the profile's router (C5 part 2a; G13)

C5 part 2a of docs/roadmap/NAV-COPH-ROADMAP.md (section 4.5), additive and default-off. A car carries
the cars controller's learner (GRL-SNAM's CarLearner, demo 2b), not the crossing's: a bare
CooperativeLearner whose stages advance by MazeLearner's rule, routing with the profile's own planner
since a car's world has no surveyed network, and sending packets without maze or terrain layers.

- coph_learner.h:
  - coph_profile_route and coph_edge_clear port navigation.route without a maze graph: A* through
    the sensor footprints on a 0.1 m grid, with edges priced by the stages' risk, replanning on
    stagnation, the update cadence, a blocked waypoint or a newly sensed disk.
  - coph_control dispatches on the learner's network: an empty one takes the profile's router
    and drops the guard's corridor checks.
  - Each kept stage keeps its entry context, from which the replay and the pilot start.
- coph_agent with an empty network runs CooperativeLearner on Learner: no geometry reports, no
  terrain anchors, and CooperativeLearner's packet (coph_packet::maze false: no geometry keys in
  its JSON).
- coph_can_export: whether an export makes a packet, so the fleet asks a draw source only then.
- coph_crossing_world with no network and risk patches is CooperativeWorld's open field.

nav_coph_cars_test reproduces GRL-SNAM's G13 (CVC-Lab/GRL-SNAM#203; data/coph_golden.json is its
fixture). Every decision matches, including each planned route and every delivery, and positions
are within 5.6e-16 against an atol of 1e-6. G1 to G12 are unchanged.

The vehicle driver on sim_world and the plant_ledger items (D11) are part 2b.
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