Move co-sim behavior configuration to scenario YAML - #27
Draft
kawaeeeee wants to merge 2 commits into
Draft
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Moves CARLA/TeraSim co-simulation behavior settings from process environment variables into a typed top-level
cosimsection in each scenario YAML. CARLA and TeraSim now resolve the same Pydantic model, log the effective configuration, and persist it with the simulation output.Deployment-specific values remain outside the scenario: CARLA/TeraSim hosts and ports, the direct gRPC address, and the scenario path continue to be supplied through CLI arguments or deployment environment variables.
Motivation
Previously, behavioral configuration was split across two processes and two independent groups of environment variables:
That arrangement had no shared schema, made invalid values fail inconsistently, and allowed the CARLA and TeraSim sides to run with different effective settings. Reproducing a run also required preserving container environment in addition to the scenario file, while the final resolved values were not saved with the output.
The project is still in development and has no deployed compatibility requirement, so the old behavioral environment-variable readers are removed instead of retaining a second configuration source. This keeps precedence and debugging straightforward: scenario YAML first, then typed model defaults for omitted fields.
Design
One typed model for both processes.
terasim_service.cosim_config.CosimConfigowns all behavioral settings and nested validation:The model covers:
actor_scope— enable filtering, select the center actor, and configure its radius.lane_relative_position— emit reconstructed lane-relative positions in TeraSim and prefer them in CARLA.batch— batch CARLA transform updates and actor spawn commands.spawn— configure CARLA spawn Z clearance.backoff— configure initial and maximum actor-spawn failure delays.idle_state_write_interval_seconds— rate-limit Redis state refreshes while the Redis-backed plugin is idle.Unknown keys and negative distances/intervals are rejected. If
backoff.max_secondsis belowinitial_seconds, it is clamped to the initial delay to preserve the runtime backoff invariant.Configuration flow. The FastAPI simulation path and
run_direct.pyparse the scenario and inject the same model intoTeraSimCoSimPlugin/TeraSimCoSimDirectPlugin.CarlaCosimloads the same scenario before connecting to CARLA and uses the CARLA-relevant fields from that model. There is no CARLA-side or TeraSim-side environment fallback.Effective configuration. Both sides log the fully resolved model. The TeraSim plugin additionally writes
cosim_effective_config.yamlinto the individual simulation output directory next toterasim_cosim_plugin.log, so a run carries the exact behavior configuration used after defaults were applied.Deployment boundary. Runtime topology stays configurable outside the scenario.
--carla_host,--carla_port,--terasim_host,--terasim_port,--direct_addr,--grpc_host, and--grpc_portare unchanged. Only simulation behavior moves into YAML.Defaults
The shared defaults favor the current dense co-simulation path:
AV, 300 m radiuscosim_mcity.yamlandcosim_town01.yamlinclude the complete section explicitly. Individual scenarios can disable actor filtering or batching by setting the corresponding YAML values tofalse.Files
terasim_service/cosim_config.py— shared Pydantic models, scenario loader, effective-config logging, and YAML persistence.plugins/cosim.py— consumes the injected model for actor scope, lane-relative state, and idle writes; saves the effective config.plugins/cosim_direct.py— accepts and forwards the shared model to the base plugin.api.pyandrun_direct.py— load the scenariocosimsection for Redis/FastAPI and direct gRPC runners.utils/carla/cosim.py— replaces CARLA behavioral environment reads with the shared model.examples/scenarios/cosim_{mcity,town01}.yaml— explicit typed co-sim settings.docker-compose.cosim-odaiba-3cosim-direct.yml— removes behavioral environment variables; the selected scenario owns those values.docs/cosim_configuration.md— schema, defaults, deployment boundary, and effective-config location.Testing
tests/test_service/test_cosim_config.py: 8 passing cases covering defaults, shared typed parsing, explicit YAML disablement, invalid/unknown value rejection, and effective-config persistence.E,F,W,C90,Icheck on the shared model and its tests.terasim-service:integrationimage:cosim_town01.yamlresolves actor filtering and batching as enabled.TeraSimCoSimPluginreceives the configured actor scope and idle interval.cosim_effective_config.yamlis written successfully.Notes
This intentionally removes support for the former behavioral
CARLA_COSIM_*andTERASIM_COSIM_*environment variables. Setting those names no longer changes simulation behavior. Deployment environment variables for connection details remain supported.The Odaiba scenario referenced by
docker-compose.cosim-odaiba-3cosim-direct.ymlis not tracked in this repository; that scenario must include its owncosimsection when supplied externally.