Python API mode: AsyncMode False does not give deterministic synchronous stepping

Open
#745 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
python

Research direction

Start by tracing synchronous-mode handling and world ticking in utils/traffic.py, pilot_carla.py, and utils/carla_world_generator.py, then inspect how CarlaApiCamera receives and returns frames. Reproduce with AsyncMode: False and compare time_stamp and frame in the metrics CSV. Done means each brain decision advances one fixed step and receives that tick's camera image; the issue asks for design agreement before a PR.

Written by the indexing model from the issue text.

Description

Expected behavior
With AsyncMode: False, the simulation should advance exactly one fixed step per brain decision (e.g. fixed_delta_seconds = 0.05), and the brain should receive the camera image of that same tick. This is how models are usually evaluated with the CARLA Python API, and it makes runs repeatable.

Actual behavior

  1. utils/traffic.py enables synchronous_mode but never sets fixed_delta_seconds, so the simulated time per tick is variable.
  2. Two processes tick the world: pilot_carla.py after each execute(), and utils/carla_world_generator.py in its own 60 Hz loop. The simulation advances several ticks per decision.
  3. CarlaApiCamera keeps only the last image received by callback, so the brain may see an older frame.

Steps to reproduce
Run a config with AsyncMode: False and inspect the metrics CSV: time_stamp steps and frame increments are not constant per brain decision.

Environment
Kubuntu 26.04.1 (Ubuntu base, X11 session), kernel 7.0, Intel i9-12900K, 32 GB RAM, NVIDIA RTX 5070 12 GB (driver 580.178.04), Python 3.10, CARLA 0.9.15 in Docker, Behavior Metrics noetic-devel (dec1502), Python API mode.

Possible cause
See the three points above. PR #719 addressed asynchrony issues but not these. The branch feature/carla-python-api-metrics changes pilot_carla.py and carla_world_generator.py but keeps the generator ticking, and its brain assumes SimHz: 20 without enforcing it.

Possible solution
A FixedDelta key in the YAML applied with synchronous_mode; only the pilot ticks (the world generator stops ticking in synchronous mode); and the camera returns the image of the current frame (queue keyed by frame number).

I validated this approach inside a brain: with it, every row of the metrics CSV advances exactly 0.05 s and one frame, and a PilotNet model behaves as in a standalone synchronous driver (428 m driven in Town02 before failing at a sharp curve, versus crashing almost immediately in asynchronous mode).

Before writing the PR I would like to agree on the design, and on whether to base it on noetic-devel or on feature/carla-python-api-metrics.

Related: #742 (external CARLA server), #744 (weather from YAML).

cc @canveo (author of #719) Daniel Guerrero (author of feature/carla-python-api-metrics)

Dominant language
Python
Stars
65
Forks
53
Avg merge
7m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JdeRobot/BehaviorMetrics

All issues in JdeRobot/BehaviorMetrics

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.