TL;DR
Combining machine learning with Model Predictive Control (MPC) promises the holy grail of robotics: adaptive, data-driven intelligence that strictly obeys real-world physical limits. However, existing tools struggle to backpropagate gradients through complex, nonlinear control problems when hard safety constraints are involved. This paper introduces a mathematical framework and a fast open-source implementation in acados that makes fully general, constrained nonlinear MPC smoothly differentiable—running over three times faster than current state-of-the-art tools.
What Problem Does This Paper Address?
Model Predictive Control (MPC) is the workhorse of modern control engineering; at every fraction of a second, it solves an optimization problem to find the best actions while respecting physical boundaries (like motor limits or obstacle avoidance). Recently, researchers have tried embedding MPC directly inside neural networks or reinforcement learning loops. To train these hybrid systems with gradient descent, you need solution sensitivities—essentially, how the optimal control action changes if you nudge the underlying parameters (costs, dynamics, or constraints).
Here is the catch: when an optimization problem hits a hard inequality constraint (say, a steering angle maxes out), the solution map develops sharp kinks where derivatives simply do not exist. Because of this, existing "differentiable MPC" libraries usually compromise: they restrict themselves to simple convex problems, drop state constraints entirely, or rely on mathematical approximations that quietly ruin gradient accuracy on nonlinear problems.
Methods
Rather than unrolling and differentiating through every step of an optimization solver (which eats up memory and compute), the authors differentiate the optimality conditions directly at the solution using the Implicit Function Theorem (IFT). To handle the sharp kinks caused by constraints, they introduce Sequential Barrier Quadratic Programming (SBQP) alongside a clever two-solver architecture:
- Controlled Smoothing via SBQP: Standard Sequential Quadratic Programming (SQP) solves nonlinear problems via a sequence of quadratic approximations. When paired with an Interior-Point Method (IPM), inequalities are replaced by smooth logarithmic "barriers" controlled by a parameter $\tau$ that is driven to zero. SBQP generalizes this by letting $\tau$ stop at a prescribed positive target $\tau_{\min} \ge 0$. Stopping early intentionally preserves a smoothed version of the problem, rounding off sharp corners so gradients remain well-behaved for learning algorithms (recovering exact SQP when $\tau_{\min} = 0$).
- The Two-Solver Approach: Fast MPC solvers almost always use approximate curvature (like Gauss-Newton Hessians) to converge quickly. However, differentiating using an approximate Hessian produces wrong gradients. The authors decouple the work: a nominal solver uses fast approximations to find the optimal trajectory, and then hands the solution to a sensitivity solver, which evaluates and factorizes the exact Hessian just once (via an optimal-control-tailored Riccati recursion) to compute exact forward or adjoint sensitivities.
Datasets
Not discussed in the paper. Because this is a numerical optimization and control paper rather than a data-driven benchmark study, the authors evaluate their solver on synthetic, simulated optimal control problems:
- A 4-state nonlinear OCP with highly nonlinear parameter dependencies across costs, dynamics, and constraints.
- A newly configured batch benchmark of 128 linear-quadratic regulator (LQR) problems with varying initial states sampled from a standard normal distribution (designed simple enough so baseline solvers could still run it).
- A nonlinear "chain of masses" control problem (9 states, 3 controls, 113 parameters).
Key Insights and Ideas
- The "Approximate Hessian Pitfall": Previous differentiable MPC frameworks suggested reusing the solver's convexified (Gauss-Newton) Hessian to compute gradients for free. The authors prove theoretically and show empirically that on general nonlinear problems, this shortcut yields completely erroneous sensitivities. You must use the exact Hessian of the Lagrangian for the backward pass.
- Smoothing is a Feature, Not a Bug: By keeping $\tau_{\min} > 0$ in SBQP, you get two wins at once: smooth, continuous gradients across active-set changes (where constraints turn on or off), and cheaper computation since the interior-point solver takes fewer iterations when it doesn't have to shrink the barrier all the way to zero.
- Adjoint Sensitivities Unlock Scale: Computing the full Jacobian of how every output changes with respect to 100+ parameters is expensive. By formulating an adjoint sensitivity pass (tailored with a custom block-elimination in
HPIPM), you only need a single linear system backsolve to get the exact gradient needed for neural network backpropagation.
Key Results
Implemented in C (with OpenMP batch parallelization and Python/ML wrappers via leap-c) inside the open-source acados framework, the method delivers substantial speedups:
- Faster Across the Board: On batches of 128 bounded LQR problems on CPU,
acadoscomputes both the solution and adjoint sensitivities 3.8x to 12x faster thanmpc.pytorchand 16x to 33x faster thancvxpygenacross varying horizons and state dimensions. - Immunity to Tight Constraints: When control bounds are tightened so constraints frequently activate,
mpc.pytorch's runtime balloons from 102 ms to 1,793 ms.acadosbarely flinches (going from 21.0 ms to 23.4 ms), resulting in a 77x speedup overmpc.pytorchand 53x overcvxpygen. - Adjoint Efficiency: On the 113-parameter nonlinear chain-of-masses problem, computing a single adjoint sensitivity for backpropagation is roughly 4x faster than computing the full forward sensitivity matrix.
- Gradient Accuracy: On the nonlinear parametric OCP,
acadossensitivities with $\tau_{\min}=0$ match finite-difference ground truth, whereas the standard approximate-Hessian IFT approach fails dramatically.
Limitations and Future Work
- CPU-Only Execution: To maintain
acados's minimal-dependency C design for embedded microcontrollers, the implementation runs strictly on CPUs. While CPUs excel at small-scale linear algebra and variable-time constrained solves, lack of native GPU execution may bottleneck massive-batch neural network training. - Discrete-Time Dynamics Only: System dynamics currently must be supplied as discrete-time CasADi expressions; general parametric sensitivities are not yet integrated into
acados's fast continuous-time integrators. - Future Directions: The authors plan to add continuous-time integrator support, implement regularizations to differentiate through locally non-unique solutions, and benchmark how smoothed SBQP gradients compare against nonsmooth "conservative Jacobians" in end-to-end learning pipelines.
Summary updated