Skip to main content

Differentiable iLQR algorithm for dynamical systems

Project description

DiffiLQRax logo

Pylint Python Package Python Publish

Diffilqrax: Differentiable optimal control

Diffilqrax: What is it?

This repository contains an implementation of the iterative Linear Quadratic Regulator (iLQR) using the JAX library. The iLQR is a powerful algorithm used for optimal control, and this implementation is designed to be fully differentiable.

Getting Started

To get started with this code, clone the repository and install the required dependencies. Then, you can run the main script to see the iLQR in action.

git clone git@github.com:ThomasMullen/diffilqrax.git
cd diffilqrax
python -m build
pip install -e .

or, you can import from pip install

pip install diffilqrax

Quick example

import jax.numpy as jnp
import jax.random as jr
from diffilqrax import ilqr
from diffilqrax.typs import iLQRParams, Theta, ModelDims, System
from diffilqrax.utils import initialise_stable_dynamics, keygen

dims = ModelDims(8, 2, 100, dt=0.1)

key = jr.PRNGKey(seed=234)
key, skeys = keygen(key, 5)

Uh = initialise_stable_dynamics(next(skeys), dims.n, dims.horizon, 0.6)[0]
Wh = jr.normal(next(skeys), (dims.n, dims.m))
theta = Theta(Uh=Uh, Wh=Wh, sigma=jnp.zeros(dims.n), Q=jnp.eye(dims.n))
params = iLQRParams(x0=jr.normal(next(skeys), dims.n), theta=theta)
Us = jnp.zeros((dims.horizon, dims.m))   
# define linesearch hyper parameters
ls_kwargs = {
    "beta":0.8,
    "max_iter_linesearch":16,
    "tol":1e0,
    "alpha_min":0.0001,
    }
def cost(t, x, u, theta):
    return jnp.sum(x**2) + jnp.sum(u**2)

def costf(x, theta):
    return jnp.sum(x**2)

def dynamics(t, x, u, theta):
    return jnp.tanh(theta.Uh @ x + theta.Wh @ u)

model = System(cost, costf, dynamics, dims)
ilqr.ilqr_solver(params, model, Us, **ls_kwargs)

Design principle

DiffiLQRax Deisgn Principle

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgments

This project has received funding from the European Union’s Horizon 2020 research and innovation programme under the Marie Skłodowska-Curie grant agreement #813457.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diffilqrax-0.0.7.tar.gz (50.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

diffilqrax-0.0.7-py3-none-any.whl (35.8 kB view details)

Uploaded Python 3

File details

Details for the file diffilqrax-0.0.7.tar.gz.

File metadata

  • Download URL: diffilqrax-0.0.7.tar.gz
  • Upload date:
  • Size: 50.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for diffilqrax-0.0.7.tar.gz
Algorithm Hash digest
SHA256 56f2d12e7fe003a1fae6474249bca78ce790fe1b0e42d315e5e77ea53b7f2c7f
MD5 49ecdf014c0d07f8621b024633d6c6d2
BLAKE2b-256 19111a7fd0130d107fe24c77280ac1bb18c210c87f874ab8932d76beadebaad0

See more details on using hashes here.

File details

Details for the file diffilqrax-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: diffilqrax-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 35.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.21

File hashes

Hashes for diffilqrax-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f12477929b33bddf3b5cfcbbc32c4aec231aebd1de0285a8bfe3b2177c123df0
MD5 d3ed491562811bbf916fc223ea67fa4d
BLAKE2b-256 3bcc9e61d59ecdfe666579fce903088ca8a621c136d8038d893af82183d9f585

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page