Differentiable iLQR algorithm for dynamical systems
Project description
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
Structure
Examples
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)
License
This project is licensed under the MIT License. See the LICENSE file for details.
Define Lagrangian
Partial derivatives
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file diffilqrax-0.0.1.tar.gz
.
File metadata
- Download URL: diffilqrax-0.0.1.tar.gz
- Upload date:
- Size: 34.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e09dc3e3453bc464d35daa973568004b4334165d2ff66dc9a784d46a698749f |
|
MD5 | 8fed3e9fe4bdb67da5b40a2989d21422 |
|
BLAKE2b-256 | 4be4cc1dbbff82926c4eef6e671f3e0018e6893c5479a0864486d1dc6a6282b4 |
File details
Details for the file diffilqrax-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: diffilqrax-0.0.1-py3-none-any.whl
- Upload date:
- Size: 38.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a689cdef5619ffbb6f5b5f560667c05334565b98d61333505197429355cbfbf |
|
MD5 | f4a58f00b834b41518fefdace9bb9e80 |
|
BLAKE2b-256 | 2dc5adf57b07a805b09c3507e72ca0f87ac5276057454eee449f931a3a2cf1c7 |