---
title: 'ZipMPC: Context-Dependent Cost for MPC'
url: https://www.emergentmind.com/topics/zipmpc
type: topic
---

# ZipMPC: Context-Dependent Cost for MPC

Searching arXiv for the ZipMPC paper and closely related differentiable MPC work.
Searching arXiv for "ZipMPC" and "Differentiable MPC".
ZipMPC is a supervised imitation-learning framework for learning a context-dependent cost function for short-horizon model predictive control (MPC). It is designed for settings in which long-horizon MPC yields desirable behavior but is computationally too expensive for real-time deployment. The method trains a neural network to map the current state and long-horizon environmental context into cost parameters for a short-horizon constrained MPC, so that the resulting controller imitates a well-tuned long-horizon expert while retaining online runtime close to that of the short-horizon problem [2507.13088].

## 1. Problem setting and conceptual scope

ZipMPC addresses a standard tradeoff in model predictive control. Long-horizon MPC can optimize behavior with respect to long-term objectives because it reasons farther into the future, but its optimization problem grows with horizon length and can become impractical for real-time systems. Short-horizon MPC is computationally cheaper and therefore real-time feasible, but it often behaves myopically because it lacks future information. The paper emphasizes that this tradeoff is not only computational: short horizons also make cost design substantially harder, because a stage cost that works well under a long horizon may fail to align local decisions with the desired long-term task objective when the controller cannot anticipate distant consequences [2507.13088].

ZipMPC is proposed precisely for the question of how to design a short-horizon MPC cost that preserves the behavior and long-term objective of a well-performing long-horizon MPC. Its core idea is to learn a compressed, context-dependent short-horizon cost rather than a direct policy \(u=\pi(x)\). In this formulation, the system dynamics, the constraint structure, and the online optimization layer remain explicit. What changes online is the objective of the short-horizon MPC, conditioned on the current situation and on information lying beyond the short horizon [2507.13088].

The term “compressed context-dependent MPC cost” has two specific meanings in the paper. “Compressed” means that the effect of long-horizon future information is not represented by explicitly optimizing over the full long horizon; instead, it is summarized into a lower-dimensional set of cost parameters for the short-horizon problem. “Context-dependent” means that the cost is not globally fixed, but changes with state and environment. In the racing experiments, the context is a long-horizon sequence of track curvatures ahead of the vehicle, which provides exactly the kind of future geometric information a short-horizon controller would otherwise miss [2507.13088].

A common ambiguity in the literature concerns the acronym “MPC.” In ZipMPC it denotes model predictive control, not secure multi-party computation; the latter usage appears in unrelated systems-oriented work such as "SMT-Boosted Security Types for Low-Level MPC" [2501.17824].

## 2. Mathematical formulation and learned cost structure

The paper formulates a context-dependent discrete-time system as
$$
x(k+1)=f(x(k),u(k),\zeta(k)),
$$
where \(x\in\mathbb{R}^n\) is the state, \(u\in\mathbb{R}^m\) is the control input, and \(\zeta\in\mathbb{R}^a\) is environmental context. For prediction horizon \(N\), the MPC problem is written as
$$
\begin{aligned}
[X_{k,N}^*,U_{k,N}^*] := \mathit{MPC}_N(C_N,x(k))
= \arg\min_{\{x_i\}_{0}^{N+1},\{u_i\}_{0}^{N}}
& \sum_{i=0}^{N}\ell(x_i,u_i,c_i) \\
\text{s.t.}\quad
& x_0=x(k), \\
& x_{i+1}=f(x_i,u_i,\zeta_i), \\
& x_i\in\mathcal{X},\quad u_i\in\mathcal{U}, \\
& i=0,\ldots,N .
\end{aligned}
$$
Here \(c_i\in\mathbb{R}^b\) are stage-cost parameters and \(C_N:=\{c_i\}_{0}^{N}\). Only the first control \(u_0^*\) is applied before the problem is re-solved at the next step. The formulation deliberately omits terminal ingredients, motivated by the observation that sufficiently long horizons may already produce good performance and that terminal cost or constraint design can itself be difficult [2507.13088].

The expert controller is a long-horizon MPC with horizon \(N_L\),
$$
[X_{k,N_L}^*,U_{k,N_L}^*] := \mathit{MPC}_{N_L}(C^M_{N_L},x(k)),
$$
where \(C^M_{N_L}\) is manually tuned. The learned controller is a short-horizon MPC with \(N_S<N_L\),
$$
[X_{k,N_S}^{\theta},U_{k,N_S}^{\theta}] := \mathit{MPC}_{N_S}(C^\theta_{N_S},x(k)).
$$
Learning is posed as trajectory imitation:
$$
\theta^* := \arg\min_{\theta}\mathbb{E}_k\big[\mathcal{L}([X_{k,N_S}^{\theta},U_{k,N_S}^{\theta}],
[X_{k,N_L}^*,U_{k,N_L}^*])\big].
$$
Because the horizons differ, the comparison uses only the first part of the trajectories; conceptually this is the first \(N_S\) steps, while the implementation uses only the first \(N_D\leq N_S\) steps [2507.13088].

The central parameterization is
$$
C^\theta_{N_S}=h^\theta(x(k),Z_{k,N_L}),
$$
where \(h^\theta\) is a neural network and \(Z_{k,N_L}\) is the contextual sequence carrying long-horizon information. In implementation, ZipMPC learns a residual correction on top of a manual warm start:
$$
\Delta C^\theta_{N_S}=h^\theta(x(k),Z_{k,N_L}), \qquad
C^\theta_{N_S}=C^M_{N_S}+\Delta C^\theta_{N_S}.
$$
Accordingly, the method does not predict the entire cost from scratch; it learns how to modify a standard short-horizon cost so that the resulting short-horizon optimizer behaves like the long-horizon expert [2507.13088].

For autonomous racing, the short-horizon controller is a model predictive contouring controller (MPCC) in Frenet coordinates with quadratic stage cost. The per-stage parameter is
$$
c_i=[q_i,p_i], \qquad q_i,p_i\in\mathbb{R}^{n+m},
$$
and the stage objective takes the quadratic-plus-linear form
$$
\sum_{i=0}^{N}\|[x_i,u_i]\|_{q_i}^2+\langle p_i,[x_i,u_i]\rangle .
$$
The network predicts both \(Q_{N_S}^\theta\) and \(P_{N_S}^\theta\), denoted in the paper by mappings \(h_Q^\theta\) and \(h_P^\theta\) [2507.13088].

## 3. Differentiable training pipeline

Training requires gradient propagation through the short-horizon MPC solution map. The paper writes the loss gradient as
$$
\frac{\partial \mathcal{L}}{\partial \theta}
=
\frac{\partial \mathcal{L}}{\partial [X_{k,N_S}^{\theta},U_{k,N_S}^{\theta}]}
\cdot
\frac{\partial [X_{k,N_S}^{\theta},U_{k,N_S}^{\theta}]}{\partial C^\theta_{N_S}}
\cdot
\frac{\partial C^\theta_{N_S}}{\partial \theta}.
$$
The difficult term is the derivative of the MPC solution with respect to the cost parameters. For this, ZipMPC uses the differentiable MPC method of Amos et al. (2018), based on iLQR-style approximations and KKT-based differentiation [2507.13088; 1810.13400].

The data generation and optimization pipeline is explicit. A feasible initial state \(x(k)\) is sampled, the long-horizon expert \(\mathit{MPC}_{N_L}(C^M_{N_L},x(k))\) is solved, and its optimal predicted trajectory is used as supervision. The neural network receives the current state and context sequence, predicts the cost correction \(\Delta C^\theta_{N_S}\), forms the learned cost \(C^\theta_{N_S}=C^M_{N_S}+\Delta C^\theta_{N_S}\), solves the short-horizon MPC, compares the resulting trajectory with the expert trajectory, and updates \(\theta\) by backpropagation using Adam. Algorithm 1 is executed in mini-batches [2507.13088].

The imitation objective is mean squared error over trajectories:
$$
\mathcal{L}\gets \mathrm{MSE}_{N_D}([X^*_{k,N_L},U^*_{k,N_L}],
[X^\theta_{k,N_S},U^\theta_{k,N_S}]).
$$
The appendix clarifies that the loss is the sum of MSE on state variables and MSE on control variables, that only the first \(N_D\leq N_S\) steps are used, and that variables are manually weighted because their scales differ. The training target is therefore trajectory and action imitation rather than direct matching of cost parameters [2507.13088].

Several stabilization measures are reported. The residual formulation provides a warm start via the manual short-horizon cost. Infeasible initial states are excluded. Because the differentiable MPC approximation uses soft state constraints, samples for which the differentiable solver mismatches a standard solver beyond a tolerance are also excluded from gradient computation. Validation and model selection are based on lap performance on a fixed initial state; this is described as especially important for the Pacejka model because of nonconvexity [2507.13088].

## 4. Architecture, context encoding, and deployment behavior

The input to the neural network consists of three state-derived global variables, \(v\), \(d\), and \(\phi\), together with the context time series \(Z_{k,N_L}\), which is a sequence of upcoming track curvatures. This sequence is formed starting from the current progress \(\sigma(k)\) and collecting curvature values up to the maximum possible progress \(\sigma_\Delta\) achievable over the long horizon; the appendix gives the example
$$
\sigma_\Delta = T\cdot N_L\cdot v_{\max}.
$$
In the racing setting, this context representation is intended to supply the information gap between \(N_S\) and \(N_L\), such as upcoming curvature that would matter for preparatory positioning and speed adaptation [2507.13088].

The network architecture combines a convolutional feature extractor for the curvature time series with batch normalization and dropout, followed by four fully connected layers, each with 512 hidden units and LeakyReLU activation. The final shared representation branches into two outputs: a global representation layer producing a fixed component of the MPC cost, and a modulation layer producing time-varying components. The modulation layer has output dimension
$$
2\times N_S\times (n+m),
$$
because it predicts both \(P_{N_S}^{\theta}\) and \(Q_{N_S}^{\theta}\). The final output is scaled to keep predicted parameters within a certain range, although the exact range is specified in code rather than in the paper text [2507.13088].

At deployment time, the controller measures the current state \(x(k)\), extracts the context sequence \(Z_{k,N_L}\) from environment geometry, runs the neural network to obtain \(\Delta C^\theta_{N_S}\), forms \(C^\theta_{N_S}\), solves the short-horizon MPC using the known dynamics and constraints, and applies the first control action. The online computational budget is therefore described as the cost of neural-network inference plus the solve time of the short-horizon MPC [2507.13088].

The paper emphasizes that ZipMPC learns the cost rather than the control action directly. What remains fixed is the dynamics model \(f\), the MPC constraint structure, the short horizon \(N_S\), the long-horizon expert formulation, and the manual base cost \(c^M\). What is learned is the mapping \(h^\theta\), equivalently the cost correction \(\Delta C^\theta_{N_S}\), or the short-horizon cost parameters \(Q^\theta_{N_S}\) and \(P^\theta_{N_S}\). This distinction is central to the method’s claim of preserving structured constraint-aware control [2507.13088].

## 5. Autonomous racing instantiation and experimental evidence

The main application domain is autonomous racing in Frenet coordinates, evaluated in simulation with a kinematic bicycle model and a more complex Pacejka vehicle model, and in real-world experiments with a 1/28-scaled miniature race car. For the kinematic model, the state is
$$
x=[\sigma,d,\phi,v],
$$
with inputs acceleration \(a\) and steering angle \(\delta\). For the Pacejka model, the state is
$$
x=[\sigma,d,\phi,r,v_x,v_y],
$$
with inputs motor torque \(\tau\) and steering angle \(\delta\). The racing MPCC uses the track boundary constraint
$$
-\omega \le d_i \le \omega,
$$
together with polyhedral constraints
$$
G[x_i,u_i]^\top \le g.
$$
Tracks have constant width \(2\omega\), and context is based on track curvature \(\kappa(\sigma)\) [2507.13088].

The experimental baselines are the long-horizon expert \(\mathit{MPC}_{N_L}\), the short-horizon controller \(\mathit{MPC}_{N_S}\), a Bayesian-optimization baseline that tunes a constant \(\Delta\)-cost to minimize imitation loss between short and long MPC, and an eMPC baseline consisting of a neural network policy that clones the long-horizon MPC directly. The paper also situates ZipMPC conceptually against approximate explicit MPC and automatic cost parameter tuning, though not all such methods are direct empirical baselines [2507.13088].

On the kinematic model, ZipMPC achieves the lowest trajectory imitation RMSE in all tested horizon settings. For \(N_S=5, N_L=25\), the reported trajectory RMSE is \(0.203\pm0.004\) for short MPC, \(0.150\pm0.006\) for the BO baseline, \(0.086\pm0.009\) for eMPC, and \(0.068\pm0.009\) for ZipMPC. For \(N_S=10, N_L=25\), the corresponding values are \(0.088\pm0.008\), \(0.086\pm0.008\), \(0.108\pm0.007\), and \(0.043\pm0.012\), respectively [2507.13088].

Lap-time results show the same pattern. For the kinematic model with \(N_S=5, N_L=25\), long-horizon MPC achieves \(8.286\pm0.012\) s, short-horizon MPC \(9.103\pm0.043\) s, BO \(8.955\pm0.028\) s, eMPC does not complete the lap, and ZipMPC achieves \(8.394\pm0.012\) s. For \(N_S=10, N_L=25\), long-horizon MPC remains at \(8.286\pm0.012\) s, short-horizon MPC achieves \(8.556\pm0.018\) s, BO \(8.610\pm0.013\) s, and ZipMPC \(8.325\pm0.015\) s. These results place ZipMPC close to the long-horizon reference while maintaining short-horizon computational characteristics [2507.13088].

The Pacejka results are more severe because short horizons can fail to complete the lap. For \(N_S=6, N_L=35\), long-horizon MPC achieves \(11.09\pm0.07\) s, short-horizon MPC does not complete, and ZipMPC achieves \(13.83\pm0.43\) s, successful in at least 80% of attempts, with execution time reduction \(82.5\pm1.1\%\). For \(N_S=6, N_L=45\), long-horizon MPC achieves \(9.89\pm0.10\) s, short-horizon MPC does not complete, and ZipMPC achieves \(12.82\pm0.33\) s, with execution time reduction \(87.9\pm0.4\%\). For \(N_S=12, N_L=45\), short-horizon MPC achieves \(20.36\pm0.20\) s, whereas ZipMPC achieves \(12.82\pm0.28\) s, with execution time reduction \(76.6\pm0.5\%\) [2507.13088].

The runtime appendix supports the claim that ZipMPC remains near the computational cost of short-horizon MPC. For the kinematic model with \(N_S=5, N_L=25\), \(\mathit{MPC}_{N_S}\) runs at \(60\pm16\) ms, \(\mathit{MPC}_{N_L}\) at \(287\pm102\) ms, and ZipMPC at \(61\pm16\) ms. For the Pacejka model with \(N_S=6, N_L=45\), the corresponding values are \(65\pm59\) ms, \(704\pm337\) ms, and \(66\pm59\) ms [2507.13088].

## 6. Generalization, interpretation, and limitations

A central empirical claim is generalization to unseen environments. The training procedure uses a single track containing diverse curvature sequences, while evaluation is performed both on that track and on two unseen tracks of different lengths and curvature patterns. For the kinematic model with \(N_S=5, N_L=25\), lap times are \(8.286\) for long MPC, \(9.090\) for short MPC, and \(8.394\) for ZipMPC on the training track; \(6.273\), \(6.891\), and \(6.312\) on Test 1; and \(8.790\), \(9.537\), and \(8.823\) on Test 2. For the Pacejka model with \(N_S=12, N_L=45\), the train-track times are \(9.894\), \(20.361\), and \(12.822\); Test 1 gives \(8.718\), \(15.123\), and \(12.000\); Test 2 gives \(10.245\), \(17.736\), and \(15.123\). The paper stresses that the unseen tracks are chosen so that curvature steepness does not extrapolate beyond training support [2507.13088].

The ablation study isolates the importance of context dependence by comparing \(h_Q^\theta(x(k),Z_{k,N_L})\) and \(h_P^\theta(x(k),Z_{k,N_L})\) against context-free variants depending only on \(x(k)\). The reported result is that context provides substantial improvement, especially when \(N_S\) is much smaller than \(N_L\), while the benefit diminishes as \(N_S\) approaches \(N_L\). The paper also analyzes a learned linear cost component \(p_d\) associated with lateral deviation, reporting that right-hand curves lead to positive learned \(p_d\), left-hand curves lead to negative learned \(p_d\), and that \(p_d\) strongly correlates with average upcoming curvature. This supports an interpretable reading of the learned cost shaping [2507.13088].

The real-world setup uses the Chronos and CRS test bench, with a 1/28-scaled miniature car, pose measurement by a motion capture system, a server running the control algorithm, WiFi communication, and racing on a predefined track. ZipMPC is trained in simulation and deployed on hardware without retraining. The hardware results are mostly qualitative in the main text, but they include the observation that ZipMPC improves trajectories over short-horizon MPC and, in one additional setting with \(N_S=10, N_L=25\), that short-horizon MPC gets stuck at the third corner after 4 seconds while ZipMPC completes the lap [2507.13088].

The method’s strengths, assumptions, and limitations are stated explicitly. The claimed strengths are near long-horizon performance with short-horizon runtime, preservation of model-based structured constraint handling, improved alignment with long-term objectives, better generalization than direct policy cloning baselines, and interpretable adaptation of learned cost parameters. The assumptions are access to a good long-horizon expert MPC, a sufficiently accurate known dynamics model, a differentiable MPC implementation providing useful gradients, runtime access to contextual variables such as future curvature, and a representative feasible training set. The limitations include dependence on the differentiable MPC approximation, sensitivity to infeasible training samples, nonconvexity of the learning problem, imperfect handling of hard state constraints during differentiable training, lack of automatic inheritance of theoretical guarantees from the expert MPC, and the absence of a detailed study of noisy or partial context [2507.13088].

In that sense, ZipMPC occupies a specific point in the design space. It does not learn dynamics, and it does not replace constrained optimization by an unconstrained policy network. Instead, it learns how to shape the objective of a constrained short-horizon MPC so that future information, compressed into context-conditioned cost parameters, can substitute for explicit long-horizon optimization at deployment time [2507.13088].

Source: https://www.emergentmind.com/topics/zipmpc