RepositoryPythonJPJapan
kohonda

kohonda/mppi_playground

Model Predictive Path Integral Control (MPPI) with PyTorch

238stars
28forks
0issues
3views

Featured achievements

The project's latest awards

1
TINIX TRENDING·Topic: mppi

#1 Repository of the week

3
TINIX TRENDING·Topic: gymnasium

#3 Repository of the week

3
TINIX TRENDING·Topic: motion-planning

#3 Repository of the week

MPPI Playground

A PyTorch implementation of Model Predictive Path Integral Control (MPPI).

Key Features:

  • 🚀 GPU-accelerated parallel computation
  • 🧠 Differentiable implementation in PyTorch
  • ⚙️ Flexible definitions of dynamics and cost functions
  • 🔧 Additional useful features, including automatic temperature tuning and Savitzky–Golay trajectory smoothing
  • 🤖 Example applications

Tested Environment

  • Ubuntu 20.04 or higher
  • [Optional] GPU with NVIDIA Driver (510 or later, tested with 550)
  • uv

Run Examples

To run the example applications, install with additional dependencies:

# Clone repository
git clone https://github.com/kohonda/mppi_playground.git
cd mppi_playground
uv sync --extra example # Install with extra dependencies for examples
# uv run pre-commit install  # (optional) install pre-commit hooks for code formatting
# uv run pre-commit run --all-files  # (optional) format code
uv run python example/navigation2d.py

navigation2d

Racing

uv run python example/racing.py

racing

circuit course information (Japan Automotive AI Challenge 2024)

Pendulum

uv run python example/pendulum.py

pendulum

Cartpole

uv run python example/cartpole.py

cartpole

Mountain car

uv run python example/mountaincar.py

mountaincar

Usage in Your Project

Add dependency to your pyproject.toml and uv sync:

dependencies = [
    "pi-mpc"
]

[tool.uv.sources]
pi-mpc = {git = "https://github.com/kohonda/mppi_playground.git"}

Or install via pip:

pip install git+https://github.com/kohonda/mppi_playground
Minimal code example
import torch
from pi_mpc.mppi import MPPI

# Define dynamics function (batch processing: state [N, dim_state], action [N, dim_control])
def dynamics(state: torch.Tensor, action: torch.Tensor) -> torch.Tensor:
    # Example: simple integrator
    next_state = state + action
    return next_state

# Define cost function (batch processing)
def cost_func(state: torch.Tensor, action: torch.Tensor, info: dict) -> torch.Tensor:
    # Example: distance to goal
    goal = torch.tensor([1.0, 1.0], device=state.device)
    return torch.sum((state - goal) ** 2, dim=1)

# Create MPPI controller
controller = MPPI(
    horizon=50,
    num_samples=1000,
    dim_state=2,
    dim_control=2,
    dynamics=dynamics,
    cost_func=cost_func,
    u_min=torch.tensor([-1.0, -1.0]),
    u_max=torch.tensor([1.0, 1.0]),
    sigmas=torch.tensor([0.5, 0.5]),
    lambda_=1.0,
)

# Solve for optimal action sequence
current_state = torch.tensor([0.0, 0.0])
action_seq, state_seq = controller(current_state)
print(f"Optimal first action: {action_seq[0]}")
Configurations

MPPI Parameters

ParameterTypeDefaultDescription
horizonintrequiredPrediction horizon length
num_samplesintrequiredNumber of trajectory samples
dim_stateintrequiredState dimension
dim_controlintrequiredControl dimension
dynamicsCallablerequiredDynamics model: (state, action) -> next_state
cost_funcCallablerequiredCost function: (state, action, info) -> cost
u_minTensorrequiredMinimum control bounds, shape (dim_control,)
u_maxTensorrequiredMaximum control bounds, shape (dim_control,)
sigmasTensorrequiredNoise std for each control dim, shape (dim_control,)
lambda_float / strrequiredTemperature or auto-tuning method ("MPO", "LBPS", "ESSPS")

Auto-Lambda Parameters

ParameterTypeDefaultDescription
lbps_deltafloat0.01Confidence parameter for LBPS (0 < δ < 1)
essps_target_essfloatnum_samples/10Target effective sample size for ESSPS
lambda_minfloat0.01Minimum lambda bound for optimization
lambda_maxfloat10.0Maximum lambda bound for optimization

Sampling & Filtering Parameters

ParameterTypeDefaultDescription
explorationfloat0.0Fraction of purely random samples (0 to 1)
use_sg_filterboolFalseEnable Savitzky-Golay smoothing
sg_window_sizeint5Window size for SG filter (must be odd)
sg_poly_orderint3Polynomial order for SG filter

Automatic Temperature Tuning (Auto-Lambda)

The temperature parameter λ is a hyperparameter that controls the exploration-exploitation trade-off. Three auto-tuning methods are available:

# Example: Enable auto-lambda with LBPS
controller = MPPI(..., lambda_="LBPS", lbps_delta=0.01)

Trajectory Smoothing

# Example: Enable smoothing
controller = MPPI(..., use_sg_filter=True, sg_window_size=5, sg_poly_order=3)

Citation

If you use this repo in your work, please cite this paper (https://arxiv.org/abs/2511.08019) as:

@article{honda2026model,
  title={Model Predictive Control via Probabilistic Inference: A tutorial and survey},
  author={Honda, Kohei},
  journal={Annual Reviews in Control},
  volume={61},
  pages={101052},
  year={2026},
  publisher={Elsevier}
}

Similar Projects

Discover other similar projects and AI models.

RepositoryPython
UM-ARM-Lab/pytorch_mppi

Model Predictive Path Integral (MPPI) with approximate dynamics implemented in pytorch

775
Mar 15, 2026
RepositoryPython
openrobokit/robokit

A high-performance, general-purpose toolkit for versatile robotic tasks.

482
Nov 27, 2026
RepositoryC
acados/acados

Fast and embedded solvers for nonlinear optimal control and nonlinear model predictive control

1.5k
Dec 1, 2026
RepositoryC++
loco-3d/crocoddyl

Crocoddyl is an optimal control library for robot control under contact sequence. Its solver is based on various efficient Differential Dynamic Programming (DDP)-like algorithms

1.3k
Nov 24, 2026
RepositoryC++
formiat/px4-ros2-drone-nav

Autonomous UAV navigation in GNSS-denied indoor spaces with no prior map: stereo VIO (MSCKF) and lidar-inertial odometry with map-based relocalization (SLAM), 3D occupancy mapping, D* Lite path planning and GPU MPPI obstacle avoidance. PX4 + ROS 2 + Gazebo SITL, DARPA SubT Urban.

176
Nov 29, 2026
RepositoryC++
kohonda/proj-svg_mppi

[ICRA2024] Stein Variational Guided Model Predictive Path Integral Control: Proposal and Experiments with Fast Maneuvering Vehicles

172
Jul 8, 2025
RepositoryJupyter Notebook
shaoanlu/mppi_cbf

Colab notebooks showcasing experiments on MPPI (model predictive path integral control) and CBF (control barrier function). Utilizes jax to accelerate computation.

143
Nov 11, 2025
RepositoryJulia
sisl/MPOPIS

Adaptive importance sampling modification to MPPI

121
Apr 1, 2024
Modelsentence-similarity
sentence-transformers/all-MiniLM-L6-v2

all-MiniLM-L6-v2 This is a sentence-transformers(https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search. Usage (Sentence-Transformers) Using t...

♥0
157.6M
Jun 1, 2026