Skip to content

Time Stepping and Determinism#

This page gives the clocks of the simulators, the time at which a command applies, and the conditions for repeatable runs.

Sources: Game/Config/DefaultEngine.ini, Game/Source/Acres/AcresCommandTiming.h, AcresSimControl.h, Game/Core/Source/AcresCoreBatch.h.

Clocks#

Item Value
Physics step of the game 1/120 s (AsyncFixedTimeStepSize=0.008333333333333333, bTickPhysicsAsync=True)
Physics time of one frame, at most 0.1 s, 12 steps (MaxPhysicsDeltaTime=0.1)
Control step of the bridges, the run-time library and ACRES Core 0.1 s (12 physics steps)
Clock frame of the sensor stream Each physics step

The game renders frames at its own rate. The physics thread runs the steps that the frame time asks for, at most 12. A frame that is longer than 0.1 s thus makes the simulation slower than real time.

When a Command Applies#

Time in ACRES: in a free run the game maps the arrival time of each command onto the solver interval of the frame, and the first physics step at or after that time applies the command. The sensors sample on the physics steps of 1/120 s. In lockstep each frame advances one physics step and the next step waits for the sensors. Physics steps, commands, sensor samples and lockstep FREE RUN: A COMMAND APPLIES AT THE STEP THAT AGREES WITH ITS ARRIVAL TIME Wall clock socket reads, one for each frame Solver time physics steps of 1/120 s read n-1 read n read n+1 slow frame, 50 ms 1 2 3 4 5 6 solver interval of frame n: 6 physics steps a command arrives (50 Hz) a step applies a command The queue keeps the order and the spacing of the commands. Without the queue, the 3 commands reach step 1 together. SENSOR SAMPLES ON THE PHYSICS STEPS, 0.2 S OF SIMULATION TIME step 0 step 12 step 24 physics steps, 120 Hz IMU, 120 Hz INS, 100 Hz DBW reports, 50 Hz CAN signals, 20 Hz LiDAR, camera, GNSS, 10 Hz LOCKSTEP: A REQUEST OF 3 STEPS held step 1 wait for the sensors step 2 wait for the sensors step 3 wait for the sensors barriers, reply held step request Each frame advances the solver by one physics step. The world does not move between two requests.
A command applies at the physics step that agrees with its arrival time. The sensors sample on the physics steps. In lockstep, a request runs its steps and waits for the sensors. Open the diagram

The game reads the sockets one time in each rendered frame. A long frame has more than one physics step. When all messages of the frame apply at its first step, the other steps get no message. A controller at 50 Hz then looks silent, and the drive-by-wire timeout of 0.1 s trips.

Thus a receiver thread stamps each message with its arrival time on the wall clock. At each read, the game maps the wall-clock interval since the last read onto the simulation interval that the frame advances. The first physics step at or after the mapped time takes the message. The steps of a long frame thus see the commands in the sequence and at the spacing of their arrival.

In lockstep, each command applies at the next step, as the step request expects.

Lockstep#

-Lockstep (or -SimControl=PORT and the state 2) holds the world. A step request of N steps does these steps:

The flow of one lockstep step request: the client sends commands and a step request, the simulator releases the world for N frames with one physics step in each frame, holds the world, lets the sensors finish, sends a barrier on each data channel and then sends the reply. CLIENT GAME OR CORE SERVER DATA CHANNELS 1 Send the commands on the vehicle bridge, before the step request Vehicle bridge the commands go into the command queue of the agent commands 2 Send the step request {"op":"step","steps":N} 3 Start the request frame time = one physics step, 1/120 s wait until no step is in progress 4 Release the world for one frame exactly one physics step for each agent the queued commands apply apply at the next step 5 Hold the world while sensors work the sensors complete the scans and images that were due in the step steps 4 and 5: N times 6 Send a barrier on each channel the N steps are complete, the world is held and all sensors are idle Barrier: sensor stream frame type 6, payload step S Barrier: vehicle bridge {"type":"barrier","step":S} Barrier: CAN transport frame 0xFF1E, payload step S 7 Send the reply {"ok":true,"step":S,"barrier":S} 8 Receive the reply S is the physics step that the world reached the client waits 9 Read each channel to its barrier. All data of the N steps is before the barrier. sensor data and reports of the steps, then the barrier
One step request. The world advances one physics step in each frame. The reply comes after the barrier on each data channel. Open the diagram
  1. It sets a fixed frame time of one physics step. Chaos then runs exactly one step in each frame.
  2. It releases the world for N frames and holds it again.
  3. While the world is held, the vehicle pawns keep ticking. The sensors finish their scans and images. The bridges send their reports.
  4. A barrier goes into each sensor stream and each vehicle bridge.
  5. The reply goes to the client after the N steps, when the sensors of each agent are idle.

-LockstepFrameSteps lets one frame run the steps up to the next sensor sample, at most 12. The frames between sensor samples then are not rendered.

For many episodes (training, evaluation), these options also cut the frames that nobody reads. The physics does not change.

  • -LockstepFrameSteps.
  • -SensorCameraRearHz=2: the rear camera at the rate that the perception of the vehicle reads it.
  • -ResX=320 -ResY=180 -ForceRes and main-view show flags off (-ExecCmds=ShowFlag.DynamicShadows 0,...).

Warning

Keep Lumen and the reflections of the main view on. Without a ray-tracing feature, the view builds no ray-tracing scene, and the GPU LiDAR stops the game (assertion LayerView.RayTracingSceneBufferSRV).

Tools/Performance/lockstep_benchmark.py --rollout measures the rate with these options.

ACRES Core#

A call of Batch.step runs 12 physics steps of 1/120 s for each environment. One thread steps one environment. The build of ACRES Core and of the run-time library uses -O2 -ffp-contract=off -fno-fast-math. Thus two machines with the same compiler give the same numbers, and the results do not depend on the number of threads (Tests/Runtime/determinism_tests.cpp).

Repeatable Runs#

  • In the game, use lockstep and an episode log. Tools/SimControl/lockstep_determinism.py starts the game more than one time with the same seed and the same commands, and compares the trajectories.
  • Outside lockstep, the frame timing changes the step at which a command applies. Thus two free runs are not equal.
  • Set the seeds: -EnvSeed= for the weather and -SensorSeed= for the sensor noise.
  • Send the commands only between two step requests. A command that arrives during a request applies at a step that changes with the timing.
  • Start each run in a new session. A reset does not set the physics clock or the soil water back to the start.
  • Outside lockstep, the soil water runs on its own thread. Its snapshots can reach the tires at slightly different steps (Results/Tractor/soil_weather_results.md). In lockstep, the physics thread steps the water grid itself.