Solvers¶
Solver objects configure algorithm choices, tolerances, and iteration limits.
Calls use validated defaults unless a solver= is supplied. Diffrax and
Optimistix objects retain their native interfaces in simulation and
optimization.
import jax
jax.config.update("jax_enable_x64", True)
import jax.numpy as jnp
import contrax as cx
solver = cx.solvers.Lyapunov(method="doubling", rtol=1e-12)
result = cx.dlyap(0.5 * jnp.eye(2), jnp.eye(2), solver=solver)
assert result.successful
Close over solver objects in jax.jit, or pass them through Equinox transforms.
Model matrices remain differentiable dynamic data. Numerical result statuses
are integer JAX scalars, using SolverStatus codes. throw=False returns
failure diagnostics; throw=True checks the result during execution. Invalid
matrix shapes or algorithm configuration raise immediately.
DARE configures structured doubling; CARE configures Hamiltonian-subspace
design with accepted Newton corrections. lqr and lqi accept the solver for
their system's time domain. kalman_gain accepts a DARE object for the dual
design equation. All these return .status and .successful in eager and
compiled execution. They require float64 mode and use implicit JVP/VJP rules.
Kalman and EKF configure covariance updates. Both default to Joseph form;
compact form requires covariance_update="compact". EKF(num_iter=3) enables
iterated measurement linearization in online and batch estimators. Filtering
supports float32 and float64 inputs and preserves their precision.
SteadyStateKalman(design) explicitly reuses a kalman_gain result. Its gain
and covariance are differentiable data. The initial predicted covariance
defaults to design.P; a supplied P0 must match it. The batch checks the
fixed-point equations for the supplied A, C, Q, R and the estimator's
stability. An inconsistent design or a missing observation reports
invalid_problem. Use covariance-form filtering for varying covariances or
missing observations. Design creation still requires float64 mode.
InformationKalman() accepts diagonal observation variances as R.shape=(p,).
It whitens the prior and observations, then factors an n-by-n matrix. It
avoids forming the prior inverse or a dense innovation covariance, and is useful
when observations outnumber states. Predicted covariances at observed steps
must be positive definite and all variances positive. Controls, masks,
initialization defaults and differentiation follow ordinary Kalman filtering.
UKF(alpha=1, beta=2, kappa=0) configures the scaled unscented transform.
Sigma-point and innovation covariances must be positive definite. Missing
observations skip the measurement transform and contribute zero log likelihood.
The innovation Cholesky factor is reused for the gain and likelihood.
Lyapunov supports stable doubling, general dense solves, and bounded automatic
fallback. See Analysis and Control for equation
assumptions, residual criteria and transform behavior.
PolePlacement configures the design-time KNV0/YT method, update limit,
determinant-improvement tolerance, achieved-pole tolerances and conditioning
limit. fallback_limit=8 bounds SISO Ackermann fallback; zero disables it.
Pole matching preserves multiplicities and conjugate pairs. Configuration
errors raise immediately; convergence and numerical failures return status
diagnostics unless throw=True. Read the control reference for
its float64 and transform contract.
contrax.solvers
¶
Configuration objects for numerical solvers.
Solver objects hold static algorithm choices and tolerances. Close over a
configuration in jax.jit; model matrices remain dynamic inputs.
CARE
¶
Bases: Module
Configure a Hamiltonian stable-subspace CARE solve with Newton refinement.
Refinement accepts corrections that reduce the residual and retain stable feedback. The Hamiltonian must provide a well-separated stable subspace.
Attributes:
| Name | Type | Description |
|---|---|---|
refinement_steps |
int
|
Maximum Newton corrections of the stabilizing candidate. |
rtol |
float
|
Relative equation residual tolerance. |
atol |
float
|
Absolute equation residual tolerance. |
Source code in contrax/solvers.py
DARE
¶
Bases: Module
Configure structured doubling for the discrete algebraic Riccati equation.
Attributes:
| Name | Type | Description |
|---|---|---|
max_steps |
int
|
Maximum structured doubling iterations. |
rtol |
float
|
Relative iterate and equation residual tolerance. |
atol |
float
|
Absolute iterate and equation residual tolerance. |
Source code in contrax/solvers.py
EKF
¶
Bases: Module
Extended Kalman measurement-update configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
covariance_update |
str
|
|
num_iter |
int
|
Measurement linearization passes; one gives ordinary EKF. The prediction covariance stays fixed during iterated updates. |
Source code in contrax/solvers.py
InformationKalman
¶
Bases: Module
Whitened state-space Kalman update for diagonal observation noise.
Use a positive observation-variance vector R with shape (p,). Prior
whitening and state-size Cholesky solves make this formulation useful when
observations outnumber states. Predicted covariances must be positive
definite; controls and missing observations follow covariance-form Kalman
conventions.
Source code in contrax/solvers.py
Kalman
¶
Bases: Module
Covariance-form linear Kalman filter configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
covariance_update |
str
|
|
Source code in contrax/solvers.py
Lyapunov
¶
Bases: Module
Configure a continuous- or discrete-time Lyapunov solve.
auto uses squared Smith iteration with dense fallback when the state
count is at most dense_limit. doubling applies to stable systems;
dense handles any uniquely solvable equation, including unstable A.
Explicit dense selection permits O(n^4) storage and O(n^6) work.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
|
rtol |
float
|
Scale-aware equation residual tolerance. |
atol |
float
|
Absolute equation residual tolerance. |
max_steps |
int
|
Maximum doubling steps, including residual correction solves. |
dense_limit |
int
|
Largest state dimension allowed for automatic fallback. |
Source code in contrax/solvers.py
PolePlacement
¶
Bases: Module
Configure design-time pole assignment and acceptance tolerances.
Attributes:
| Name | Type | Description |
|---|---|---|
method |
str
|
auto chooses KNV0 for real poles and YT for complex pairs. Explicit KNV0 and YT selections are also accepted. |
rtol |
float
|
Relative determinant-improvement convergence tolerance. |
max_steps |
int
|
Maximum eigenvector-update sweeps. |
assignment_rtol |
float
|
Scale-aware achieved-pole tolerance. |
assignment_atol |
float
|
Absolute achieved-pole tolerance. |
condition_limit |
float
|
Maximum controllability/eigenvector condition estimate. |
fallback_limit |
int
|
Largest SISO dimension allowed for Ackermann fallback; zero disables fallback. Every fallback is validated independently. |
Source code in contrax/solvers.py
SolverStatus
¶
Bases: IntEnum
JAX-compatible integer status codes shared by numerical results.
Source code in contrax/solvers.py
SteadyStateKalman
¶
Bases: Module
Explicitly reuse a kalman_gain design for a fully observed LTI stream.
Uses the gain design as differentiable data for a fully observed LTI stream.
Batch filtering defaults P0 to design.P, the predicted covariance before
the first update. A different P0, a missing observation, or an inconsistent
model/noise pair reports invalid_problem; use covariance-form filtering
when those cases are expected.
Attributes:
| Name | Type | Description |
|---|---|---|
design |
KalmanGainResult
|
KalmanGainResult returned by |
rtol |
float
|
Relative tolerance for gain/fixed-point and initialization checks. |
atol |
float
|
Absolute tolerance for those checks. |
Source code in contrax/solvers.py
UKF
¶
Bases: Module
Scaled unscented transform for additive-noise filtering.
Attributes:
| Name | Type | Description |
|---|---|---|
alpha |
float
|
Positive sigma-point spread; defaults to 1. |
beta |
float
|
Prior-distribution correction; 2 is standard for Gaussian priors. |
kappa |
float
|
Secondary scaling; n+kappa must be positive for n states. |
Sigma-point covariances and innovation covariances must be positive definite. Supply covariances that satisfy this condition before filtering.