A PyTorch implementation of Path Integral Networks for differentiable optimal control, now featuring both standard MPPI and Latent-space MPPI (LMPPI), based on:
- Okada et al., 2017, "Path Integral Networks: End-to-End Differentiable Optimal Control"
- Okada & Taniguchi, 2018, "Acceleration of Gradient-Based Path Integral Method for Efficient Optimal and Inverse Optimal Control"
- Standard MPPI: Classic Model Predictive Path Integral control
- Latent-space MPPI (LMPPI): NEW! VAE-based latent space control for high-dimensional trajectory optimization
- Accelerated MPPI: Gradient-based acceleration with Adam, NAG, and RMSprop
- Batch Processing: Efficient parallel processing of multiple initial states (3-4x speedup)
- GPU Acceleration: Full CUDA support for high-performance computing
- End-to-End Learning: Differentiable implementation for neural dynamics and cost learning
- VAE Trajectory Modeling: Learn compact latent representations of complex trajectory patterns
- Clean Interface: Simple, reusable API for different control problems
- Pip Installable: Easy installation and integration
# Clone the repository
git clone https://github.com/kisisjrlly/diff-mppi.git
cd diff-mppi
# Install in development mode
pip install -e .import torch
import diff_mppi
# Define your system dynamics
def dynamics(state, control):
# Your dynamics model here
return next_state
# Define your cost function
def cost(state, control):
# Your cost function here
return cost_value
# Create controller
controller = diff_mppi.create_mppi_controller(
state_dim=3,
control_dim=1,
dynamics_fn=dynamics,
cost_fn=cost,
horizon=30,
num_samples=100,
temperature=0.1,
acceleration="adam", # Optional: "adam", "nag", "rmsprop"
device="cuda"
)
# Solve for optimal control
initial_state = torch.tensor([1.0, 0.0, 0.0])
optimal_control = controller.solve(initial_state, num_iterations=10)
# Batch processing for multiple initial states (NEW!)
initial_states = torch.tensor([[1.0, 0.0, 0.0], [2.0, 1.0, 0.0], [0.0, -1.0, 0.0]])
batch_controls = controller.solve(initial_states) # 3x speedup on GPU!
# Simulate trajectory
trajectory = controller.rollout(initial_state, optimal_control)import torch
from diff_mppi.lmppi import TrajectoryVAE, LMPPIController, LMPPITrainer
from diff_mppi.lmppi import create_synthetic_trajectories, VAEConfig, ControllerConfig
# Step 1: Generate or load trajectory data
trajectories = create_synthetic_trajectories(
num_trajectories=1000,
horizon=30,
state_dim=4,
control_dim=2
)
# Step 2: Train VAE for trajectory representation learning
vae_config = VAEConfig(
input_dim=4, # state dimension
latent_dim=8, # compressed latent dimension
hidden_dims=[64, 32],
architecture="mlp"
)
vae = TrajectoryVAE(vae_config)
trainer = LMPPITrainer(vae, learning_rate=1e-3)
# Train the VAE
trainer.train(trajectories, epochs=100, batch_size=32)
# Step 3: Create LMPPI controller
controller_config = ControllerConfig(
num_samples=100,
temperature=0.1,
horizon=30,
lambda_=1.0
)
def dynamics(state, control):
# Your dynamics model
return next_state
def cost_fn(state, control):
# Your cost function
return cost
controller = LMPPIController(vae, dynamics, cost_fn, controller_config)
# Step 4: Solve in latent space
initial_state = torch.tensor([1.0, 0.0, 0.5, -0.5])
optimal_control = controller.solve(initial_state, num_iterations=20)Run the included examples:
# Basic pendulum swing-up with acceleration method comparison
python examples/pendulum_example.py
# Batch processing demonstration
python examples/batch_processing_example.py
# Neural dynamics learning and control
python examples/neural_dynamics_example.py
# Complete imitation learning with end-to-end training
python examples/imitation_learning_example.py
# Simple LMPPI demonstration (NEW!)
python examples/simple_lmppi_demo.pyThese examples demonstrate different aspects of the library:
- Pendulum example: Optimization with known models
- Batch processing: Efficient parallel processing of multiple states
- Neural dynamics: Learning dynamics models
- Imitation learning: Complete end-to-end differentiable learning
- LMPPI demo: Latent space trajectory optimization with VAE
π Complete Documentation - Comprehensive documentation suite including:
- Installation Guide - System requirements, setup, and troubleshooting
- API Reference - Complete API documentation with examples
- Examples & Tutorials - Practical examples and step-by-step tutorials
- Theoretical Background - Mathematical foundations and implementation details
- Contributing Guide - How to contribute to the project
The main controller class implementing Path Integral Networks.
Key Methods:
solve(initial_state, num_iterations): Solve for optimal control sequencerollout(initial_state, control_sequence): Simulate system trajectorystep(state): Get single control action for real-time control
Latent-space MPPI for high-dimensional trajectory optimization.
Key Classes:
TrajectoryVAE: Variational autoencoder for trajectory representation learningLMPPIController: Controller operating in latent spaceLMPPITrainer: Training utilities for VAE modelsTrajectoryDataset: Data handling and preprocessing utilities
Key Features:
- Support for MLP, LSTM, and CNN encoder/decoder architectures
- Comprehensive training with validation and checkpointing
- Configurable latent space dimensions and model complexity
- Built-in visualization and evaluation tools
# Create controller with default settings
controller = diff_mppi.create_mppi_controller(
state_dim, control_dim, dynamics_fn, cost_fn, **kwargs
)The library supports several gradient-based acceleration methods:
- Standard MPPI (
acceleration=None): Classic path integral method - Adam (
acceleration="adam"): Adaptive moment estimation - NAG (
acceleration="nag"): Nesterov accelerated gradient - RMSprop (
acceleration="rmsprop"): Root mean square propagation
| Problem | Horizon | Samples | Device | Time/Iteration |
|---|---|---|---|---|
| Pendulum | 30 | 100 | CPU | 25ms |
| Pendulum | 30 | 100 | GPU | 8ms |
| Navigation | 40 | 200 | CPU | 85ms |
| Navigation | 40 | 200 | GPU | 22ms |
- Python >= 3.8
- PyTorch >= 1.9
- NumPy >= 1.21
- Matplotlib >= 3.3 (for examples)
Clean separation between core functionality and examples:
diff_mppi/
βββ __init__.py # Public API
βββ core.py # Core MPPI implementation
βββ lmppi/ # NEW! Latent-space MPPI module
β βββ __init__.py # LMPPI API exports
β βββ models.py # VAE architectures (MLP/LSTM/CNN)
β βββ controller.py # Latent space controller
β βββ trainer.py # VAE training utilities
β βββ data.py # Trajectory data handling
β βββ config.py # Configuration management
β βββ utils.py # Visualization and evaluation
β βββ README.md # LMPPI documentation
examples/
βββ pendulum_example.py # Pendulum swing-up example
βββ simple_lmppi_demo.py # NEW! LMPPI demonstration
βββ test_lmppi.py # NEW! LMPPI test suite
docs/
βββ README.md # Documentation index
βββ API_REFERENCE.md # Complete API docs
βββ THEORY.md # Mathematical background
βββ ... # Additional documentation
We welcome contributions! Please see our Contributing Guide for:
- Development environment setup
- Code style guidelines
- Testing requirements
- Pull request process
See CHANGELOG.md for detailed release notes and version history.
MIT License - see LICENSE file for details.
If you use this library in your research, please cite the original papers:
@article{okada2017path,
title={Path integral networks: End-to-end differentiable optimal control},
author={Okada, Masashi and Taniguchi, Tadahiro},
journal={arXiv preprint arXiv:1706.09597},
year={2017}
}
@article{okada2018acceleration,
title={Acceleration of gradient-based path integral method for efficient optimal and inverse optimal control},
author={Okada, Masashi and Taniguchi, Tadahiro},
journal={arXiv preprint arXiv:1805.11897},
year={2018}
}- Documentation: Start with docs/README.md
- Examples: Check the examples/ directory
- Issues: Report bugs on GitHub Issues
- Discussions: Join GitHub Discussions