Skip to content

nav: the belief-material controller's contract and inputs (C1) - #1071

Merged
transfix merged 3 commits into
masterfrom
feat/nav-belief-material-controller-c1
Nov 9, 2026
Merged

transfix merged 3 commits into
masterfrom
feat/nav-belief-material-controller-c1

Conversation

@transfix

@transfix transfix commented Nov 8, 2026

Copy link
Copy Markdown
Owner

This is C1 of docs/roadmap/NAV-BELIEF-MATERIAL-CONTROLLER-ROADMAP.md (spec merged in #1053): the C++ twin of GRL-SNAM's BeliefMaterialController, up to the model inputs. On "Yes, start C1", the spec's decisions E1–E10 are settled on the recommended column, and the spec now records that (§9).

What's in it

inc/cvc/nav/belief_material_controller.h is compiled with -ffp-contract=off (/fp:precise on MSVC), like belief_material.cpp. It has:

  • belief_material_contract, the .cvcnm meta record (grl_snam.belief_material).
    • from_meta uses a small JSON reader that behaves like Python's json.loads: it accepts NaN/Infinity, the last of duplicate keys wins, \u escapes decode, numbers are read locale-free, and trailing text is refused.
    • Only JSON numbers and a string frame are accepted (E6).
    • to_meta writes exactly the bytes of Python's json.dumps(sort_keys=True), with Python's float repr (20.0, 1e-05, 1e+16, 5e-324).
  • belief_header_mismatches / belief_runtime_mismatches: the §1.2 and §1.3 checks. They compare within 1e-6 (E7) and use Python's field names.
  • material_config_for: the material_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, in from_cvcnm's order, plus 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. Distances are computed in f64 from the f32 centres; equal distances keep row-major order (E5).

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.

The golden comes from Python

src/cvc/tests/data/belief_material_controller_golden.{json,cvcnm} is written by GRL-SNAM's grl_snam.tools.belief_material_controller_golden (CVC-Lab/GRL-SNAM#164). That generator is stacked on CVC-Lab/GRL-SNAM#163, the E5 stable sort and E6 strict types. Every float32 is stored as raw bits.

nav_belief_material_controller_test (11 tests) reproduces it:

case tier
G1 28 meta strings: values and to_meta for the 10 accepted, a refusal for the 18 others BIT
G2 the golden .cvcnm against 12 belief/patch settings refused fields, in order
G3 6 material_configs, plus material_config_for on 8 cell widths refused fields; gate constants
G4 31 token sets: 3 belief cases × 3 ticks × 3 agents, a 7.5 m scale, an empty obstacle set BIT (dist: 1 ulp, numpy's norm may use BLAS)
G5 each agent's visible obstacles at max_obstacles 36 and 5, and a 9 × 9 scene of equal distances BIT

The golden carries the planes the tokens are cropped from. The test checks that their SHA-256 equals belief_material_golden.json's, so they are the planes libcvc's own belief kernels build.

bindings/pycvc/test_pycvc_nav_belief_controller.py checks the bindings against the same golden.

Checked locally

Windows, MSVC 19.44, Release, deps from the .deps cvcpkg prefix, master merged in:

  • nav_belief_material_controller_test: 11/11;
  • nav_belief_material_test: 19/19;
  • CTest pycvc_nav_belief_controller, pycvc_nav_belief and pycvc_nav_train: passed;
  • clang-format 18 clean on the new C++ files.

Default-off and additive: nothing existing calls the new code.

Next

C2 (decide, decide_batch, rollout, material_drive_for, goldens G6–G7) extends the GRL-SNAM generator first. C2 is not started.

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.
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 merged commit 038e347 into master Nov 9, 2026
25 of 29 checks passed
@transfix
transfix deleted the feat/nav-belief-material-controller-c1 branch November 9, 2026 02:42
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