Skip to content

Latest commit

 

History

History
507 lines (373 loc) · 15.5 KB

simengine_usage.md

File metadata and controls

507 lines (373 loc) · 15.5 KB

SimEngine Usage Guide

This guide covers how to use SimEngine for closed-loop simulation, rollout generation, and model testing. SimEngine provides photorealistic simulation environments powered by 3D Gaussian Splatting.

Table of Contents


Quick Reference

cd projects/SimEngine

# Single-GPU testing
bash scripts/run_testing.sh <config> <checkpoint> <model_name> <data_type> <react_type> [<asset_name>]

# Multi-GPU distributed testing (8 GPUs)
bash scripts/run_ray_distributed_testing.sh <config> <checkpoint> <model_name> <data_type> <react_type> [<asset_name>]

# Multi-GPU distributed rollout (data generation)
bash scripts/run_ray_distributed_rollout.sh <config> <checkpoint> <model_name> <data_type> [<asset_name>]

Running Simulations

Basic Simulation

Run a basic simulation with default settings:

conda activate simengine
cd projects/SimEngine

python worldengine/runner/run_simulation.py \
    data_pkl_file_name=your_scenario.pkl

Parameters:

  • data_pkl_file_name: Scene pickle file in data/sim_engine/scenarios/

Custom Scenario Count

python worldengine/runner/run_simulation.py \
    data_pkl_file_name=your_scenario.pkl \
    num_scenarios=50 

Rollout Scripts

Rollout scripts run closed-loop simulation with an E2E planning model and reward computation. Useful for:

  • Generating training data for RL-based fine-tuning (with reward)
  • Rollout data augmentation/synthesis

Multi-GPU Distributed Rollout

For large-scale data generation:

export WORLDENGINE_ROOT=/path/to/WorldEngine

# The exporter expects these parent directories to exist.
mkdir -p "$WORLDENGINE_ROOT/data/alg_engine/openscene-synthetic/"{meta_datas,pdms_pkl,sensor_blobs}

bash "$WORLDENGINE_ROOT/projects/SimEngine/scripts/run_ray_distributed_rollout.sh" \
    "$WORLDENGINE_ROOT/projects/AlgEngine/configs/worldengine/e2e_vadv2_50pct.py" \
    "$WORLDENGINE_ROOT/data/alg_engine/ckpts/e2e_vadv2_50pct_ep8.pth" \
    e2e_vadv2_50pct \
    navtrain_50pct_collision \
    navtrain

Arguments:

  1. <config>: Model configuration file
  2. <checkpoint>: Trained model checkpoint
  3. <model_name>: Experiment name (creates output folder)
  4. <data_type>: Scenario directory name (e.g., navtrain_50pct_collision). The launcher reads data/sim_engine/scenarios/original/<data_type>/all_scenarios.pkl by default. For BWM inputs, see Rollouts from BWM Scenarios.
  5. <asset_name> (optional): Asset folder name under data/sim_engine/assets/. Defaults to <data_type> if not provided

Features:

  • Distributes scenarios across 8 GPUs (8 splits)
  • Each GPU processes 1/8 of scenarios in parallel
  • Automatically merges results and exports an AlgEngine dataset at the end
  • Resumes from previous runs (ENABLE_RESUME=true)

The output directory is $WORLDENGINE_ROOT/experiments/closed_loop_exps/<model_name>/<data_type>_NR/. asset_name selects the rendering assets; it does not change the output name.

After a successful run, continue with Verify the Exported Rollout Dataset and configure fine-tuning. Manual merge and export commands below are for processing existing results separately. Resume skips completed simulation scenarios, but export is not idempotent: an existing export with the same dataset name causes FileExistsError.

Rollouts from BWM Scenarios

First generate and publish BWM scenarios. For a job named my_scenario, the input is data/sim_engine/scenarios/augmented/my_scenario/all_scenarios.pkl.

The current rollout launcher selects original or augmented through its DATAFILE_FOLDER_PATH assignment, rather than a command-line argument. Before launching a BWM run, edit that assignment in projects/SimEngine/scripts/run_ray_distributed_rollout.sh to:

DATAFILE_FOLDER_PATH="data/sim_engine/scenarios/augmented/${DATA_TYPE}"

Then run the published scenario set with the original base scene assets:

export WORLDENGINE_ROOT=/path/to/WorldEngine
mkdir -p "$WORLDENGINE_ROOT/data/alg_engine/openscene-synthetic/"{meta_datas,pdms_pkl,sensor_blobs}

bash "$WORLDENGINE_ROOT/projects/SimEngine/scripts/run_ray_distributed_rollout.sh" \
    "$WORLDENGINE_ROOT/projects/AlgEngine/configs/worldengine/e2e_vadv2_50pct.py" \
    "$WORLDENGINE_ROOT/data/alg_engine/ckpts/e2e_vadv2_50pct_ep8.pth" \
    e2e_vadv2_50pct \
    my_scenario \
    navtrain

Here my_scenario is the BWM scenario_name, and navtrain selects the base assets under data/sim_engine/assets/navtrain/assets. Adjust the asset name to match the corpus used during BWM generation.

Rollout uses NR mode: other agents follow the trajectories stored in the input scenario, including BWM-generated trajectories, while AlgEngine controls ego in closed loop. The launcher computes dense rewards and automatically merges and exports results:

  • Rollout directory: $WORLDENGINE_ROOT/experiments/closed_loop_exps/e2e_vadv2_50pct/my_scenario_NR/
  • Exported dataset name: e2e_vadv2_50pct_my_scenario_NR_<YYMMDD>

Use that exported name in the BWM rollout fine-tuning config, following AlgEngine Fine-Tuning Configuration. Restore the launcher's original/${DATA_TYPE} input path before using it for original scenarios again.

Customizing Rollout Splits

Edit the rollout script to change GPU count:

# In run_ray_distributed_rollout.sh, line ~140
# Change from:
for i in {0..7}; do    # 8 GPUs
    run_planner $i &
done

# To (for 4 GPUs):
for i in {0..3}; do    # 4 GPUs
    run_planner $i &
done

Testing Scripts

Testing scripts run closed-loop evaluation with a planning model. Used for:

  • Model performance evaluation
  • Rare case testing

Single-GPU Testing

For quick tests or debugging:

export WORLDENGINE_ROOT=/path/to/WorldEngine

cd  projects/SimEngine
bash scripts/run_testing.sh \
    $WORLDENGINE_ROOT/projects/AlgEngine/configs/worldengine/e2e_vadv2_50pct.py \
    $WORLDENGINE_ROOT/data/alg_engine/ckpts/e2e_vadv2_50pct_ep8.pth \
    e2e_vadv2_50pct \
    navtest_failures \
    NR

Arguments:

  1. <config>: Model configuration file
  2. <checkpoint>: Trained model checkpoint
  3. <model_name>: Experiment name (creates output folder)
  4. <data_type>: Scenario split (e.g., navtest_failures, navtest)
  5. <react_type>: Reactive mode (NR or R)
    • NR (Non-Reactive): Other agents replay logged trajectories
    • R (Reactive): Other agents use IDM policy to react
  6. <asset_name> (optional): Asset folder name under data/sim_engine/assets/. Defaults to <data_type> if not provided

Output:

experiments/closed_loop_exps/e2e_vadv2_50pct/navtest_failures_NR/
├── WE_output/
│   └── openscene_format/
│       └── all_scenes_pdm_averages_NR.csv  # Main metrics CSV
├── plan_traj/              # Model-predicted trajectories (.npy)
├── frames/                 # Communication files (deleted after run)
└── merged_ann_files/       # Merged annotations (.pkl)

Multi-GPU Distributed Testing (Recommended)

For faster evaluation on large test sets:

export WORLDENGINE_ROOT=/path/to/WorldEngine

cd  projects/SimEngine
bash scripts/run_ray_distributed_testing.sh \
    $WORLDENGINE_ROOT/projects/AlgEngine/configs/worldengine/e2e_vadv2_50pct.py \
    $WORLDENGINE_ROOT/data/alg_engine/ckpts/e2e_vadv2_50pct_ep8.pth \
    e2e_vadv2_50pct \
    navtest_failures \
    NR

How it works:

  1. Launches SimEngine ray distributed server (handles scenario distribution)
  2. Spawns 8 AlgEngine clients (one per GPU)
  3. Each client processes 1/8 of scenarios in parallel
  4. Auto-merges results after completion

Testing on Different Scenario Splits

# Test on all navtest scenarios (not just failures)
bash scripts/run_ray_distributed_testing.sh \
    ... \
    navtest \  # Changed from navtest_failures
    NR

# Test on training set
bash scripts/run_ray_distributed_testing.sh \
    ... \
    navtrain \
    NR

Testing with Reactive Agents

# Non-reactive (default): Other agents replay logged paths
bash scripts/run_ray_distributed_testing.sh \
    ... \
    NR

# Reactive: Other agents use IDM to react to ego
bash scripts/run_ray_distributed_testing.sh \
    ... \
    R  # Changed to R

Reactive mode impact:

  • More challenging (agents respond to ego's mistakes)
  • Lower scores expected
  • Tests robustness to unexpected agent behaviors

Configuration

SimEngine uses Hydra for configuration management.

Configuration Files

Default config: projects/SimEngine/worldengine/configs/default_runner.yaml

Override with:

python worldengine/runner/run_simulation.py \
    --config-name custom_config.yaml

Output Format

Directory Structure

experiments/closed_loop_exps/<model_name>/<data_type>_<react_type>/
├── split_0/ ... split_7/
├── plan_traj/
└── WE_output/
    └── openscene_format/
        ├── meta_datas/
        ├── pdms_pkl/
        ├── sensor_blobs/
        └── all_scenes_pdm_averages_NR.csv

OpenScene Format

WE_output/openscene_format/
├── sensor_blobs/
│   ├── CAM_F0/                 # Front camera
│   ├── CAM_L0/                 # Left camera
│   ├── CAM_R0/                 # Right camera
│   └── LIDAR_TOP/              # LiDAR point clouds
├── meta_datas/
│   └── {scenario_token}.pkl         # Per-scenario metadata
└── all_scenes_pdm_averages_NR.csv

Utility Scripts

Convert nuPlan Data to SimEngine Format

Convert nuPlan dataset to SimEngine scenario format with navsim filter-based scene selection.

Example:

conda activate simengine

python projects/SimEngine/worldengine/utils/dataset_utils/nuplan/digitaltwin_nuplan_converter_navsim_filter.py \
    --navsim-filters $ALGENGINE_ROOT/configs/navsim_splits/navtrain_split/e2e_vadv2_50pct_rare/navtrain_50pct_collision.yaml \
        $ALGENGINE_ROOT/configs/navsim_splits/navtrain_split/e2e_vadv2_50pct_rare/navtrain_50pct_ep_1pct.yaml \
        $ALGENGINE_ROOT/configs/navsim_splits/navtrain_split/e2e_vadv2_50pct_rare/navtrain_50pct_off_road.yaml \
    --out-dir data/sim_engine/scenarios/original/navtrain_vadv2_50pct_rare \
    --num-processes 8

Key Parameters:

  • --navsim-filters: Path(s) to navsim config file(s) for scenario filtering (supports multiple files)
  • --digitaltwin-asset-root: Digital Twin asset root directory (default: data/sim_engine/assets/navtrain)
  • --nuplan-root-path: nuPlan dataset root directory
  • --nuplan-db-path: nuPlan database file directory
  • --openscene-dataroot: OpenScene data root directory
  • --out-dir: Output directory for converted scenario files
  • --sample-interval: Keyframe sampling interval (default: 10)
  • --num-processes: Number of parallel processes

Output:

  • {out-dir}/all_scenarios.pkl - Converted WorldEngine scenario file

The script extracts from Digital Twin config and nuPlan raw data:

  • Ego and agent vehicle trajectories
  • Camera and LiDAR calibration parameters
  • Traffic light states
  • Map features (lanes, intersections, etc.)

Converted scenarios can be directly used for SimEngine simulation.


Merge Distributed Results

The distributed rollout and testing launchers already merge results. Use this command only when merging existing split outputs separately. The example follows the scenario set used in AlgEngine Fine-Tuning.

conda activate simengine
ROLLOUT_PATH="$WORLDENGINE_ROOT/experiments/closed_loop_exps/e2e_vadv2_50pct/navtrain_vadv2_50pct_rare_NR"

python "$WORLDENGINE_ROOT/projects/SimEngine/scripts/merge_simulation_results.py" \
    --test_path "$ROLLOUT_PATH" \
    --react_type NR

Export OpenScene Format Data

The rollout launcher automatically exports after merging, with a YYMMDD suffix from the system date at export time. After a successful automatic export, proceed directly to dataset verification.

For an existing merged rollout that has not been exported, use this manual command. Choose an unused suffix; manual_v1 is an example:

conda activate simengine
ROLLOUT_PATH="$WORLDENGINE_ROOT/experiments/closed_loop_exps/e2e_vadv2_50pct/navtrain_vadv2_50pct_rare_NR"
mkdir -p "$WORLDENGINE_ROOT/data/alg_engine/openscene-synthetic/"{meta_datas,pdms_pkl,sensor_blobs}

python "$WORLDENGINE_ROOT/projects/SimEngine/scripts/export_simulation_data.py" \
    --test_path "$ROLLOUT_PATH" \
    --appendix manual_v1

Pass an absolute --test_path without a trailing slash. The exporter uses the path directly and derives the model and run names from its last two components.

The example creates dataset e2e_vadv2_50pct_navtrain_vadv2_50pct_rare_NR_manual_v1 under each of data/alg_engine/openscene-synthetic/{meta_datas,sensor_blobs,pdms_pkl}. Omitting --appendix omits the suffix; the exporter does not add a date itself. Existing symlink destinations are not overwritten. A new suffix creates another name for the same source rollout, not a new simulation.


Troubleshooting

Issue 1: Ray initialization fails

Error: ray.exceptions.RaySystemError: System error: Failed to start Ray

Solution:

# Kill existing Ray processes
ray stop

# Check port availability
netstat -tulpn | grep 6379

# Restart simulation
bash scripts/run_ray_distributed_testing.sh ...

Issue 2: GPU out of memory

Error: CUDA out of memory

Solution:

# Reduce GPU allocation (fewer scenarios per GPU)
# Edit the script and change:
number_of_gpus_allocated_per_simulation=1.0  # From 0.5

# Or reduce batch size in model config

Issue 3: "No scenarios found"

Error: FileNotFoundError: all_scenarios.pkl

Solution:

# Check scenario data path
ls -lh data/sim_engine/scenarios/original/navtest_failures/

# Verify pickle file exists
file data/sim_engine/scenarios/original/navtest_failures/all_scenarios.pkl

Issue 4: Simulation hangs

Symptoms: Process runs but no progress

Solution:

# Check if AlgEngine client is connected
tail -f experiments/closed_loop_exps/*/WE_output/*.log

# Check for stuck frames
ls -lt experiments/closed_loop_exps/*/frames/ | head -20

# Kill and restart with debug mode
debug_mode=true num_scenarios=1

Issue 5: Resume not working

Error: Scenarios restart from beginning

Solution:

# Ensure resume flag is set
enable_resume=true

# Check completed scenarios file
cat experiments/closed_loop_exps/*/completed_scenarios/completed_scenarios.txt

# Verify scenario IDs match

Performance Tips

  1. GPU Allocation: Use 0.5 for most scenarios (2 workers per GPU)
  2. Resume Mode: Always enable enable_resume=true for long runs
  3. Distributed Mode: Both testing and rollout use SCENARIO_BASED mode by default
  4. Cleanup: Set sim.clean_temp_files=True to save disk space
  5. Ray Resources: Limit Ray memory with RAY_memory_limit=30GB if needed

Next Steps

For questions, visit GitHub Discussions.