patrick-kidger / diffrax

Numerical differential equation solvers in JAX. Autodifferentiable and GPU-capable. https://docs.kidger.site/diffrax/
Apache License 2.0
1.32k stars 121 forks source link

Using diffrax to integrate system dynamics for Model Predictive Control #393

Open Hs293Go opened 3 months ago

Hs293Go commented 3 months ago

Diffrax docs' Kalman Filter Example encouraged me to apply diffrax to other linear-quadratic control problems, such as the following

\min_{u(t)} x_N^TQx_N + \sum_{k=0}^N x_k^T Q x_k + u_k^T R u_k\quad \text{subject to}\ \dot{x}(t) = f(x(t), u(t)),\ x(0) = x_{init}

essentially finding the optimal control $u$ over a prediction horizon $T$ discretized into $N$ segments.

Diffrax seems like a good fit for solving the IVP $\dot{x}(t) = f(x(t), u(t)),\ x(0) = x{init}$ over the prediction horizon to compute $x{0,\ldots,N}$. In this case...

Is diffrax the right tool for this job? Is yes, what is the best approach; Are there any idioms?

patrick-kidger commented 3 months ago

Yup, this sounds exactly like what Diffrax is for. You might also find this example a useful reference for how to insert the control input u.

Touching on your other points:

I hope that helps!