Skip to content

belief-material controller: the golden libcvc's C++ twin reproduces - #164

Merged
transfix merged 1 commit into
mainfrom
feat/belief-material-controller-golden
Nov 9, 2026
Merged

transfix merged 1 commit into
mainfrom
feat/belief-material-controller-golden

Conversation

@transfix

@transfix transfix commented Nov 8, 2026

Copy link
Copy Markdown
Contributor

This is T-a of libcvc's belief-material controller spec (transfix/libcvc#1053, docs/roadmap/NAV-BELIEF-MATERIAL-CONTROLLER-ROADMAP.md §6). The Python controller is the reference: this generator writes the golden, libcvc commits it in src/cvc/tests/data, and libcvc's C1 PR reproduces every case.

Stacked on #163 (E5's stable obstacle order and E6's strict contract types), since the golden pins both. Once #163 merges, GitHub retargets this PR to main.

Usage: python -m grl_snam.tools.belief_material_controller_golden --out DIR writes belief_material_controller_golden.json (336 KB) and belief_material_controller_golden.cvcnm (241 KB). It covers the C1 cases (G1–G5 in the spec):

key what records
contract 28 meta strings through from_meta: defaults, partial and integer records, repr edge cases (1e+16, 5e-324, 0.0001, 9999999999999998.0), other keys with NaN/-Infinity, a duplicate key, then 18 refusals accepted: the parsed values and to_meta(); refused: only that it was refused
header_check the golden .cvcnm against 12 belief/patch settings: one field each, one case with two, and two within the 1e-6 tolerance the fields the refusal names, in order
runtime_check 6 material_config constant sets (float32 k_sharp/d_hat, as libcvc holds them) the fields check_runtime names
material_config_for the gate horizon and margin MaterialRuntime derives on 8 cell widths (0.3 to 70 m) horizon cells, margin, gate constants
obstacles scan_visible_geometry after each agent's sense tick on the belief golden's 32 × 32 scene, max_obstacles 36 and 5; plus a 9 × 9 scene of equal distances centres, radii, weights (f32 bits) and each agent's last_visible
planes / tokens build_belief_material_controller_inputs for 3 belief cases × 3 ticks × 3 agents, a 7.5 m scale variant and a no-obstacle variant, on the planes it records obs_feats, goal_feats, the 3 × 9 × 9 patch (f32 bits)

Determinism:

  • The net (d_tok 16, nhead 2, 1 layer, d_risk 16, P 9 over 36 m) takes its weights from numpy's PCG64 stream, not torch's initialisers, so the file does not depend on the torch version. Both lambda heads' last biases are 0, so the lambdas sit mid-range for C2's gate cases.
  • Two runs give identical bytes. test_belief_material_controller_golden.py regenerates both files and compares them with tests/fixtures/belief_material_controller_golden/.
  • The JSON is written as bytes, and .gitattributes marks the fixtures -text, so line endings match on every OS.

Tests: 42 passed locally (Windows, cvcpkg cp312, torch 2.8 CPU): the new golden test, test_belief_material_controller.py and test_austin_material_evaluation.py. black --check and ruff check are clean. docs/MATERIAL_NAV.md's parity table has a row for the golden.

C2 extends the generator with decide and rollout (G6–G7).

T-a of libcvc's NAV-BELIEF-MATERIAL-CONTROLLER-ROADMAP.md (transfix/libcvc#1053,
§6): the Python controller is the reference. The generator writes
belief_material_controller_golden.{json,cvcnm}. libcvc commits them in
src/cvc/tests/data, and its C1 test reproduces every case.

Run python -m grl_snam.tools.belief_material_controller_golden --out DIR.
It covers the C1 cases (the spec's G1-G5):

- contract: 28 meta strings through from_meta. Accepted ones record the parsed
  values and to_meta(); refused ones record only the refusal.
- header_check: the golden .cvcnm against 12 belief/patch settings. Each
  records the fields the refusal names: one field each, one case with two, and
  two within the 1e-6 tolerance.
- runtime_check: 6 material_config constant sets (float32 k_sharp/d_hat, as
  libcvc holds them).
- material_config_for: the gate horizon and margin MaterialRuntime derives on
  8 cell widths.
- obstacles: scan_visible_geometry after each agent's sense tick on the
  belief golden's scene (max_obstacles 36 and 5), plus a 9 x 9 scene of equal
  distances.
- tokens: build_belief_material_controller_inputs for 3 belief cases x 3 ticks
  x 3 agents, plus a 7.5 m scale and a no-obstacle variant.

Float32 values are written as raw bits. The net (d_tok 16, 1 layer, P 9 over
36 m) takes its weights from numpy's PCG64 stream, so the file does not depend
on torch's initialisers. The test regenerates both files and compares bytes
with tests/fixtures. .gitattributes keeps git from converting their line
endings.

C2 adds decide and rollout (G6-G7).
@transfix
transfix force-pushed the feat/belief-material-controller-golden branch from e6c3adb to bde7b6d Compare November 9, 2026 01:18
@transfix
transfix changed the base branch from fix/belief-material-stable-strict to main November 9, 2026 01:18
transfix added a commit to transfix/libcvc that referenced this pull request Nov 9, 2026
* nav: the belief-material controller's contract and inputs (C1)

C1 of docs/roadmap/NAV-BELIEF-MATERIAL-CONTROLLER-ROADMAP.md: the C++ twin of
GRL-SNAM's BeliefMaterialController, up to the model inputs. Joe settled
decisions E1-E10 on the recommended column ("Yes, start C1"), and the spec now
records them as settled.

inc/cvc/nav/belief_material_controller.h (built with -ffp-contract=off):
- belief_material_contract: the .cvcnm meta record (grl_snam.belief_material).
  from_meta parses it with a small JSON reader that behaves like Python's
  json.loads: NaN/Infinity, last duplicate key wins, locale-free numbers. It
  accepts only JSON numbers and a string frame (E6). to_meta writes
  byte-for-byte what Python's json.dumps(sort_keys=True) writes, using Python's
  float repr.
- belief_header_mismatches: the .cvcnm v2 belief block against the belief and
  patch settings, within 1e-6 (E7).
- belief_runtime_mismatches: a material_config against the contract.
- material_config_for: the config a contract implies on a grid. The gate
  horizon is Python's 25 m rounded half-even to cells; libcvc's 12-cell
  default would look 180 m ahead on the Austin 15 m grid.
- belief_material_controller: a loaded net that passed those checks, with
  check_runtime.
- build_belief_material_controller_inputs: robot-relative float32 tokens in
  numpy's operation order, and the 3-channel patch centred on the float32
  position.
- visible_obstacles: the twin of scan_visible_geometry. Equal distances are
  kept in row-major order (E5).

The golden (G1-G5) is written by GRL-SNAM
(grl_snam.tools.belief_material_controller_golden, CVC-Lab/GRL-SNAM#164, on
#163's E5/E6 changes) and committed in src/cvc/tests/data.
nav_belief_material_controller_test reproduces it bit for bit; the goal
token's dist may differ by 1 ulp because numpy's norm can go through BLAS. The
planes the tokens are cropped from hash to belief_material_golden.json's
values, so they are libcvc's own belief planes.

pycvc gains nav_belief_material_contract, nav_belief_material_contract_to_meta,
nav_belief_material_check_cvcnm, nav_visible_obstacles and
nav_belief_material_controller_inputs; refusals raise ValueError.
test_pycvc_nav_belief_controller.py checks them against the same golden.

* nav: keep a JSON object's keys and values in parallel vectors

clang-tsan's build (clang with libstdc++ 13) refused json_value's
std::vector<std::pair<std::string, json_value>>: the pair needs json_value
complete inside its own definition. A vector of an incomplete type is fine
in C++17, so the object now holds obj_keys and obj_vals side by side.
@transfix transfix closed this Nov 9, 2026
@transfix transfix reopened this Nov 9, 2026
@transfix
transfix merged commit a9b77a0 into main Nov 9, 2026
5 of 6 checks passed
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