Paying for Adaptivity: Unfolded SQP Solvers Under a Microcontroller Cycle Budget

Many robots and vehicles plan their next move by solving a small optimization problem many times per second. This is model predictive control: at each tick, the controller computes a short plan that respects obstacles and actuator limits, executes the first step, and replans. For nonlinear systems the standard approach, sequential quadratic programming (SQP), repeatedly linearizes the problem and solves a convex quadratic program (QP). The QP is usually solved with ADMM (the alternating direction method of multipliers), a simple splitting method whose speed depends heavily on a step-size parameter $\rho$. A recent line of work, deep unfolding, treats a fixed number of solver iterations as the layers of a neural network and learns how to set such parameters. Deep FlexQP does exactly this inside SQP. It uses a recurrent network (an LSTM) that reads the solver's residual history and predicts $\rho$ and two other parameters at every iteration. It reports 4–16x speedups over OSQP on nonlinear trajectory optimization, but every one of those measurements was taken on a desktop.

This proposal argues that the desktop speedup measures the wrong cost. On a microcontroller, the expensive part of an adaptive ADMM step is probably not the network that chooses $\rho$. It is what happens after $\rho$ changes. Embedded OSQP is fast and division-free because it factors the linear system once for a fixed $\rho$ and caches the factorization (Stellato et al.). A new $\rho$ at every iteration either forces a new factorization or requires a different inner solver, and either one can erase the reduction in iteration count. We propose an unfolded solver whose parameter policy is designed for and trained against a measured microcontroller cycle budget. The policy chooses $\rho$ from a small menu of factorizations that are precomputed offline and stored in memory, and it decides when switching is worth the cost. We will validate the solver on real ARM hardware for nonlinear obstacle-avoidance problems.

Core Claim

The claim has three parts. First, inside SQP for nonlinear trajectory optimization, most of the iteration savings that come from adapting $\rho$ can be kept by switching among $K$ cached factorizations, with $K$ between about 3 and 6. Second, the policy that does the switching can be a small feedforward network over a few residual statistics rather than an LSTM. Third, when solver cost is measured in cycles on a Cortex-M class processor, this design beats both static-$\rho$ embedded OSQP and a direct port of Deep FlexQP on worst-case solve latency. The contribution is not simply "port Deep FlexQP to a microcontroller." It is a hardware-cost model of adaptivity that is built into training, together with the first bare-metal evidence on how much optimization memory is worth once you pay for it. The file contains no reported result for any unfolded solver on a microcontroller, and Deep FlexQP explicitly leaves out embedded metrics such as cycle counts and SRAM use.

The cost the policy is trained against is, for one QP solve of $N$ unfolded iterations,

$$ C = \sum_{k=1}^{N} \Big( c_{\text{iter}} + c_{\text{policy}} + \mathbb{1}[\rho_k \neq \rho_{k-1}]\, c_{\text{switch}} \Big). $$

Each term is measured on the target chip:

  • $c_{\text{iter}}$ is the cycle cost of one ADMM iteration using a cached factorization.
  • $c_{\text{policy}}$ is the cost of evaluating the parameter network.
  • $c_{\text{switch}}$ is the cost of switching to a different cached factorization. It is small when the factorization is already resident in SRAM and large when it has to be streamed from Flash or recomputed.

The training loss is solution quality plus $\lambda C$. The discrete choice of $\rho$ is relaxed with a straight-through estimator so the loss can be differentiated. Under this loss the policy is pushed to adapt only when the expected reduction in iterations exceeds the switching price. A desktop-trained policy never sees that price.

Research Program

The first stage is measurement, and it should be published even if the method fails. We will write library-free C implementations of four solvers, all with static memory allocation in the style of the OSQP code generator:

  • elastic-QP ADMM with a fixed $\rho$;
  • elastic-QP ADMM with refactorization every time $\rho$ changes;
  • the Deep FlexQP LSTM policy;
  • our cached-menu solver.

Each runs on two targets. One is a Cortex-M4F/M7 class microcontroller with a single-precision floating-point unit. The other is the NXP i.MX6 UltraLite ARM board that Sheik et al. used to show that schemes that look viable on a PC miss real deadlines. We will record:

  • cycle counts from the hardware cycle counter;
  • Flash and SRAM footprint;
  • energy per solve;
  • the full latency distribution, including its tail, rather than only the mean.

These measurements give $c_{\text{iter}}$, $c_{\text{policy}}$, and $c_{\text{switch}}$ as functions of problem size. They also answer whether the LSTM's per-iteration overhead, which Deep FlexQP acknowledges, matters on such chips. Direction 1 of the file gives reason to expect large surprises: an identity-based signature verification takes 946 ms on that ARM board, against a 50 ms safety limit.

The second stage is the method. The QP formulation is kept: FlexQP's $\ell_1$ elastic relaxation, which keeps linearized subproblems solvable when obstacle constraints cannot all be satisfied. The parameter policy is replaced in three ways:

  • $\rho$ takes values from a menu of $K$ values whose factorizations are cached, with the menu values learned jointly with the policy.
  • The relaxation and penalty parameters, which do not change the matrix being factored, remain continuous.
  • The policy is a small multilayer perceptron over hand-chosen residual features: primal and dual residual norms, their ratio, and their change over the last few iterations. This replaces an LSTM hidden state.

Training uses the measured cost model. The menu size $K$ is swept under the SRAM budget, since each cached factorization costs memory on the same order as the OSQP binaries Stellato et al. report, 46–554 kB depending on problem size.

The third stage closes the loop. The solver is embedded in SQP with a fixed number of outer and inner iterations, so latency is deterministic. It then runs in closed-loop simulation with the controller executing on the physical board in a processor-in-the-loop setup, and on a small mobile robot comparable to the trailer platform used by PANOC.

Baselines

The naive reference point is embedded OSQP with a single static $\rho$ tuned per problem class and code-generated as described by Stellato et al.. For fairness we add explicit $\ell_1$ slack variables to its QP so that it handles infeasible linearizations the same way FlexQP does. This removes the "OSQP crashes on infeasibility" argument, which would otherwise make the baseline a straw man. Its $\rho$ gets the same tuning budget, in wall-clock hours, as our training.

A second handcrafted baseline updates $\rho$ by the usual rule of balancing primal and dual residuals and refactorizes whenever $\rho$ changes. It isolates what adaptivity buys when its true hardware cost is paid.

The strongest existing method is Deep FlexQP itself, ported to C. Its reported numbers are the 4–16x speedup over OSQP inside SQP, more than 70% fewer safety-filter violations, and 43% higher task completion, all on desktop (Deep FlexQP). We will train it with the authors' losses on the same problem distributions and give it the same training compute. No reported result was found on Lacuna for Deep FlexQP on any embedded target.

PANOC in C is the strongest non-unfolded nonlinear competitor. It is reported to be about two orders of magnitude faster than IPOPT and SQP.

The ablations are:

  • the cached-menu policy trained without the cost term;
  • an open-loop learned $\rho$ schedule that depends only on the iteration index;
  • the LSTM inside the cached-menu design;
  • menu sizes from 1 to 8.

We count it as beating the baselines if the method meets both of the following on the microcontroller. It must cut 99th-percentile SQP solve latency to a fixed constraint-violation tolerance by at least 2x relative to tuned slack-augmented OSQP. It must also match or beat the ported Deep FlexQP on that latency while matching its task completion rate.

Why not just…?

Why not just use embedded OSQP with slack variables and a well-tuned static $\rho$? This is the real threat. Once slacks are added, OSQP's crash on infeasible subproblems is no longer a problem, and its per-iteration cost is the lowest possible. What remains is the claim that OSQP's speed is sensitive to $\rho$ across problem instances (OSQP). The test is direct. If menu size 1 with a tuned $\rho$ comes within 1.5x of our method's tail latency on the quadrotor and Dubins tasks, we will report that adaptivity is not worth its cost on microcontrollers. That would be a useful negative result for the unfolding literature.

Why not just learn a fixed schedule of $\rho$ values with no feedback at all? An open-loop schedule needs no policy evaluation and is known in advance, so it could switch factorizations on a predictable timetable. Deep FlexQP's finding that LSTMs beat MLPs suggests that feedback matters, but that finding was measured in iterations, not cycles. The open-loop ablation answers the question. If it matches our method, the "memory" Deep FlexQP found is not worth carrying onto hardware.

Why not just use PANOC, which already runs embedded nonlinear MPC? PANOC has a small memory footprint and strong reported speed. Its line search makes the iteration count vary, however, and fixed latency is the reason the unfolding literature exists (Shlezinger et al.). PANOC could still win on average latency. We therefore compare deadline-miss rates at fixed control rates, not only means. If PANOC wins on the tail as well, the unfolding argument fails for this problem class.

Why not just use a learned policy, or a GPU board? End-to-end policies that output motor thrusts directly failed on the real quadrotor in Kaufmann et al.'s benchmark and offer no constraint handling. Real-Time Neural MPC reaches over 100 Hz, but only on a Jetson-class GPU, which is outside the power envelope targeted here.

Proposed Experiments

The benchmarks come from Deep FlexQP: the Dubins-vehicle and quadrotor SQP trajectory optimization tasks with obstacles that make linearized subproblems infeasible, and the autonomous-driving safety filter. We add PANOC's trailer-robot obstacle avoidance task, and OSQP's portfolio and LASSO problems as a convex sanity check of footprint scaling. Metrics are:

  • median and 99.9th-percentile cycles per SQP solve;
  • deadline-miss rate at 50 Hz and 100 Hz;
  • constraint violation and task completion;
  • Flash and SRAM usage;
  • energy per solve.

The first decisive check is the cost decomposition from stage one. If $c_{\text{switch}}$ for a resident cached factorization is not small relative to $c_{\text{iter}}$, the menu design loses its rationale and we stop there with a measurement paper. The second check is the latency Pareto curve against tuned slack-augmented OSQP. The third is the gap between rankings measured in iterations and rankings measured in cycles: whether the desktop ordering of Deep FlexQP, the multilayer perceptron, and static $\rho$ flips on the microcontroller. A flip would show directly that desktop benchmarks misjudge unfolded solvers.