# hyzhou404/hugsim architecture

> Architecture diagram of the GitHub repository hyzhou404/hugsim, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-20). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hyzhou404/hugsim
- Repository: https://github.com/hyzhou404/hugsim

## Overview

##### Project Type & Purpose
- HUGSIM is a full-stack, closed-loop simulator for autonomous driving.
- It provides pipelines for scene reconstruction (train), export (eval_render), interactive scenario configuration (GUI), and real-time simulation loops (closed_loop.py).
- It integrates ML-based reconstruction, photorealistic rendering, and external AD algorithm clients (UniAD_SIM, VAD_SIM, NAVSIM).

##### File Structure Analysis
- Top‐level directories:
- configs: YAMLs for data preparation, benchmarks, simulation settings.
- data: raw datasets (kitti360, nusc, waymo, pandaset), InverseForm model, colmap utilities.
- sim: HUGSIM gym environment (hugsim_env), ILQR planner, utility scripts.
- eval_render: scene/vehicle conversion & rendering scripts.
- gui: Flask-based GUI for scenario config (app.py + static/ templates).
- scene, gaussian_renderer: core scene‐representation and Gaussian splatting modules.
- train.py / train_ground.py: reconstruction model training entry points.
- closed_loop.py: simulation orchestrator invoking external AD clients and the gym environment.
- submodules: Pplan (sampling planners), simple-knn (CUDA‐accelerated KNN).

##### README Insights
- Two-phase installation via pixi (Python, PyTorch, CUDA).
- Data preparation & download documented under data/README.md.
- Reconstruction → Export → GUI configuration → Closed-loop simulation.
- External dependencies: UniAD_SIM, VAD_SIM, NAVSIM clients.

a. Main Components
- Data Preparation Module
– Input raw sequences → dataset readers (data/* + scene/dataset_readers.py).
- Reconstruction Pipeline
– train_ground.py (ground surfaces) → train.py (semantic scene + objects)
– Uses InverseForm submodule, PyTorch models (data/InverseForm/models).
- Scene Export & Conversion
– eval_render (export_scene.py, convert_vehicles.py, convert_scene.py)
– Outputs minimized scene & vehicle splat/semantic formats.
- GUI Scenario Configurator
– gui/app.py: web server, user edits YAML templates → scenario definitions.
- Closed-Loop Simulator
– closed_loop.py: loads scenario, base & camera configs, kinematic model;
– Creates HUGSIM gym env (sim/hugsim_env), launches external AD client, loops sensor→action→render.
- Planning & Control
– sim/ilqr (LQR solver), submodules/Pplan (sampling planners), sim/utils (agent_controller).
- Rendering Engine
– gaussian_renderer: real-time Gaussian splatting.
- External AD Clients
– UniAD_SIM, VAD_SIM, NAVSIM (installed separately).

b. Relationships & Interactions
– Data Preparation feeds Reconstruction.
– Reconstruction outputs models/scene data → Export converts to simulation format.
– GUI reads exported scene & vehicle data → writes scenario YAML.
– closed_loop.py consumes scenario & configs → instantiates HUGSIM env + Gaussian renderer + planning modules → calls external AD client → loops.
– Planning & control modules interface with gym environment.
– Rendering engine provides observations to both GUI and closed-loop.

c. Architectural Patterns
– Modular pipeline: clear separation of stages (prep → train → export → config → simulate).
– Plugin/integration: external AD clients plugged into simulation loop.
– Gym-style environment abstraction for sim.
– Component-based scene modeling (ground_model, obj_model, gaussian_model).

d. Key Technologies
– Python, PyTorch, CUDA for ML & rendering.
– pixi for environment & dependency management.
– Flask (or FastAPI) for GUI.
– Open3D/colmap scripts for reconstruction preprocessing.
– YAML-based config files.
– Gym API abstraction in sim/hugsim_env.

##### Key Details to Capture
- Config files driving each stage (configs/benchmark, configs/sim).
- Interaction points: eval_render ↔ gui, gui → closed_loop.
- The gym environment wrapper (sim/hugsim_env).
- Planning modules (ILQR & Pplan) plugged into env.
- Rendering engine (gaussian_renderer) providing observations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Preparation Layer
    subgraph "Data Preparation" 
        direction TB
        RawData["Raw Datasets"]:::store
        DataPrep["Data Preparation Module"]:::data_preproc
        DatasetReaders["scene/dataset_readers.py"]:::data_preproc
        ColmapUtils["data/colmap utilities"]:::data_preproc
    end

    %% Reconstruction Layer
    subgraph "Reconstruction Pipeline"
        direction TB
        TrainGround["train_ground.py"]:::reconstruction
        TrainMain["train.py"]:::reconstruction
        InverseFormModels["InverseForm Models"]:::reconstruction
        InverseFormUtils["data/InverseForm/utils"]:::reconstruction
        PrepareColmap["prepare_colmap.py"]:::reconstruction
        TrainedModels["Trained Scene & Object Models"]:::store
    end

    %% Export & GUI Layer
    subgraph "Export & GUI"
        direction TB
        EvalRender["eval_render/"]:::export
        ExportScene["export_scene.py"]:::export
        ConvertScene["convert_scene.py"]:::export
        ExportVehicles["export_vehicles.py"]:::export
        ConvertVehicles["convert_vehicles.py"]:::export
        RenderScript["render.py"]:::export
        ExportedAssets["Exported Scene & Vehicle Assets"]:::store

        GuiApp["gui/app.py"]:::gui
        GuiStatic["gui/static/"]:::gui
        GuiTemplates["gui/templates/index.html"]:::gui
        ScenarioYAML["Scenario YAML"]:::store
    end

    %% Simulation & Control Layer
    subgraph "Closed-Loop Simulation"
        direction TB
        ClosedLoop["closed_loop.py"]:::sim
        GymEnv["sim/hugsim_env/"]:::sim
        LaunchAD["sim/utils/launch_ad.py"]:::sim
        ILQR["sim/ilqr/"]:::sim
        SamplingPlanner["submodules/Pplan/Policy/sampling_planner.py"]:::sim
        PplanSampling["submodules/Pplan/Sampling/"]:::sim
        AgentCtrl["sim/utils/agent_controller.py"]:::sim
        GaussianRenderer["gaussian_renderer/"]:::sim
        SensorObs["Sensor Observations"]:::store
    end

    %% External AD Clients
    subgraph "External AD Clients"
        direction TB
        UniAD_SIM["UniAD_SIM"]:::ext
        VAD_SIM["VAD_SIM"]:::ext
        NAVSIM["NAVSIM"]:::ext
    end

    %% Configuration
    Configs["configs/"]:::data_preproc

    %% Flow Connections
    RawData -->|reads| DataPrep
    DataPrep -->|"datasets"| DatasetReaders
    DataPrep -->|colmap data| ColmapUtils
    DataPrep -->|prepared data| TrainGround

    TrainGround -->|ground model| TrainedModels
    TrainMain -->|semantic+obj model| TrainedModels
    DataPrep -->|data feeds| TrainMain
    InverseFormModels -->|model definitions| TrainMain
    InverseFormUtils --> TrainMain
    PrepareColmap --> TrainMain

    TrainedModels -->|scene data| ExportScene
    TrainedModels -->|vehicle data| ExportVehicles
    ExportScene -->|scene splats| ExportedAssets
    ConvertScene -->|formatted scene| ExportedAssets
    ExportVehicles -->|vehicle splats| ExportedAssets
    ConvertVehicles -->|formatted vehicles| ExportedAssets
    RenderScript -->|renders| ExportedAssets

    ExportedAssets --> GuiApp
    GuiStatic --> GuiApp
    GuiTemplates --> GuiApp
    GuiApp -->|writes| ScenarioYAML

    ScenarioYAML --> ClosedLoop
    Configs --> ClosedLoop
    ClosedLoop --> GymEnv
    ClosedLoop --> LaunchAD
    ClosedLoop --> GaussianRenderer
    ClosedLoop --> SensorObs
    ClosedLoop --> ILQR
    ClosedLoop --> SamplingPlanner
    ClosedLoop --> AgentCtrl

    GymEnv -->|obs| SensorObs
    SensorObs --> ClosedLoop
    ClosedLoop -->|actions| GymEnv
    LaunchAD -->|control| ClosedLoop

    ILQR --> GymEnv
    SamplingPlanner --> GymEnv
    AgentCtrl --> GymEnv

    GaussianRenderer -->|renders obs| SensorObs

    ClosedLoop -->|calls| UniAD_SIM
    ClosedLoop -->|calls| VAD_SIM
    ClosedLoop -->|calls| NAVSIM

    %% Click Events
    click RawData "https://github.com/hyzhou404/hugsim/tree/main/data/"
    click DataPrep "https://github.com/hyzhou404/hugsim/tree/main/data/"
    click DatasetReaders "https://github.com/hyzhou404/hugsim/blob/main/scene/dataset_readers.py"
    click ColmapUtils "https://github.com/hyzhou404/hugsim/tree/main/data/colmap/"
    click TrainGround "https://github.com/hyzhou404/hugsim/blob/main/train_ground.py"
    click TrainMain "https://github.com/hyzhou404/hugsim/blob/main/train.py"
    click InverseFormModels "https://github.com/hyzhou404/hugsim/tree/main/data/InverseForm/models/"
    click InverseFormUtils "https://github.com/hyzhou404/hugsim/tree/main/data/InverseForm/utils/"
    click PrepareColmap "https://github.com/hyzhou404/hugsim/blob/main/data/*/prepare_colmap.py"
    click EvalRender "https://github.com/hyzhou404/hugsim/tree/main/eval_render/"
    click ExportScene "https://github.com/hyzhou404/hugsim/blob/main/eval_render/export_scene.py"
    click ConvertScene "https://github.com/hyzhou404/hugsim/blob/main/eval_render/convert_scene.py"
    click ExportVehicles "https://github.com/hyzhou404/hugsim/blob/main/eval_render/export_vehicles.py"
    click ConvertVehicles "https://github.com/hyzhou404/hugsim/blob/main/eval_render/convert_vehicles.py"
    click RenderScript "https://github.com/hyzhou404/hugsim/blob/main/eval_render/render.py"
    click GuiApp "https://github.com/hyzhou404/hugsim/blob/main/gui/app.py"
    click GuiStatic "https://github.com/hyzhou404/hugsim/tree/main/gui/static/"
    click GuiTemplates "https://github.com/hyzhou404/hugsim/blob/main/gui/templates/index.html"
    click ClosedLoop "https://github.com/hyzhou404/hugsim/blob/main/closed_loop.py"
    click GymEnv "https://github.com/hyzhou404/hugsim/tree/main/sim/hugsim_env/"
    click LaunchAD "https://github.com/hyzhou404/hugsim/blob/main/sim/utils/launch_ad.py"
    click ILQR "https://github.com/hyzhou404/hugsim/tree/main/sim/ilqr/"
    click SamplingPlanner "https://github.com/hyzhou404/hugsim/blob/main/submodules/Pplan/Policy/sampling_planner.py"
    click PplanSampling "https://github.com/hyzhou404/hugsim/tree/main/submodules/Pplan/Sampling/"
    click AgentCtrl "https://github.com/hyzhou404/hugsim/blob/main/sim/utils/agent_controller.py"
    click GaussianRenderer "https://github.com/hyzhou404/hugsim/tree/main/gaussian_renderer/"
    click Configs "https://github.com/hyzhou404/hugsim/tree/main/configs/"

    %% Styles
    classDef data_preproc fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1;
    classDef reconstruction fill:#C8E6C9,stroke:#388E3C,color:#1B5E20;
    classDef export fill:#FFE0B2,stroke:#FB8C00,color:#E65100;
    classDef gui fill:#FFECB3,stroke:#FDD835,color:#F57F17;
    classDef sim fill:#FFCDD2,stroke:#E53935,color:#B71C1C;
    classDef ext fill:#E0E0E0,stroke:#9E9E9E,color:#424242;
    classDef store fill:#E3F2FD,stroke:#64B5F6,color:#0D47A1,stroke-dasharray: 5 5;
```
