Skip to main content

JAX-native control theory library

Project description

Contrax

Differentiable control theory primitives for JAX.

CI Docs PyPI Python License: MIT

Contrax is a JAX-native systems, estimation, and control toolbox. MATLAB-familiar names at the API surface — ss, lqr, kalman, place — with jit, vmap, and grad behavior underneath.

Documentation · Getting started · API reference


Install

pip install contrax

Requires Python 3.11+ and JAX 0.4+. For GPU support, install JAX separately per the JAX installation guide before installing Contrax.

Why Contrax

A controller design step can sit inside an ordinary differentiable objective instead of being a separate offline calculation:

import jax
jax.config.update("jax_enable_x64", True)

import jax.numpy as jnp
import contrax as cx

A = jnp.array([[1.0, 0.05], [0.0, 1.0]])
B = jnp.array([[0.0], [0.05]])
SYS = cx.dss(A, B, jnp.eye(2), jnp.zeros((2, 1)), dt=0.05)
X0 = jnp.array([1.0, 0.0])


def closed_loop_cost(log_q_diag, log_r):
    K = cx.lqr(SYS, jnp.diag(jnp.exp(log_q_diag)), jnp.exp(log_r)[None, None]).K
    _, xs, _ = cx.simulate(SYS, X0, lambda t, x: -K @ x, num_steps=80)
    return jnp.sum(xs**2) + 1e-2 * jnp.sum((xs[:-1] @ K.T) ** 2)


cost, (dq, dr) = jax.jit(jax.value_and_grad(closed_loop_cost, argnums=(0, 1)))(
    jnp.zeros(2), jnp.array(0.0)
)

This is the central Contrax idea: control primitives that behave like normal JAX building blocks.

Scope

Systems ss, dss, c2d, nonlinear_system, phs_system, canonical_J, schedule_phs, linearize, linearize_ss, phs_to_ss, series, parallel

Simulation lsim, simulate, rollout, step_response, impulse_response, initial_response, sample_system, foh_inputs

Control lqr, lqi, dare, care, place, feedback, state_feedback, augment_integrator

Estimation kalman, ekf, ukf, rts, uks kalman_predict, kalman_update, kalman_step ekf_predict, ekf_update, ekf_step kalman_gain, mhe_objective, mhe, mhe_warm_start

Analysis ctrb, obsv, poles, evalfr, freqresp, dcgain, ctrb_gramian, obsv_gramian, lyap, dlyap, zeros

Diagnostics innovation_diagnostics, likelihood_diagnostics, ukf_diagnostics, smoother_diagnostics, phs_diagnostics, innovation_rms

Parameterization positive_exp, positive_softplus, spd_from_cholesky_raw, diagonal_spd, lower_triangular

Interoperability contrax.compat.python_control — optional bidirectional conversion with python-control (pip install control)

Solver Status

  • dare — structured-doubling forward solve with implicit-differentiation VJP. Most mature path.
  • care — Hamiltonian stable-subspace solver with implicit backward pass. Validated, less benchmarked than dare.
  • place — JAX-native KNV0/YT-style robust pole placement; Ackermann retained as SISO fallback only.
  • ekf / ukf / rts / uks — differentiable nonlinear filtering and smoothing with full JAX transform support.
  • mhe — LBFGS-backed fixed-window MHE. Useful optimization-based estimation primitive; not a full NLP framework.

LTI workflows are the most mature slice. Nonlinear models, PHS support, and fixed-window MHE are real public capabilities, but they should be read with more explicit solver-maturity caution than the core discrete design path.

Development

git clone https://github.com/givani30/Contrax.git
cd Contrax
uv sync --group dev
uv run pre-commit install
uv run pytest tests/ -q

See CONTRIBUTING.md for contribution guidelines.

Acknowledgements

Contrax is built on top of several excellent JAX-ecosystem libraries:

  • JAX — the foundation: JIT compilation, autodiff, and vectorization.
  • Equinox — pytree-compatible modules used for all result bundles and system types.
  • Diffrax — ODE solvers powering simulate() on continuous-time models.
  • Optimistix — LBFGS solver backing mhe().
  • Lineax — linear solvers used in the estimation and Riccati paths.

The DARE structured-doubling custom VJP is adapted from trajax (Google) and the DiLQR approach (ICML 2025). The UKF sigma-point rules follow Wan & van der Merwe (2000).

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

contrax-0.1.0.tar.gz (71.7 kB view details)

Uploaded Source

Built Distribution

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

contrax-0.1.0-py3-none-any.whl (57.6 kB view details)

Uploaded Python 3

File details

Details for the file contrax-0.1.0.tar.gz.

File metadata

  • Download URL: contrax-0.1.0.tar.gz
  • Upload date:
  • Size: 71.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for contrax-0.1.0.tar.gz
Algorithm Hash digest
SHA256 55b93fb83e42ad9450898ee00375a7da5569a36a3815a086fad5e572b99473fc
MD5 4314a749b6449ce78e896042896fecc5
BLAKE2b-256 7330a490bba0733ecb86ed9436ddfa3521355169540a81e78f982b5f8c0e979a

See more details on using hashes here.

File details

Details for the file contrax-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: contrax-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 57.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Arch Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for contrax-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b0a9b0e5db5454938d3901174a7e2318fb76917c73a5769e6c1a65d96ff01acb
MD5 12b855b951f04d9fc5e45988f341710c
BLAKE2b-256 c754539a71bbabbde5e1c70d5401490a1ff16ddda56a24e37bae7ce63431a5fc

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