Skip to content

pycvc: the physics world, its vehicles and the navigator's plant (P6) - #693

Merged
transfix merged 2 commits into
masterfrom
feat/pycvc-physics
Oct 18, 2026
Merged

transfix merged 2 commits into
masterfrom
feat/pycvc-physics

Conversation

@transfix

Copy link
Copy Markdown
Owner

P6 of the vehicle physics roadmap, the libcvc part: pycvc for the physics world, its vehicles and the navigator's plant. The gate is "Python reads the same values as C++", and it is met bit for bit. Stacked on P5, and opened once that merges.

What Python gets (bindings/pycvc/pycvc_physics.i)

  • physics_world takes world_config's fields as keywords.
    • Materials, and add_box / add_sphere / add_hull / add_mesh (a pycvc.geometry) / add_terrain (a pycvc.height_field).
    • state / states / set_state / forces and impulses.
    • Vehicles through drive (the driver model) or set_controls (the pedals). vehicle_state is a dict, with the wheels and the energy ledger.
    • step, contacts, raycast, save / restore, state_hash, and snapshot_json (C++'s own serializer).
    • Bodies and vehicles are ints, and a stale id raises as in C++.
  • vehicle_desc: humvee() and roboracer(), scalar fields read/write, axle(i), gear_ratios().
  • physics_binding: world_binding, the world in the state tree.
  • nav_plant: a world's vehicles as a sim_world's plant. It has its options as keywords, state(i) (with the measured tire use, load transfer, pitch and roll), vehicle(i), the drift, set_modulation, pull / publish, and terrain_config_of(desc, mu).
  • On a sim_world handle (pycvc_nav.i's):
    • nav_sim_world_set_plant(sim, plant) selects the plant, or nav's bicycle with None; nav_sim_world_plant_kind reports it;
    • set_terrain / set_terrain_config / terrain_settings / infeasible_entries (P5);
    • pull / publish (the sim_world's settings in the tree) and tick;
    • nav_sim_world_create takes "" for the built-in policy, as the C++ tests use. It also takes an optional map_id / n_planes, so an agent can have its own belief plane, as GRL-SNAM's Squad needs.
  • pycvc's state helpers gain state_comment, state_property and state_property_keys, so Python reads what a key says it is (unit, access, recommended min/max).
  • Lifetimes. A nav_plant keeps its world alive, a physics_binding its app and world, and a sim_world handle the plant set on it. The handle's destructor releases the plant after the world that borrowed it.

The gate

test_pycvc_physics.py (ctest pycvc_physics), 62 checks, all passing on Windows:

  • The golden scene. PhysicsJolt.CrossPlatformGoldenHash's exact scene, rebuilt through pycvc, gives C++'s pinned 70b2cc0bd34ea4be.
  • The C++ reference. physics_parity_test (new, 3 tests; ctest passes its path in CVC_PHYSICS_PARITY_EXE) writes its scenarios' values. Python rebuilds them call for call and requires the same, bit for bit: 3 state hashes and 22 values.
    • A Humvee through the driver model: 10.06 m, hash ad4f3e75970506ac on this box.
    • A sim_world's agent on the Jolt plant: 42.9 m, hash fab1bf415fa513f7.
  • Three readings of one state. A vehicle's state dict, the snapshot JSON and the physics.vehicles.<name>.* keys carry the same numbers. The tree's doubles round-trip exactly.
  • The rest.
    • save / restore reproduces a run.
    • Plant selection, kinematic ↔ Jolt. The plant keeps working after its Python names are deleted.
    • The sim_world's and the plant's keys with their metadata. A vmax and a modulation gain set in the tree reach the drive.
    • Terrain: the M1097A2's limits, the infeasible cells, and a config change rebuilding them.

Not in this PR

The rest of P6 is downstream and needs a libcvc release with P4–P6:

  • GRL-SNAM Squad(plant=…) and the nav_native plant option;
  • grl-snam-dbg gen-episodes / eval on Jolt, a KinematicsRecord schema bump and energy in the scorecards;
  • cvcdbg --plant / --vehicle / --clock and the HUD.

Test

  • Windows MSVC:
    • physics_parity_test 3/3 and test_pycvc_physics.py 59/59;
    • the related pycvc scripts pass unchanged: nav_train, state, world_geometry, world_units, world_clock, app, numpy, integration.
  • PR CI does not build pycvc. CI runs physics_parity_test, and pycvc runs locally (on Windows with CVC_DLL_DIRS naming the DLL directories).

Python drives the same world, vehicles and plant as C++ and reads the
same values (bindings/pycvc/pycvc_physics.i):
- physics_world: materials; box, sphere, hull, mesh and terrain bodies;
  state, states, set_state, forces; vehicles through drive or the
  pedals, with their state, wheels and energy ledger as dicts; step,
  contacts, raycast, save/restore, state_hash and snapshot_json (C++'s
  own serializer).
- vehicle_desc with the humvee() and roboracer() presets.
- physics_binding: world_binding, the world in the state tree.
- nav_plant: a world's vehicles as a sim_world's plant, with its
  state, drift, modulation, tree keys and terrain_config_of.
- On a sim_world handle: nav_sim_world_set_plant (None = nav's
  bicycle), plant_kind, set_terrain / set_terrain_config /
  terrain_settings / infeasible_entries, pull / publish and tick.
  nav_sim_world_create takes "" for the built-in policy.
- state_comment, state_property and state_property_keys read what a
  key says it is.
A nav_plant keeps its world alive, a physics_binding its app and world,
and a sim_world handle the plant set on it.

The gate, Python reads the same values as C++: test_pycvc_physics.py
rebuilds the cross-platform golden scene through pycvc and gets C++'s
pinned 70b2cc0bd34ea4be. It rebuilds physics_parity_test's scenarios
(a Humvee through the driver model, an agent on the Jolt plant) call
for call and matches their state hashes and values bit for bit, and a
vehicle's state, the snapshot JSON and the tree agree. 59 checks pass
on Windows; physics_parity_test (3 tests) is the C++ reference.
An optional map_id ((N,) plane ids) and n_planes put each agent in its
own belief plane, as sim_world's constructor allows: one per agent is
the fog-of-war twin, GRL-SNAM's Squad on the native runtime. An id
outside [0, n_planes) raises, and the arrays are released when the
constructor throws. test_pycvc_physics checks the shared default, the
private planes and the bad id (62 checks).
@transfix
transfix merged commit 607729d into master Oct 18, 2026
15 checks passed
@transfix
transfix deleted the feat/pycvc-physics branch October 18, 2026 18:15
transfix added a commit that referenced this pull request Oct 18, 2026
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