Skip to main content

PyTorch MPPI Implementation

This repository implements the improved Cross Entropy Method (iCEM) with approximate dynamics in pytorch, from this paper.

MPPI typically requires actual trajectory samples, but this paper showed that it could be done with approximate dynamics (such as with a neural network) using importance sampling.

Thus it can be used in place of other trajectory optimization methods such as the Cross Entropy Method (CEM), or random shooting.

Related projects

  • pytorch CEM - alternative sampling based MPC
  • pytorch MPPI - alternative sampling based MPC
  • iCEM - original paper's numpy implementation and experiments code

Installation

pip install pytorch-icem

for running tests, install with

pip install pytorch-icem[test]

for development, clone the repository then install in editable mode

pip install -e .

Usage

See tests/pendulum_approximate_continuous.py for usage with a neural network approximating the pendulum dynamics. Basic use case is shown below

from pytorch_icem import iCEM

# create controller with chosen parameters
ctrl = icem.iCEM(dynamics, terminal_cost, nx, nu, sigma=sigma,
                 warmup_iters=10, online_iters=10,
                 num_samples=N_SAMPLES, num_elites=10, horizon=TIMESTEPS, device=d, )

# assuming you have a gym-like env
obs = env.reset()
for i in range(100):
    action = ctrl.command(obs)
    obs, reward, done, _, _ = env.step(action.cpu().numpy())

Requirements

  • pytorch (>= 1.0)
  • next state <- dynamics(state, action) function (doesn't have to be true dynamics)
    • state is K x nx, action is K x nu
  • trajectory cost <- cost(state, action) function for the whole state action trajectory, T is the horizon
    • cost is K x 1, state is K x T x nx, action is K x T x nu

Features

  • Parallel/batch pytorch implementation for accelerated sampling

Metadata

Release files for pytorch-icem 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytorch-icem 0.1.0
File Size Uploaded Provenance
pytorch_icem-0.1.0.tar.gz 7.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for pytorch-icem 0.1.0
File Interpreter ABI Platform
pytorch_icem-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.0 kB

Release files / pytorch_icem-0.1.0.tar.gz

Download URL pytorch_icem-0.1.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6ab86b351e2b8eb367d1698444a58d8112b1bbff98cab293d9d41b87ba422c35
BLAKE2b-256 checksum
How to use checksums
67ebf93cc1583c0da784722c76845dfd296792b6ca3353359e63329d52d5b0d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Release files / pytorch_icem-0.1.0-py3-none-any.whl

Download URL pytorch_icem-0.1.0-py3-none-any.whl
Size 6.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d22309e0b8879b1e4f88787687631c03f1a7f01c639a7cc7134f87951794e180
BLAKE2b-256 checksum
How to use checksums
be95e79c59148f2528ee0a2f2e2d47067b26827a1dcdb82e8bcad819f0129aaf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.13

Security for pytorch-icem 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page