# acdslab/mppi-generic architecture

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

- Interactive diagram: https://gitdiagram.com/acdslab/mppi-generic
- Repository: https://github.com/acdslab/mppi-generic

## Overview

##### Project Type and Purpose
- MPPI-Generic is a high-performance, header-only C++/CUDA library implementing Model Predictive Path Integral Control (MPPI) methods. The project is designed for researchers and practitioners needing GPU-accelerated stochastic optimization for control applications.
- It provides multiple controllers (MPPI, ColoredMPPI, Primitives, Tube-MPPI, R-MPPI), cost functions, dynamics models, sampling distributions, feedback control algorithms, and utilities—all organized in a modular way.
- The README and file structure indicate that the library supports various simulation examples (e.g., for cartpole, double integrator, quadrotor) along with extensive testing, CUDA kernel components, and build integration through CMake.

##### Analysis of the File Structure
- Core Directories:
- "include/mppi": This is the heart of the library. It contains further subdirectories for controllers, cost functions, dynamics, feedback controllers, instantiations, sampling distributions, and shaping functions.
- "src": Contains sample implementations of controllers (autorally, cartpole, double integrator, quadrotor), which show how the library is used in practice.
- "examples": Provides example programs, often CUDA files (.cu), to demonstrate the application of MPPI-Generic in real-world scenarios.
- "tests": A comprehensive suite (unit tests, integration tests, kernel tests) to ensure functionality across various components (controllers, cost functions, dynamics, utils).
- "resources": Contains pre-trained models or test data (e.g., neural network parameters), which the controllers/dynamics components might use.
- "cmake": Contains modules and configuration files necessary to build the project with CMake, ensuring proper integration of CUDA, Eigen, and other dependencies.
- Other files:
- The various CMakeLists.txt files at different levels indicate that the project is built modularly.
- The .clang-format, .gitattributes, LICENSE, and README files indicate standard practices for an open-source library.
- The “scripts” directory contains utility scripts (e.g., for converting autorally networks, generating test data, autoformatting), reinforcing the modular design and testing workflow.

##### Key Components to Highlight
- Library Core Modules:
- Controllers: Under “include/mppi/controllers”, separate folders for different controller types illustrate that multiple algorithm variants are implemented (e.g., MPPI, ColoredMPPI, Tube-MPPI).
- Cost Functions: Found under “include/mppi/cost_functions”, these modules are critical for evaluating the control objectives (e.g., for cartpole, autorally).
- Dynamics: Located in “include/mppi/dynamics”, these files describe how the simulated plants (cartpole, quadrotor, double integrator, etc.) evolve.
- Feedback Controllers and DDP: Feedback and optimization-based methods (from “include/mppi/feedback_controllers” and “include/mppi/ddp”) support trade-offs in performance and robustness.
- Utilities: “include/mppi/utils” contains helper functions (e.g., activation and math utilities) that support the overall computational framework.
- Build and Deployment:
- CMake Configuration: Tools and modules under the “cmake” directory cover configuration and build automation, ensuring CUDA and Eigen are properly linked.
- Testing Infrastructure: The “tests” directory is organized by component (controllers, cost functions, dynamics, etc.) and indirect kernel tests, emphasizing robust verification.
- External Dependencies:
- NVIDIA CUDA: The core computations (especially in .cu files) are GPU-accelerated.
- Eigen: Used for matrix operations in control algorithms.
- Others: Dependencies like git, git-lfs, and optional libraries for testing (yaml-cpp, python-pil).

##### Relationships and Interactions
User Application / Example → Controller Invocation → Cost Function & Dynamics Evaluation → Sampling (using distributions and shaping functions) → Feedback & Optimized Control Output.
- Dependencies:
- Controllers depend on cost functions, dynamics, and sampling modules.
- Feedback modules and DDP algorithms integrate with the controller logic.
- Utilities provide cross-cutting support to all these modules.
- Testing components (unit, integration, kernel tests) use mocks (see tests/mppi_test/mock_classes) to simulate various aspects of system behavior.

##### Architectural Patterns & Design Principles
- Modularity: Each logical module (controllers, cost functions, dynamics, etc.) is encapsulated in its own directory.
- Extensibility: The existence of “instantiations” for different control problems (cartpole, double integrator, autorally, quadrotor) suggests design flexibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    user["User / Example Application"]:::external
    examples["Examples (Simulation/Demo Programs)"]:::example

    user -->|"invokes"| examples

    subgraph "MPPI-Generic Library Core"
        libraryCore["Library Core"]:::core
        ctrl["Controllers"]:::core
        cost["Cost Functions"]:::core
        dyn["Dynamics"]:::core
        fb["Feedback & DDP"]:::core
        sample["Sampling Distributions"]:::core
        shaping["Shaping Functions"]:::core
        utils["Utilities"]:::core
    end

    examples -->|"calls"| libraryCore
    libraryCore -->|"routes_to"| ctrl
    ctrl -->|"evaluates"| cost
    ctrl -->|"simulates"| dyn
    cost -->|"feedbacks"| ctrl
    dyn -->|"feedbacks"| ctrl
    ctrl -->|"integrates"| fb
    ctrl -->|"applies"| sample
    sample -->|"shapes"| shaping

    utils ---|"supports"| ctrl
    utils ---|"supports"| cost
    utils ---|"supports"| dyn
    utils ---|"supports"| fb
    utils ---|"supports"| sample
    utils ---|"supports"| shaping

    cmake["CMake Configuration"]:::build
    tests["Testing Infrastructure"]:::test
    scripts["Auxiliary Scripts"]:::scripts
    resources["External Resources"]:::resource
    extDep["External Dependencies (CUDA, Eigen)"]:::external

    ctrl -->|"built_with"| cmake
    cost -->|"verified_by"| tests
    dyn -->|"verified_by"| tests
    fb  -->|"verified_by"| tests
    sample -->|"verified_by"| tests
    shaping -->|"supported_by"| tests

    cmake -->|"configures"| utils
    scripts -->|"assists"| cmake
    resources -->|"feeds"| dyn

    extDep ---|"supports"| ctrl
    extDep ---|"supports"| cost
    extDep ---|"supports"| dyn
    extDep ---|"supports"| fb

    %% Click Events
    click libraryCore "https://github.com/acdslab/mppi-generic/tree/main/include/mppi"
    click ctrl "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/controllers"
    click cost "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/cost_functions"
    click dyn "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/dynamics"
    click fb "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/feedback_controllers"
    click fb "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/ddp"
    click sample "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/sampling_distributions"
    click shaping "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/shaping_functions"
    click utils "https://github.com/acdslab/mppi-generic/tree/main/include/mppi/utils"
    click cmake "https://github.com/acdslab/mppi-generic/tree/main/cmake"
    click tests "https://github.com/acdslab/mppi-generic/tree/main/tests"
    click scripts "https://github.com/acdslab/mppi-generic/tree/main/scripts"
    click resources "https://github.com/acdslab/mppi-generic/tree/main/resources"
    click examples "https://github.com/acdslab/mppi-generic/tree/main/examples"

    %% Styles
    classDef external fill:#CDEBF9,stroke:#1F78B4,stroke-width:2px;
    classDef example fill:#F9E79F,stroke:#F1C40F,stroke-width:2px;
    classDef core fill:#D6EAF8,stroke:#3498DB,stroke-width:2px;
    classDef build fill:#FCF3CF,stroke:#F39C12,stroke-width:2px;
    classDef test fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef scripts fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef resource fill:#FAD7A0,stroke:#E67E22,stroke-width:2px;
```
