Skip to content

MaxMSun/lqrax

Repository files navigation

logo

LQRax

LQRax is JAX-enabled continuous-time LQR solver. It is essentially a Riccati equation solver completely written in JAX:

  • It accelerates numerical simulation through JAX's scan mechanism;
  • It allows rapid prototyping of iterative LQR (iLQR) for nonlinear control by supporting auto-differentiation on the loss function and dynamics;
  • It also enables batch-based large-scale optimal control using JAX's vmap mechanism.

This repo is currently under active development.

2d drone landing example (ilqr)

Install

Follow the instructions to install JAX before installing this package.

To install: pip install lqrax

Usage

There are two modules: LQR and iLQR,

The LQR module solves the following time-varying LQR problem:

arg min u ( t ) 0 T [ ( x ( t ) x r e f ( t ) ) Q ( x ( t ) x r e f ( t ) ) + u ( t ) R u ( t ) ] d t s.t.  x ˙ ( t ) = A ( t ) x ( t ) + B ( t ) u ( t ) , x ( 0 ) = x 0

An jupyter notebook example for the LQR module is provided here. You can open it in Google Colab here.

The iLQR module solves a different time-varying LQR problem:

arg min v ( t ) 0 T [ z ( t ) Q z ( t ) + v ( t ) R v ( t ) + z ( t ) a ( t ) + v ( t ) b ( t ) ] d t s.t.  z ˙ ( t ) = A ( t ) z ( t ) + B ( t ) v ( t ) , z ( 0 ) = 0.

This formulation is often used as the sub-problem for iterative linear quadratic regulator (iLQR) to calculate the steepest descent direction on the control for a general nonlinear control problem:

arg min u ( t ) 0 T l ( x ( t ) , u ( t ) ) d t ,  s.t.  x ˙ ( t ) = f ( x ( t ) , u ( t ) ) ,

where the z ( t ) and v ( t ) are perturbations on the system's state x ( t ) and control u ( t ) , and A ( t ) and B ( t ) are the linearized system dynamics f ( x ( t ) , u ( t ) ) on the current system trajectory with respect to the state and control.

An jupyter notebook example of using the iLQR module for a nonlinear control problem is provided here. You can open it in Google Colab here.

Copyright and License

The implementations contained herein are copyright (C) 2024 - 2025 by Max Muchen Sun, and are distributed under the terms of the GNU General Public License (GPL) version 3 (or later). Please see the LICENSE for more information.

If you use the package in your research, please cite this repository. You can see the citation information at the right side panel under "About". The BibTeX file is attached below:

@software{sun_lqrax_2025,
    author = {["Sun"], Max Muchen},
    license = {GPL-3.0},
    month = march,
    title = {{LQRax: JAX-enabled continuous-time LQR solver}},
    url = {https://github.com/MaxMSun/lqrax},
    version = {0.0.1},
    year = {2025}
}

Contact: [email protected]