Skip to content

Ariadne gym: the drive a twin replays (plants()' drive), and intents from Python - #1284

Merged
transfix merged 40 commits into
masterfrom
feat/gym-drive-intents
Nov 17, 2026
Merged

transfix merged 40 commits into
masterfrom
feat/gym-drive-intents

Conversation

@transfix

Copy link
Copy Markdown
Owner

Two generic hooks a differentiable twin of the world gym needs to judge an external force in the gym itself. Stacked on #1263 (base feat/gym-twin-exports).

What

  • plants() reports the drive that commanded each agent (entity_plant::drive, a new entity_drive): the policy's coefficients (alpha, beta, gamma), the point the drive steered for (its carrot, world m) and the external force it summed (force_x, force_y, m/s², world frame), on the last tick. It reads sim_world's drive telemetry, which WorldVehicles::set_drive_telemetry(bool) turns on for every fleet. The gym turns it on by default (gym_options::drive_telemetry, pycvc.WorldGym(..., drive_telemetry=True)). known is false until a tick has run.
  • pycvc.WorldGym.set_intent(id, steer=, accel=, mode=, weight=, force=(fx, fy), force_steers=), intent(id) and clear_intent(id): WorldVehicles::set_intent from Python, with the signature pycvc.WorldEntities.set_intent already has. A force then acts on the drive while the navigator drives. A step's finite command still replaces the drive for that step.
  • ARIADNE.md's twin section describes both.

Why

With these, a twin can replay the gym's own controller on a tick, a force included, from the gym's state: the coefficients, the carrot, the force, then the plant. Before, it could only replay the plant given the commands. The first user is a private comm-force trainer that runs on GRL-SNAM's grl_snam.gym_twin. It sets its force as an intent, and on dynamic4w the twin's command matches the gym's to float precision on most ticks. Nothing here is specific to it: any outside field or controller on a gym vehicle (a wind, a formation term, a human nudge) is judged the same way.

Checks

On this branch (built locally, Release, Jolt):

  • ariadne_scene_world_test: 50/50, including the new AriadneWorldGym.TheDriveATwinReplaysAndTheForceItSummed. It checks the drive is not known before a tick and known after, that the force summed is the intent's, that the other agent has none, and that the carrot lies toward the goal. It also checks that two gyms on one seed, one capturing and one not, drive bit for bit the same over 30 ticks.
  • bindings/pycvc/test_pycvc_gym.py: 74 checks, including the new drive and intent checks. They check set_intent / intent / clear_intent, that an unknown id is refused, that a force must be two numbers, and that the force moves only its own agent against the same episode without it.

The same change on a merge with #1275 (the 0.06 s tick) also passes: 48/48 and 78 checks. Merging this after #1275 conflicts in one place: both add a trailing argument to pycvc.WorldGym's constructor (tick, drive_telemetry). The fix is to keep both.

A world document driven headless by reset(seed), step(steer, accel) and
observe(), with a reward of the user's and an episode log: one app per gym,
its clock paused, every draw seeded. WorldVehicles gains per-tick commands,
held goals, reseeding and per-step contact counts; SceneWorld::restart hands
the vehicles the new ground bodies. GymCars and --gym run the cars template's
controllers in a world document; world_gym.ari/.py are the example.
…a world per episode

WorldVehicles runs jolt, kinematic, dynamic and dynamic4w entities, a navigator per plant (the
dynamic models' chassis in a world of their own holding the world's colliders); entity_spec and
vehicles.spawn.plant name it; across plants vehicles touch by their chassis boxes, and cvcGL draws a
vehicle with no chassis from its pose. A world's terrain alone is its ground
(SceneWorldBody::ground), so a building is an obstacle. WorldGym's regenerate makes a generated
world per episode from the reset's seed (SceneWorld::regenerate_world). GymCars and --gym take the
cars template's plant names; dyn_bike_plant and dyn_4w_plant gain add_desc.
A vehicle in world_gym.ari's generated world (seed 1, agent 3 at about
(-51.7, 46.4)) fell straight down from its first step. The terrain
collider has no hole there: a raycast at every free grid cell hits the
ground. The spot is a slope of about 0.75, and nav_plant placed every
start level at one ground sample (the nearest 2 m grid cell under the
rear axle) plus its resting height. Facing uphill, the Humvee's origin
started under the ground at its own centre and its nose more than a
metre deep; a body that starts below a height field falls through it.

nav_plant: with ground_height set, a start is tilted onto the plane
fitted to the ground under its chassis, its origin its resting height
above that plane, then lifted clear of the highest ground under the
chassis and the wheels at full reach. Level ground and a constant
ground_z keep the pose they had.

WorldVehicles: every plant's ground height (and height_at) is the world's
terrain where it has one, the physics collider's own heights, else the
grid bilinear between its samples, not the nearest sample.

Tests: a downward raycast at every free cell of the generated world finds
the ground at the grid's height; twelve Humvees placed on its slopes
(1 in 3 to 1 in 1, up and across) start above the ground and are on it
3 s later (two fell to z -27 before).
Vehicles start on a slope, not inside it
Each terrain cell took its material from one raster sample, its NE corner where the raster and
the mesh share samples. On a steep shore that corner can be dry or shallow while the cell is
metres deep, so the navigator and the physics took deep water for drivable ground: 151 cells
deeper than 0.5 m on world_gym.ari's generated world, the deepest at -1.91 m.

The materials stage now classes each cell's water by the mean of its corners against the sea,
with derived_class's depths (deep below sea - 0.5, shallow below sea, sand for a dry cell the
raster called water). A prop's footprint keeps its own material.

Test: WorldGenerated.ACellsWaterIsTheMeshsDepth checks every ungraded cell's class against its
mean height.
add_world_geometry adds four static boxes around the rectangle the collide height fields cover
(world_bodies::edges): 2 m thick, 1 cm outside the edge, from 20 m below the lowest height to
20 m above the highest. They are not items and not ground, so a vehicle touching one has hit an
obstacle. SceneWorld keeps them as the terrain node's bodies, so they go and come with it.

world_gym.ari's generated world, seed 1: from agent 1's start (-122.9, -72.6) toward its goal on
the west shore, the vehicle slid down the slippery underwater slope and off the west edge in 14
of 18 runs (3 masses x 3 top speeds x nav@1 and world_gym.py's policy). Now 0 of 18; seeds 1-20
under both controllers have no agent out.

Tests: PhysicsWorldGeometry.NothingLeavesTheTerrainOverItsEdge (a box sliding at 15 m/s down a
mu 0.1 slope stops at the wall; rays down on the edge still meet the terrain) and
AriadneWorldGym.AGeneratedWorldsEdgeHoldsAVehicleIn (Humvees flat out at each edge stay in). The
body counts of generated and data worlds include the 4 walls.
What is at a generated world's edge is now a choice (generated_world_params::edge, world_edge):

- wall (the default): the invisible walls of the previous commit.
- shore: a band at the rim (15 % of half, 40-250 m) becomes coast. From the band's inner end the
  ground eases down to a beach sloping 1 in 50 to the waterline, then under the sea to the island
  preset's shelf depth at the edge. Ground already lower keeps its bed. It wraps any terrain
  generator (fbm, dem, registered), lots stay off the shore, and the sea goes on past the world:
  outer_sea() is a ring at the waterline out 6 km, which cvcGL draws under <id>_water. No walls.
- none: the edge is open.

world_geometry::edge_walls() says whether add_world_geometry adds the walls; a generated world sets
it from its edge (only wall), and every other world_geometry keeps them on.

Ariadne: a generated_world node's `edge: wall | shore | none`. pycvc: generate_world's "edge"
param, and info()["edge"]. docs/ARIADNE.md describes it.

Tests: WorldGenerated.AShoreEdgeLinesTheWorldWithABeachAndTheSea (deep water all round the rim, a
sand beach inside it, the relief untouched past the band, the outer sea ring),
PhysicsWorldGeometry.TheEdgeWallsCanBeLeftOut, AriadneSceneWorld.AGeneratedWorldsEdgeCanBeAShore,
cvcgl_ariadne_realize (the drawn outer sea), test_pycvc_plant_host.py.
Rendered, the shore's blend from the relief to the beach was short enough (about 11 m on a 300 m
world) that high ground met the coast as a rock cliff, and the coastline ran dead straight. The
band is now 20 % of half (50-300 m), the blend takes its inner half (sea floor to waterline by
25 %, beach to 50 %), and the coastline lies up to 15 % of the band further in by a smooth wobble
the seed sets. The edge stays the sea floor and the relief past the band is untouched.
The shore's coast followed the world's square outline, corners and all. It now follows a rounded
square, |x|^4 + |y|^4 = half^4 (world_shore_roundness), so the corners curve away into the sea,
and its wobble is up to 35 % of the band on longer waves (2.5 and 0.8 bands), for bays and
headlands. The square's edge is still the sea floor everywhere and the relief past the band is
untouched; the test measures the band from the rounded edge.
…picker)

A generated_world node's edge was only its authored `edge:` key, so the terrain lab's World panel
could not change it. It is now a world.* key like the preset: world.edge (0 wall, 1 shore, 2 none),
seeded from the node, read on Regenerate, and part of the world's signature, so an edit marks the
world pending until Regenerate. world_controls.ari has an Edge combo (Wall, Shore, None) after
Water level. The walls follow the new world's colliders, and cvcGL draws or empties the outer sea
on the swap. pycvc_gl.cars logs it with the other world keys.

Tests: AriadneSceneWorld.TheWorldsEdgeIsALiveSetting (seeded 0; 1 waits, then Regenerate makes a
shore world with no walls; 0 brings them back) and the loader's world_controls check for the
Edge picker. Checked drawn too: an offscreen host switched a walled world to Shore and
regenerated it. 711/711 related ctest.
Terrain lab: an Edge picker for the generated world (world.edge)
Generated worlds: water by each cell's depth, and a choice of world edge (walls, shore, none)
Conflict in src/cvc/world/generated_world.cpp: master's #1203 made the
terrain generators each app's own (generators(app), terrainFrom), and
#1215 had put the shore edge (shore_terrain) in the old make_terrain.
shore_terrain now sits beside terrainFrom, which wraps any app's
generator in it, so make_terrain(app, p) and to_world_params(app, p)
both get the shore.

#1203 also broke code that only feat/world-gym has: its edge and gym
tests call generate_world, make_terrain and load_string without an app.
They make one first now.

cvc-cli's cmd_trace and three ariadne_runtime_test rich-text tests do
not build on master itself after #1203. This takes #1225's fix for them
line for line, so that #1170 builds; the two merge cleanly either way.
Master's #1233 (entity intents) conflicts with this branch's plants, where
each plant has its own group and navigator, not one sim. Intents now run per
group: the drive's external force is each group's, sampled by its
navigator's own agent indices. apply_intents overrides each entity's command
on its group's sim and sets or clears each group's ext_force. An external
entity's hold reads its speed from pose(), which every plant has.
before_step reads and applies the intents, then a gym's one-tick command
takes over (command.by "gym"), then each group steps.

entity_info keeps this branch's fields and adds master's command_steer,
command_accel and intent; the entity keeps both sides' members. ARIADNE.md
and the header say each plant's drive has its own force-steering switch.
…the 0.01 s clock, real time catching up 0.25 s a frame
Master's #1235 runs every plant in a scene world's one physics world (fleets per plant; dynamic
chassis boxes and kinematic boxes as bodies there; wheel poses). The gym's own plant groups (the
dynamic models in a world of their own, the bicycle with no body, the markers that drew it) give
way to it. Kept from L4 on master's fleets: a spawn's own plant (entity_spec::plant,
vehicles.spawn.plant), the gym's API (reseed, set_wander, command, set_goal, tick_seconds,
steps_per_tick, grid) and its per-tick command, the velocity, steer, goal and reach in
entity_info, contacts counted from the world's events (a kinematic box's obstacles by its grid
footprint, two kinematic boxes by overlap), the terrain's own heights under the vehicles, and
world_reset with the new ground bodies.
…r water class again

Master's #1271 lowers the terrain mesh's waterline slivers at the end of the grade stage, after
the materials stage classed each cell's water by its corners' mean height. A cell round a lowered
sample kept the class of the ground before it (sand, or shallow water over half a metre deep), so
WorldGenerated.ACellsWaterIsTheMeshsDepth failed. The materials stage's rule is now cell_class(),
and the cells touching a lowered sample are classed by it again from the lowered mesh.
…in-exports

# Conflicts:
#	src/cvc/physics/dyn_4w_plant.cpp
#	src/cvc/physics/dyn_bike_plant.cpp
#	src/cvc/tests/ariadne_scene_world_test.cpp
# Conflicts:
#	src/cvc/ariadne/world_vehicles.cpp
…rom Python (pycvc.WorldGym.set_intent)

entity_plant gains entity_drive: the navigator's coefficients, carrot and the
external force its drive summed on the last tick, from sim_world's drive
telemetry, which WorldVehicles::set_drive_telemetry turns on (the gym's
default, gym_options::drive_telemetry; capturing changes nothing the drive
does). pycvc.WorldGym gets set_intent / intent / clear_intent, as
pycvc.WorldEntities has them, so a force acts on the drive while the
navigator drives. Tests: AriadneWorldGym.TheDriveATwinReplaysAndTheForceItSummed
and test_pycvc_gym's drive and intent checks; ARIADNE.md's twin section.
…ds (fields, plants)

Ariadne gym: what a differentiable twin of the world reads (fields, plants)
Base automatically changed from feat/gym-twin-exports to feat/world-gym November 16, 2026 19:19
…le worlds on the 0.01 s clock, real time catching up 0.25 s

One simulation tick: 0.06 s by default everywhere, vehicle worlds on the 0.01 s clock, real time catching up 0.25 s
…ive-intents

# Conflicts:
#	bindings/pycvc/pycvc_gym.i
Base automatically changed from feat/world-gym to master November 17, 2026 08:25
@transfix
transfix enabled auto-merge November 17, 2026 09:20
@transfix
transfix merged commit 44628e8 into master Nov 17, 2026
29 checks passed
@transfix
transfix deleted the feat/gym-drive-intents branch November 17, 2026 12:16
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