Skip to content

CoPH's crossing demo, natively and in the browser (C6 part 3) - #1519

Merged
transfix merged 11 commits into
masterfrom
nav/coph-c6d
Nov 25, 2026
Merged

transfix merged 11 commits into
masterfrom
nav/coph-c6d

Conversation

@transfix

@transfix transfix commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

C6 part 3 of docs/roadmap/NAV-COPH-ROADMAP.md (§4.6): CoPH's crossing demo on pycvc's NavCophFleet, libcvc's C++ CoPH with no torch. It runs natively and in the browser on ariglx-web.

Parts 1, 2 and 2b (#1504, #1516, #1517) have merged, and master is merged in (bb1885c), so this diff is part 3 alone.

Since the master merge (862a685):

  • nav_coph_driver_test.cpp keeps nav: the CoPH ledger's items in the episode record (C5 part 2c) #1502's two ledger tests next to part 2b's regoal test.
  • examples/ariadne/python/coph.ari has a requires: block (af3b86c): raster.bitmap, optional. AriadneComponents.ShippedExamplesDeclareWhatTheyNeed requires one in every example, and its absence failed every package and recipe job.
  • arigl_web_smoke.mjs's CoPH case now expects 121 ticks (b4061c0), the count the run reports: tick 0 activates the agents, then 120 steps follow.

What it adds

  • examples/ariadne/python/coph.py and coph.ari. They run the crossing a few CoPH ticks a frame.
    • The crossing picture is a top-down view of the maze, the doors, the agents' trails, sensors and goals, with a flash when a packet arrives.
    • Readouts give each agent's stage, version, policy and energy account, and plots its distance to goal.
    • A Packets switch turns communication on or off, the demos' two arms.
    • The document has no scene:, so the demo runs headless, in a window, and in a browser on ariglx-web (?src=coph.py, with coph.ari preloaded).
  • Running a few ticks a frame:
    • coph_fleet::run(world, ticks) runs at most that many ticks from where the last call stopped, and tick() gives the next. run(world) is now run(world, -1).
    • NavCophFleet.run_crossing(world, ticks) keeps its world between calls and returns whether every agent is done.
  • The browser check. src/arigl/web/test/python/coph.ari is a new case in ariglx-web's smoke (arigl_web_smoke.mjs). It runs the crossing's first 120 CoPH ticks in the page, 40 at a time, on the page's own pycvc. It reports the packets and each agent's version and energy residual. CI's ariglx-web job builds the module from this PR and runs it in headless Chrome.
  • Docs. ARIADNE.md's example table, CVCGL_WASM.md's list of smoke cases, and the roadmap.

Checked on Windows (MSVC 19.44 Release, pycvc core with Python 3.11)

  • On the merged tree: nav_coph_driver_test 8, nav_stats_test 18. The new coph.ari files and cars.ari are valid against Ariadne: a closed .ari schema every load checks, and ari validate #1464's ari.v1.schema.json (checked with Python's jsonschema; the local build has no validator).
  • nav_coph_fleet_test passes 10, including the new CophFleet.RunsAFewTicksAtATime: the crossing run 15 ticks at a time is the one run whole, bit for bit. nav_coph_driver_test passes 6.
  • test_pycvc_nav_coph.py passes 1293 checks, including the same check through run_crossing(ticks=300).
  • coph.py --headless --frames 300: both agents reach their goals, at 92.2 s and 94.2 s. 192 packets were sent, and all were delivered and accepted; the residuals are 7e-15.
  • coph.ari's python block, run natively, prints the line the smoke's regex expects: 121 ticks, 30 packets sent and delivered, in 635 ms.
  • The demo's picture at 52.8 s shows both agents back from the blocked top corridor, on the bottom row.

Left to CI (this box has no cvcGL): the browser case and the offscreen example run in pycvc_gl_ariadne_host.

Next

A public page, once a libcvc release carries the bindings. GRL-SNAM's pages pin a release (v4.0.0) and build ariglx-web from it.

bindings/pycvc/pycvc_nav_coph.i puts cvc::nav's CoPH in pycvc. It only marshals between Python
values and the library.

- Kernels: nav_coph_flow, nav_coph_balance, nav_coph_risk, nav_coph_potential,
  nav_coph_grad_potential, nav_coph_command, nav_coph_shaping and nav_coph_allocate. A packet's
  bytes are NavCophPacket.bytes(), its json()'s length (D9).
- Configurations are dicts over the demos' profile, keyed by coph_config's field names. An unknown
  key is an error, and validate() runs on the result. nav_coph_profile() and
  nav_coph_communication_profile() return the whole of each.
- NavCophAgent is one learner, a crossing one or a car's (network="none"): observe, advance,
  action, last_control, update, export_to (a NavCophPacket) and assimilate.
- NavCophFleet is the runner's fleet:
  - run_crossing() on the crossing world, with the GIL released; the sensor noise may be a Python
    callable, which takes the GIL back for each call;
  - boundary() for a world of the caller's;
  - samples, controls, updates, events and the energy accounts.

test_pycvc_nav_coph.py (ctest pycvc_nav_coph) checks:
- G2, G3 and G11 from coph_golden.json at its tier;
- the configuration dicts;
- a learner driven on the plant kernel exporting a packet that a second learner assimilates;
- a car's learner;
- the fleet on G12's crossing world and noise, as CophFleet.TheEnergyAccountStaysAtRoundOffOverALongRun
  runs it: both agents reach their goals, in 767 and 784 steps, with residuals at 7e-15.
…ion-local static

pycvc-linux's writable-data scan (tools/singleton_scan) flagged config_fields()' static std::map
and its guard variable as new process-wide state in pycvcPYTHON_wrap.cxx. The table is now a
constexpr array of names and plain function pointers, which the compiler places in read-only data
(.data.rel.ro under PIC) with nothing initialised at run time; a lookup walks it. Behaviour is
unchanged: test_pycvc_nav_coph.py still passes its 1278 checks, as do test_pycvc_ph.py and
test_pycvc_nav_lab.py.
…ely (C6 part 2)

pycvc.NavCophDriver binds C5's coph_driver to a nav_sim_world_create handle. It holds a
reference to the handle while it lives, and its methods are attach, apply, ticks_per_step, steps,
done, account, controls and events. pycvc_gl.cars uses it:
- Cars(..., coph={...}) attaches every car, and step_coph() runs the driver's apply before the
  world's step. coph_froude() gives the Froude scale: the car's length over a RoboRacer's (D3, D4).
  coph_coeffs() gives each car's account for the coefficient plots and the log.
- The template takes --controller coph and --coph-scale, and the Run panel gains a CoPH choice.
  --gym and --world-doc refuse it, since the driver runs on a sim_world.
- docs/CARS.md documents it, including its limit: a CoPH car that arrives brakes and stays,
  taking no new goal.

The fleet's controls and events now share one converter between NavCophFleet and NavCophDriver.

Checked on Windows (pycvc core; this box has no cvcGL):
- test_pycvc_nav_coph.py: 1288 checks.
  - A driver with nothing attached leaves the run bit for bit.
  - Two RoboRacer-sized cars cross in 485 ticks, as CophDriver.TwoCarsCrossTheField does.
- Cars(coph=...) loaded from cars.py's source: two Humvee-sized cars on nav's bicycle cross 60 m
  of the flat world and both arrive in 37.9 s, with no contact, at s = 9.05.
- test_pycvc_gl_cars.py gains the same Cars check and a headless --controller coph run. CI runs
  it.
…s (C6 part 2b)

#1516 had two limits; this fixes both.

1. A car that arrived stayed parked even when given a new goal. coph_fleet::resume(agent) now lets
   an agent that finished at its goal run again from the next boundary, its learner keeping what
   it learned. That boundary observes without a transition and records an activation. Refused when
   the agent is running, or was ended by a hit or by the run's steps. coph_driver calls it when the
   sim moves a done car's goal, as GRL-SNAM's cars controller clears a car's done.
   NavCophFleet.resume() binds it.

2. --gym and --world-doc refused --controller coph, because the driver needs a sim_world.
   pycvc_gl.cars.CophControl runs the same fleet over NavCophFleet from any cars' CarsState, the
   twin of coph_driver:
   - Froude frames and CoPH's cadence;
   - the local goal;
   - the 21 lattice readings of a constant risk, or a risk(x, y) it is given;
   - the rays' hits within the scaled sensor radius as disks;
   - nav_coph_allocate every tick;
   - braking when done, and resume on a new goal.
   The template uses it for GymCars and HostCars. Cars keeps the native driver.

docs/CARS.md and the roadmap drop the two limits. What remains: CophControl sees obstacles only
along the rays, and a constant risk unless given one.

Checked on Windows:
- nav_coph_fleet_test (9, with CophFleet.ResumesOnlyAnAgentAtItsGoal) passes.
- nav_coph_driver_test (6) passes. CophDriver.ACarTakesANewGoalAfterArriving reaches (8, 6), then
  (14, 6), in 386 ticks.
- test_pycvc_nav_coph.py passes 1291 checks. A driven car given a new goal reaches it in 264 more
  ticks, while the other stays parked.
- Cars loaded from source: native, both cars cross and car 0 reaches a new goal. With CophControl
  both arrive in the same 649 ticks with no contact, and a new goal runs car 1 again.
- test_pycvc_gl_cars.py adds the same checks plus CophControl on GymCars and a headless
  --gym --controller coph run. CI runs it (no cvcGL here).
examples/ariadne/python/coph.py and coph.ari run the crossing demo on pycvc's NavCophFleet,
libcvc's C++ CoPH with no torch.
- It runs a few CoPH ticks a frame and shows a top-down picture of the maze, the doors, the
  agents' trails and sensors, and a flash when a packet arrives.
- It shows each agent's stage, version, policy and energy account, and its distance to goal.
- A Packets switch turns communication on or off, the demos' two arms.
- It has no scene:, so it runs headless, in a window, and in a browser on ariglx-web
  (?src=coph.py, with coph.ari preloaded).

To run a few ticks a frame:
- coph_fleet::run(world, ticks) runs at most that many ticks from where the last call stopped,
  and tick() gives the next. run(world) is now run(world, -1).
- NavCophFleet.run_crossing(world, ticks) keeps its world between calls, and returns whether every
  agent is done.

Checks:
- src/arigl/web/test/python/coph.ari, a new case in ariglx-web's browser smoke, runs the
  crossing's first 120 CoPH ticks in the page, 40 at a time, on the page's own pycvc. It reports
  the packets and each agent's version and energy residual.
- CophFleet.RunsAFewTicksAtATime: the crossing run 15 ticks at a time is the one run whole, bit for
  bit.
- test_pycvc_nav_coph.py checks the same, 300 ticks at a time.
- test_pycvc_gl_ariadne_host.py runs the example offscreen.
- ARIADNE.md's example table and CVCGL_WASM.md's list of smoke cases name them.

Checked on Windows:
- nav_coph_fleet_test (10) and nav_coph_driver_test (6) pass; test_pycvc_nav_coph.py passes 1293
  checks.
- coph.py --headless --frames 300: both agents reach their goals, at 92.2 s and 94.2 s, with 192
  packets sent, delivered and accepted, and residuals at 7e-15.
- coph.ari's python block, run natively, prints the line the smoke's regex expects: 121 ticks,
  30 packets sent and delivered, in 635 ms.
- The browser case and the offscreen example run are CI's (ariglx-web job, pycvc_gl): this box
  has no cvcGL.
# Conflicts:
#	bindings/pycvc/pycvc_nav_coph.i
#	bindings/pycvc/test_pycvc_nav_coph.py
#	docs/roadmap/NAV-COPH-ROADMAP.md
#	src/cvc/tests/nav_coph_driver_test.cpp
…eports

The crossing runs ticks 0 to 120 (tick 0 activates the agents, 120 steps follow), so
NavCophFleet.tick() is 121 when every agent is done. The regex asked for 120 and would
never have matched.
Every document under examples/ariadne/ has a requires: block
(AriadneComponents.ShippedExamplesDeclareWhatTheyNeed, ARIADNE.md 5.7). The crossing
picture shows in real pixels where the host has raster.bitmap and as half-block cells
elsewhere, so it is optional; Restart's on: is a bare event coph.py handles, not a
function, so it is not listed.
# Conflicts:
#	bindings/pycvc/pycvc_nav_coph.i
#	bindings/pycvc/pymod_gl/cars.py
#	bindings/pycvc/test_pycvc_gl_cars.py
#	bindings/pycvc/test_pycvc_nav_coph.py
#	docs/CARS.md
#	docs/roadmap/NAV-COPH-ROADMAP.md
# Conflicts:
#	docs/roadmap/NAV-COPH-ROADMAP.md
#	src/cvc/nav/coph_fleet.cpp
#	src/cvc/tests/nav_coph_fleet_test.cpp
@transfix
transfix merged commit 5f1944a into master Nov 25, 2026
31 checks passed
@transfix
transfix deleted the nav/coph-c6d branch November 25, 2026 07:41
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