Skip to content

grl_snam.coph: CoPH-Stagewise vendored at c1f1ff3; both demos reproduce upstream exactly - #166

Merged
transfix merged 5 commits into
mainfrom
feat/coph-vendor
Nov 12, 2026
Merged

transfix merged 5 commits into
mainfrom
feat/coph-vendor

Conversation

@transfix

@transfix transfix commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

This is T1 of libcvc's CoPH roadmap (transfix/libcvc#1108 and transfix/libcvc#1111, docs/roadmap/NAV-COPH-ROADMAP.md §3.1). It copies the CoPH-Stagewise core and the crossing and hazard demos from SetasAditya/CoPH-Sense at c1f1ff3 into grl_snam.coph. The copied demos reproduce upstream's numbers exactly. T3 (demo 2a on Ariadne) and T5 (the goldens) build on this.

Usage: grl-snam coph crossing|hazard --out DIR [--seeds N] [--steps N] [--workers N] [--summary-only]. A run writes its episodes, a manifest with the oracle predictions frozen before any episode ran, results.json and REPORT.md.

The numbers gate

Measured on this branch on Windows 11, with cvcpkg's Python 3.12.10, torch 2.8.0 (CPU) and numpy 2.4.6. That is the stack upstream's own reproduction ran on (2026-11-09).

Crossing (23.6 min, 8 workers): 16/16 goals and 0 collisions.

seed 76000 seed 76001 upstream
one-way saving (sum) 13.4 m 13.4 m 13.4 m
reciprocal saving 27.1 m 27.1 m 27.1 m
finish A / B, communication off 132.7 / 134.4 s 132.7 / 134.4 s same
finish A / B, reciprocal 92.0 / 92.5 s 92.0 / 93.0 s same

Hazard (17.8 min, 12 workers): 64/64 goals and 0 collisions. The carrier's worst-case excess cost:

none field occupancy_0p1 occupancy_0p25 occupancy_1 decision raw no_learning
68.1 4.6 12.3 14.9 25.3 25.3 4.6 4.6

Exact. All 40 episode files (8 crossing, 32 hazard) equal those in upstream's results/{crossing,hazard}_reproduction/ field for field, apart from wall-clock timings. The crossing rows.json and report tables match upstream's line for line. Another build was using about half the box's cores during the runs, so the times are not benchmarks.

What is copied

There are 25 of upstream's 120 modules; grl_snam/coph/VENDORED.md lists them all.

  • 15 verbatim, byte-identical to upstream: model, records, learner, navigation, stage_prediction, replay_budget, world, scenarios, shapes, maze_geometry, maze_learning, terrain_warning, sharing, route_oracle and hazard_oracle.
  • 4 changed: cooperative, route_field, crossing_demo and hazard_demo.
  • 6 trimmed to the definitions the demos reach, each one verbatim: staggered_demo (the runner), cooperative_evaluation, maze_family, diagnostics, evaluation and cli.

The roadmap estimated about 15 modules. It took 25 because the demos call into staggered_demo, maze_family, terrain_warning, sharing and diagnostics at run time. Reporting, campaigns, figures, diagnostics suites and the other demos stay out. So do the only scipy users. The package needs only torch, numpy and matplotlib.

The first commit is the verbatim copy, so the second commit's diff shows exactly what changed locally.

Local changes

Each change carries a grl_snam.coph: comment in the code.

  • The two untanglings.
    • CooperativeLearner now subclasses Learner. The InstrumentedLearner hooks became the optional diagnostics.Instrumented mixin. The demos never read the hooks, so results are unchanged.
    • route_field imports terrain_warning lazily.
  • Receivers. Receiver modes other than legacy raise NotImplementedError, because receiver_fitting is not vendored. _receiver_acceptance short-circuits exactly as receiver_fitting.acceptance does for a legacy receiver. evaluate_packet is removed.
  • Results. crossing_demo and hazard_demo write results.json, rows.json and REPORT.md through the new results.py instead of upstream's figure modules. results.py copies crossing_visuals' metric functions, so the saving arithmetic is upstream's. hazard_demo gains --steps and --seeds.
  • Provenance. source_hashes and archive_sources cover grl_snam/coph.
  • Lint. black and ruff skip the vendored files, which keep upstream's formatting so re-syncing stays a diff. They do check __init__.py, results.py and the CLI.

Tests and CI

  • Ported tests. tests/coph/ has 12 upstream test files (92 tests), trimmed where they reach modules that are not vendored. VENDORED.md lists every removed or edited test. Upstream's other 31 test files test modules that stay out.
  • CLI and smokes. tests/test_coph.py runs both demos through the CLI at a short horizon.
    • Crossing runs 1 seed × 4 arms × 50 steps. At 50 steps the first door warnings already shorten the receivers' paths. The test pins what upstream's code produces at the same horizon:
      • each arm's path lengths;
      • every packet's sender and support-point count;
      • the deliveries;
      • the geometry events.
    • Why not bytes. The first version also pinned byte counts, and Linux CI failed it on all three interpreters: 80,817–80,834 bytes against 79,488, with the paths equal to 1e-6.
      • A packet's size is its compact JSON. The first export's covariance comes from 8 identical bootstrap members, so it is pure round-off.
      • Whether np.cov returns exact 0.0 or ~1e-35 residues (22 characters each) depends on numpy's summation order. Locally, the same 8 rows give 112 or 132 exact zeros and packets 380 bytes apart.
      • VENDORED.md notes this for the goldens: roadmap G9 has bytes() as BIT.
    • Hazard runs 4 scenes × 8 arms × 10 steps.
    • It also checks both untanglings.
  • Local run. All 97 tests pass locally. black --check and ruff check are clean. Under coverage, the tests cover 88.2% of grl_snam/coph's 2,493 statements. Main is at 90.3% of 9,580, so the total should stay near 90% against the 80% gate.
  • Full gate. It is too slow for PR CI. The roadmap proposes it as a nightly, and this PR does not add that workflow.

Open questions

  • Pin. The CoPH-Sense authors haven't confirmed which package and commit to pin yet (roadmap §9). Upstream hasn't moved since c1f1ff3, and VENDORED.md has the steps for re-syncing.
  • License. CoPH-Sense has no LICENSE file and no per-file copyright lines at c1f1ff3. The MIT basis is the authors' confirmation of 2026-11-09, as VENDORED.md records. A LICENSE file upstream would make that checkable.

The modules the crossing and hazard demos reach at run time, unmodified,
so the next commit's trims and local changes show as a diff against
upstream.
- CooperativeLearner subclasses Learner; the InstrumentedLearner hooks
  become the optional diagnostics.Instrumented mixin.
- route_field imports terrain_warning lazily.
- Receiver modes other than legacy are refused (receiver_fitting is not
  vendored); _receiver_acceptance short-circuits exactly as
  receiver_fitting.acceptance does for a legacy receiver.
- Six glue modules keep only the definitions the demos reach.
- results.py writes results.json, rows.json and REPORT.md in place of
  upstream's figure modules; hazard_demo gains --steps and --seeds.
- VENDORED.md records the commit, the module list, every local change
  and the measured gate.
black and ruff skip the vendored files, which keep upstream's formatting.
tests/coph holds 12 upstream test files, trimmed where they reach modules
that are not vendored. tests/test_coph.py runs both demos at a short
horizon through the CLI, pins the crossing smoke to numbers upstream's
code produces at the same horizon, and checks the two untanglings.
Linux CI measured one_way_01 at 80817-80834 bytes against Windows' 79488,
with the paths equal to 1e-6. The first export's covariance is round-off
(8 identical bootstrap members), and whether np.cov prints exact zeros or
~1e-35 residues depends on numpy's summation order, which moves the
packet's compact-JSON size. The smoke now pins each arm's packets (sender,
support points, anchors, sources), deliveries and geometry events, and
VENDORED.md notes the finding for the goldens.
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