JAX-based implementation of the iterative Linear Quadratic Regulator (iLQR) with multiple examples. For a full derivation see the tutorial here.
The repo includes a venv with all dependencies. Just run:
make testThe Makefile uses the venv automatically—no activation needed.
# Requires Python 3.10+
python -m venv venv
source venv/bin/activate
pip install -e .Includes CUDA 12 GPU support by default. For CUDA 11 or CPU-only, edit requirements.txt (see file comments).
from ilqr import iLQR
import jax.numpy as jnp
# Define your dynamics
def dynamics(state, control):
# Your dynamics here
return next_state
# Define your cost
def build_cost():
def stage_cost(x, u):
# Stage cost
return cost_value
def terminal_cost(x_T):
# Terminal cost
return cost_value
def traj_cost(xs, us):
# Full trajectory cost
return total_cost
return {"stage": stage_cost, "terminal": terminal_cost, "traj": traj_cost}
# Setup and solve
cost = build_cost()
dims = {"state": n, "control": m}
ilqr = iLQR(cost, dynamics, horizon, dims)
(states, controls), (success, stats) = ilqr.solve(x0, u_init)make test-all # Run all tests and generate animations
make test-parking # Car parking with animation
make test-cartpole # Cart pole balancing with animation
make test-rocket # Rocket landing with animation
make test-bicycle # Bicycle navigation with animation
make test-unit # Unit test for iLQR in a LQ systemTests generate plots and animations in figures/.
LQR- Linear Quadratic RegulatoriLQR- Iterative LQR for nonlinear systemsiLQRAdaptive- iLQR with variable dynamicsiLQRAdaptiveAugmented- iLQR with constraints (augmented Lagrangian)
Python 3.10+ with:
- JAX 0.6.2 (CUDA 12 GPU support)
- NumPy 2.2.6
- Matplotlib 3.10.6
- SciPy 1.15.3
- Edit
src/ilqr/solvers.py - Run
make test - Check
figures/for plots
Changes apply immediately (editable install).





