Repository navigation
pycvc_gl.cars: --controller coph, CoPH's fleet driving the cars natively (C6 part 2) - #1516
Merged
Merged
Conversation
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.
transfix
enabled auto-merge (squash)
November 24, 2026 02:14
This was referenced Nov 24, 2026
# Conflicts: # bindings/pycvc/pycvc_nav_coph.i # bindings/pycvc/test_pycvc_nav_coph.py # docs/roadmap/NAV-COPH-ROADMAP.md
transfix
added a commit
that referenced
this pull request
Nov 25, 2026
…s (C6 part 2b) (#1517) * pycvc: CoPH's kernels, NavCophAgent and NavCophFleet (C6 part 1) 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. * pycvc_nav_coph: the config field table is constexpr data, not a function-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. * pycvc_gl.cars: --controller coph, CoPH's fleet driving the cars natively (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. * CoPH's cars take a new goal after arriving, and run on world documents (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).
transfix
added a commit
that referenced
this pull request
Nov 25, 2026
* pycvc: CoPH's kernels, NavCophAgent and NavCophFleet (C6 part 1)
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.
* pycvc_nav_coph: the config field table is constexpr data, not a function-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.
* pycvc_gl.cars: --controller coph, CoPH's fleet driving the cars natively (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.
* CoPH's cars take a new goal after arriving, and run on world documents (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).
* CoPH's crossing demo, natively and in the browser (C6 part 3)
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.
* arigl_web_smoke: the CoPH case expects 121 ticks, the count the run reports
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.
* coph.ari declares what it needs: raster.bitmap, optional
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.
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.
C6 part 2 of
docs/roadmap/NAV-COPH-ROADMAP.md(§4.6): the cars template's--controller coph, which runs CoPH's fleet natively in C++, with no torch.Stacked on #1504 (C6 part 1). Until #1504 merges, this diff includes it. This PR's own commit is the last one.
What changes
pycvc.NavCophDriver(pycvc_nav_coph.i) binds C5'scoph_driverto anav_sim_world_createhandle.attach,apply,ticks_per_step,steps,done,account,controlsandevents.stepskey in its config, a run lasts 1,000,000 CoPH steps.pycvc_gl.cars:Cars(..., coph={...})attaches every car, andstep_coph()runs the driver'sapply()before the world's step.coph_froude()is the default Froude scale: the car's length over a RoboRacer's, so 1 for a RoboRacer and about 9 for a Humvee (D3, D4).coph_coeffs()returns each car's account (allocation residual, work, risk cost, CoPH steps) for the coefficient plots and the log.--controller cophand--coph-scale, and the Run panel's Controller gains a CoPH choice.--gymand--world-docrefuse it, because the driver runs on asim_world.docs/CARS.mdgets a "CoPH, natively" section and a known limit: a CoPH car that arrives brakes and stays, because its learner's run is over.Checked on Windows (pycvc core, Python 3.11)
This box has no cvcGL, so pycvc_gl isn't built here.
test_pycvc_nav_coph.pypasses 1288 checks:CophDriver.TwoCarsCrossTheFielddoes in C++.Cars(coph=...), loaded fromcars.py's source (it needs only pycvc and numpy): two Humvee-sized cars on nav's bicycle cross 60 m of the flat world past each other. Both arrive in 37.9 s with no contact, at s = 9.05.Not run locally:
test_pycvc_gl_cars.py, which now has the sameCarscheck plus a headless--controller cophtemplate run that logs the accounts. CI'spycvc_gl_carsruns it.Next
C6 part 3 is the browser demo (pycvc-gl's wasm build).