Skip to content

pycvc: CoPH's kernels, NavCophAgent and NavCophFleet (C6 part 1) - #1504

Merged
transfix merged 2 commits into
masterfrom
nav/coph-c6a
Nov 24, 2026
Merged

transfix merged 2 commits into
masterfrom
nav/coph-c6a

Conversation

@transfix

Copy link
Copy Markdown
Owner

C6 part 1 of docs/roadmap/NAV-COPH-ROADMAP.md (§4.6): cvc::nav's CoPH in pycvc. The new bindings/pycvc/pycvc_nav_coph.i only marshals between Python values and the library.

The surface

  • Kernels (GRL-SNAM's G2, G3 and G11): 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 scene is {"centers", "weights", "width", "obstacles"}.
    • A shape is (x, y, r) for a disk, or (x, y, r, hx, hy) for a slab.
  • Configurations are dicts over the demos' profile (coph_profile(), D7), 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: one learner, either a crossing one or a car's (network="none"). It has observe, advance, action, last_control, update, export_to (which returns a NavCophPacket), assimilate and state.
  • NavCophPacket: json(), bytes() (D9), identity(), sender(), recipient(), version() and anchors().
  • NavCophFleet: the runner's fleet.
    • run_crossing(world) runs on the crossing world with the GIL released. The sensor noise can be a Python callable, which takes the GIL back for each call.
    • boundary() serves a world of the caller's.
    • It exposes samples, controls, updates, events and energy.

Checked on Windows (Release, MSVC 19.44, Python 3.11, SWIG from the cvcpkg tools prefix)

test_pycvc_nav_coph.py (ctest pycvc_nav_coph) passes 1278 checks:

  • G2 (40 plant cases), G3 (50 potential cases, 25 with progress shaping) and G11 (60 allocation cases) come within the golden's tier. They read src/cvc/tests/data/coph_golden.json, the same file the C++ tests read.
  • The configuration dicts: the profile, overrides, an unknown key, a refused value and a mode outside the profile.
  • A learner driven on the plant kernel exports a packet. Its bytes() is its JSON's length, the keys are sorted, and a second learner assimilates it. A car's learner routes without a network.
  • The fleet on G12's crossing world and noise matches CophFleet.TheEnergyAccountStaysAtRoundOffOverALongRun: both agents reach their goals, in 767 and 784 steps, with residuals of 7.5e-15 and 7.0e-15. Packets were sent and delivered.

test_pycvc_ph.py (35 checks) and test_pycvc_nav_lab.py (147 checks) still pass. The build had CVC_BUILD_PYCVC_GL=OFF, since this box has no cvcGL; this PR doesn't touch pycvc_gl.

Next

C6 part 2 is --controller coph in the cars template, then the browser demo.

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.
@transfix
transfix enabled auto-merge (squash) November 23, 2026 21:34
…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.
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