This document describes the JSON data format used to store simulation trajectories for the algovivo system. Trajectories capture the complete state of a simulation over time, enabling deterministic playback, testing, and video rendering.
The trajectory system stores simulation data in two complementary formats:
mesh.json). test/nn/generateTrajectory.js130.json, 1.json). test/nn/generateTrajectory.js63-64This separation allows efficient storage by avoiding duplication of static mesh data across timesteps. The trajectory format is consumed by the Trajectory loader class, the rendering utilities, and the neural policy tests. test/nn/trajectory.test.js27-32 utils/trajectory/renderTrajectory.js38-39
The mesh definition file contains the complete geometric and topological description of a simulated creature. This data remains constant throughout a trajectory.
Sources: test/nn/generateTrajectory.js29-35 utils/py/test/trajectory/data/mesh.json1 utils/trajectory/renderTrajectory.js67-68
| Field | Type | Required | Purpose |
|---|---|---|---|
pos | Array<[number, number]> | Yes | Initial 2D vertex positions. utils/py/test/trajectory/data/mesh.json1 |
triangles | Array<[number, number, number]> | Yes | Vertex index triples defining triangular mesh elements. utils/py/test/trajectory/data/mesh.json1 |
muscles | Array<[number, number]> | No | Vertex index pairs defining muscle connections. utils/py/test/trajectory/data/mesh.json1 |
l0 | Array<number> | If muscles present | Rest length for each muscle. utils/py/test/trajectory/data/mesh.json1 |
rsi | Array<Array<[number, number]>> | If triangles present | Reference shape inverse matrices for elasticity. utils/py/test/trajectory/data/mesh.json1 |
sorted_vertex_ids | Array<number> | For rendering | Order in which vertices are drawn for depth. utils/trajectory/renderTrajectory.js67 |
Sources: test/nn/generateTrajectory.js29-35 utils/py/test/trajectory/data/mesh.json1 utils/trajectory/renderTrajectory.js65-69
Each simulation step is generated by a simulation loop (e.g., in generateTrajectory.js) and stored as an individual JSON file. Steps are numbered sequentially starting from 0. test/nn/generateTrajectory.js45-65
Sources: test/nn/generateTrajectory.js47-61
| Field | Source | Description |
|---|---|---|
pos0 | system.pos0.toArray() | Vertex positions at the start of the step. test/nn/generateTrajectory.js48 |
vel0 | system.vel0.toArray() | Vertex velocities at the start of the step. test/nn/generateTrajectory.js49 |
a0 | system.a.toArray() | Muscle activations at the start of the step. test/nn/generateTrajectory.js50 |
pos1 | system.pos0.toArray() | Vertex positions after system.step(). test/nn/generateTrajectory.js57 |
vel1 | system.vel0.toArray() | Vertex velocities after system.step(). test/nn/generateTrajectory.js58 |
a1 | system.a.toArray() | Muscle activations after policy.step(). test/nn/generateTrajectory.js59 |
policy_input | policyTrace.policyInput | The proprioceptive input vector fed to the MLP. test/nn/generateTrajectory.js60 |
policy_output | policyTrace.policyOutput | The raw output of the neural network before clamping. test/nn/generateTrajectory.js61 |
Sources: test/nn/generateTrajectory.js47-61
The simulation state is recorded by extracting data from the System and MLPPolicy instances. The MLPPolicy.step method supports a trace argument specifically for capturing internal signals for trajectory logging. algovivo/nn/MLPPolicy.js92-97
Sources: test/nn/generateTrajectory.js45-65
The trajectory system interacts with the memory manager to ensure that tensor data is correctly serialized. In JavaScript, toArray() is used to convert internal WebAssembly memory slots to standard JavaScript arrays. algovivo/nn/MLPPolicy.js95-96 test/nn/generateTrajectory.js48-50
In the MLPPolicy, the input and output tensors are converted using this.input.toArray() and da.toArray() respectively, which are then assigned to the policyTrace object if provided during the step() call. algovivo/nn/MLPPolicy.js92-97
During rendering, these arrays are re-loaded into the system using system.pos.set(state.pos) and system.a.set(state.a). utils/trajectory/renderTrajectory.js10-11
Sources: algovivo/nn/MLPPolicy.js92-97 test/nn/generateTrajectory.js47-61 utils/trajectory/renderTrajectory.js8-15