Real-time model predictive control places strict limits on computation. In applications such as adaptive optics, the controller must run at kilohertz rates. A sampling frequency of 1000 Hz allows only one millisecond per step to compute and apply a control input. This makes efficiency a first-class concern.
The structure of MPC lends itself naturally to optimization reuse. Each time step requires solving a problem with the same dynamics and constraints. Only the initial state, forecasts, or reference signals change. Instead of treating each instance as a new problem, we can frame MPC as a parametric optimization problem and focus on how the solution evolves with the parameter.
Can the previous solution, its local sensitivity, or a learned approximation replace part of the next online optimization without hiding when that approximation ceases to be valid?
General Framework: Parametric Optimization¶
How do the optimizer and optimal value change as the initial state, forecast, or reference parameter moves?
We begin with a general optimization problem indexed by a parameter :
For each value of , we obtain a concrete optimization problem. The goal is to understand how the optimizer and value function
depend on .
When the problem is smooth and regular, the Karush–Kuhn–Tucker (KKT) conditions characterize optimality:
If the active set remains fixed over changes in , the implicit function theorem ensures that the mappings
are differentiable.
In linear and quadratic programming, this structure becomes even more tractable. Consider a linear program with affine dependence on :
Each active set determines a basis and thus a region in where the solution is affine in . The feasible parameter space is partitioned into polyhedral regions, each with its own affine law.
Similarly, in strictly convex quadratic programs
each active set again leads to an affine optimizer, with piecewise-affine global structure and a piecewise-quadratic value function.
Parametric programming focuses on the structure of the map , and the regions over which this map takes a simple form.
Solution Sensitivity via the Implicit Function Theorem¶
We often meet equations of the form
where are unknowns and are parameters. The implicit function theorem says that, if is smooth and the Jacobian with respect to ,
is invertible at a solution , then in a neighborhood of there exists a unique smooth mapping with and . Moreover, its derivative is
In words: if the square Jacobian in is nonsingular, the solution varies smoothly with the parameter, and we can differentiate it by solving one linear system.
Return to and its KKT system. Collect the primal and dual variables into
and write the KKT equations as a single residual
Here denotes the set of inequality constraints active at the solution (the complementarity part is encoded by keeping fixed; see below).
To invoke IFT, we need the Jacobian to be invertible at . Standard regularity conditions that ensure this are:
LICQ (Linear Independence Constraint Qualification) at : the gradients of all active constraints are linearly independent.
Second-order sufficiency on the critical cone (the Lagrangian Hessian is positive definite on feasible directions).
Strict complementarity (optional but convenient): each active inequality has strictly positive multiplier.
Under these, the KKT matrix,
is nonsingular. Here .
The right-hand side sensitivity to parameters is
IFT then gives local differentiability of the optimizer and multipliers:
The formula above is valid as long as the active set does not change. If a constraint switches between active/inactive, the mapping remains piecewise smooth, but the derivative may jump. In MPC, this is exactly why warm-starts are very effective most of the time and occasionally require a refactorization when the active set flips.
In parametric MPC, gathers the current state, references, and forecasts. The IFT tells us that, under regularity and a stable active set, the optimal trajectory and first input vary smoothly with . The linear map is exactly the object used in sensitivity-based warm starts and real-time iterations: small changes in can be propagated through a single KKT solve to update the primal–dual guess before taking one or two Newton/SQP steps.
Predictor-Corrector MPC¶
We start with a smooth root-finding problem
Newton’s method iterates
or equivalently solves the linearized system
Convergence is local and fast when the Jacobian is nonsingular and the initial guess is close.
Now suppose the root depends on a parameter:
We want the solution path . Numerical continuation advances in small steps and uses the previous solution as a warm start for the next Newton solve. This is the simplest and most effective way to “track” solutions of parametric systems.
At a known solution , differentiate with respect to :
If is invertible (IFT conditions), the tangent is
This is exactly the implicit differentiation formula. Continuation uses it as a predictor:
Then a few corrector steps apply Newton to starting from . If Newton converges quickly, the step was appropriate; otherwise reduce and retry.
For parametric KKT systems, set where stacks the primal decision variables (states and inputs), and the KKT residual with collecting state, references, forecasts. The KKT matrix and parameter sensitivity give the tangent
Continuation then becomes:
Predictor: .
Corrector: a few Newton/SQP steps on the KKT equations at the new .
In MPC, this yields efficient warm starts across time. As the parameter (current state and references) changes slightly, we predict the new primal-dual point and correct with 1–2 iterations, which is often enough to reach tolerance in real time.
Amortized Optimization and Neural Approximation of Controllers¶
Can a trained function approximate the parametric optimizer closely enough to replace most online solves?
The idea of reusing structure across similar optimization problems is not exclusive to parametric programming. In machine learning, a related concept known as amortized optimization aims to reduce the cost of repeated inference by replacing explicit optimization with a function that has been learned to approximate the solution map. This approach shifts the computational burden from online solving to offline training.
The goal is to construct a function , typically parameterized by a neural network, that maps the input to an approximate solution or control action . Once trained, this map can be evaluated quickly at runtime, with no need to solve an optimization problem explicitly.
Amortized optimization has emerged in several contexts:
In probabilistic inference, where variational autoencoders (VAEs) amortize the computation of posterior distributions across a dataset.
In meta-learning, where the objective is to learn a model that generalizes across tasks by internalizing how to adapt.
In hyperparameter optimization, where learning a surrogate model can guide the search over configuration space efficiently.
This perspective has also begun to influence control. Recent work investigates how to amortize nonlinear MPC (NMPC) policies into neural networks. The training data come from solving many instances of the underlying optimal control problem offline. The resulting neural policy acts as a differentiable, low-latency controller that can generalize to new situations within the training distribution.
Compared to explicit MPC, which partitions the parameter space and stores exact solutions region by region, amortized control smooths over the domain by learning an approximate policy globally. It is less precise, but scalable to high-dimensional problems where enumeration of regions is impossible.
Neural network amortization is advantageous due to the expressivity of these models. However, the challenge is ensuring constraint satisfaction and safety, which are hard to guarantee with unconstrained neural approximators. Hybrid approaches attempt to address this by combining a neural warm-start policy with a final projection step, or by embedding the network within a constrained optimization layer. Other strategies include learning structured architectures that respect known physics or control symmetries.
Imitation Learning Framework¶
Which state distribution and supervised target make an approximate controller match the optimizer where it will actually be deployed? Consider a fixed horizon and parameter vector encoding the current state, references, and forecasts. The oracle MPC controller solves
The applied action is . Our goal is to learn a fast surrogate mapping that can be evaluated in microseconds, optionally followed by a safety projection layer.
Supervised learning from oracle solutions. One first samples parameters from the operational domain and solves the corresponding NMPC problems offline. The resulting dataset
is then used to train a neural network by minimizing
Once trained, the network acts as a surrogate for the optimizer, providing instantaneous evaluations that approximate the MPC law.
Example: Propofol Infusion Control¶
How does a parametric receding-horizon controller translate a measured patient state into a constrained infusion decision?
This problem explores the control of propofol infusion in total intravenous anesthesia (TIVA). Our presentation follows the problem formulation developped by Sawaguchi et al. (2008). The primary objective is to maintain the desired level of unconsciousness while minimizing adverse reactions and ensuring quick recovery after surgery.
The level of unconsciousness is measured by the Bispectral Index (BIS), which is obtained using an electroencephalography (EEG) device. The BIS ranges from 0 (complete suppression of brain activity) to 100 (fully awake), with the target range for general anesthesia typically between 40 and 60.
The goal is to design a control system that regulates the infusion rate of propofol to maintain the BIS within the target range. This can be formulated as an optimal control problem:
Where:
is the propofol infusion rate (mg/kg/h)
, , and are the drug concentrations in different body compartments
is the effect-site concentration
are rate constants for drug transfer between compartments
is the Bispectral Index
is a regularization parameter penalizing excessive drug use
, , , and are parameters of the pharmacodynamic model
The specific dynamics model used in this problem is so-called “Pharmacokinetic-Pharmacodynamic Model” and consists of three main components:
Pharmacokinetic Model, which describes how the drug distributes through the body over time. It’s based on a three-compartment model:
Central compartment (blood and well-perfused organs)
Shallow peripheral compartment (muscle and other tissues)
Deep peripheral compartment (fat)
Effect Site Model, which represents the delay between drug concentration in the blood and its effect on the brain.
Pharmacodynamic Model that relates the effect-site concentration to the observed BIS.
The propofol infusion control problem presents several interesting challenges from a research perspective. First, there is a delay in how fast the drug can reach a different compartments in addition to the BIS measurements which can lag. This could lead to instability if not properly addressed in the control design.
Furthermore, every patient is different from another. Hence, we cannot simply learn a single controller offline and hope that it will generalize to an entire patient population. We will account for this variability through Model Predictive Control (MPC) and dynamically adapt to the model mismatch through replanning. How a patient will react to a given dose of drug also varies and must be carefully controlled to avoid overdoses. This adds an additional layer of complexity since we have to incorporate safety constraints. Finally, the patient might suddenly change state, for example due to surgical stimuli, and the controller must be able to adapt quickly to compensate for the disturbance to the system.
Source
# label: fig-mpc-propofol
# caption: Closed-loop MPC for propofol infusion keeps the Bispectral Index near the target (top), regulates infusion rates (middle), and tracks the effect-site concentration (bottom).
%config InlineBackend.figure_format = 'retina'
import numpy as np
from scipy.optimize import minimize
import matplotlib.pyplot as plt
# Apply book style
try:
import scienceplots
plt.style.use(['science', 'notebook'])
except (ImportError, OSError):
pass # Use matplotlib defaults
class Patient:
def __init__(self, age, weight):
self.age = age
self.weight = weight
self.set_pk_params()
self.set_pd_params()
def set_pk_params(self):
self.v1 = 4.27 * (self.weight / 70) ** 0.71 * (self.age / 30) ** (-0.39)
self.v2 = 18.9 * (self.weight / 70) ** 0.64 * (self.age / 30) ** (-0.62)
self.v3 = 238 * (self.weight / 70) ** 0.95
self.cl1 = 1.89 * (self.weight / 70) ** 0.75 * (self.age / 30) ** (-0.25)
self.cl2 = 1.29 * (self.weight / 70) ** 0.62
self.cl3 = 0.836 * (self.weight / 70) ** 0.77
self.k10 = self.cl1 / self.v1
self.k12 = self.cl2 / self.v1
self.k13 = self.cl3 / self.v1
self.k21 = self.cl2 / self.v2
self.k31 = self.cl3 / self.v3
self.ke0 = 0.456
def set_pd_params(self):
self.E0 = 100
self.Emax = 100
self.EC50 = 3.4
self.gamma = 3
def pk_model(x, u, patient):
x1, x2, x3, xe = x
dx1 = -(patient.k10 + patient.k12 + patient.k13) * x1 + patient.k21 * x2 + patient.k31 * x3 + u / patient.v1
dx2 = patient.k12 * x1 - patient.k21 * x2
dx3 = patient.k13 * x1 - patient.k31 * x3
dxe = patient.ke0 * (x1 - xe)
return np.array([dx1, dx2, dx3, dxe])
def pd_model(ce, patient):
return patient.E0 - patient.Emax * (ce ** patient.gamma) / (ce ** patient.gamma + patient.EC50 ** patient.gamma)
def simulate_step(x, u, patient, dt):
x_next = x + dt * pk_model(x, u, patient)
bis = pd_model(x_next[3], patient)
return x_next, bis
def objective(u, x0, patient, dt, N, target_bis):
x = x0.copy()
total_cost = 0
for i in range(N):
x, bis = simulate_step(x, u[i], patient, dt)
total_cost += (bis - target_bis)**2 + 0.1 * u[i]**2
return total_cost
def mpc_step(x0, patient, dt, N, target_bis):
u0 = 10 * np.ones(N) # Initial guess
bounds = [(0, 20)] * N # Infusion rate between 0 and 20 mg/kg/h
result = minimize(objective, u0, args=(x0, patient, dt, N, target_bis),
method='SLSQP', bounds=bounds)
return result.x[0] # Return only the first control input
def run_mpc_simulation(patient, T, dt, N, target_bis):
rng = np.random.default_rng(2026)
steps = int(T / dt)
x = np.zeros((steps+1, 4))
bis = np.zeros(steps+1)
u = np.zeros(steps)
for i in range(steps):
# Add noise to the current state to simulate real-world uncertainty
x_noisy = x[i] + rng.normal(0, 0.01, size=4)
# Use noisy state for MPC planning
u[i] = mpc_step(x_noisy, patient, dt, N, target_bis)
# Evolve the true state using the deterministic model
x[i+1], bis[i] = simulate_step(x[i], u[i], patient, dt)
bis[-1] = pd_model(x[-1, 3], patient)
return x, bis, u
# Set up the problem
patient = Patient(age=40, weight=70)
T = 120 # Total time in minutes
dt = 0.5 # Time step in minutes
N = 20 # Prediction horizon
target_bis = 50 # Target BIS value
# Run MPC simulation
x, bis, u = run_mpc_simulation(patient, T, dt, N, target_bis)
# Plot results
t = np.arange(0, T+dt, dt)
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, figsize=(10, 12), sharex=True)
ax1.plot(t, bis)
ax1.set_ylabel('BIS')
ax1.set_ylim(0, 100)
ax1.axhline(y=target_bis, color='r', linestyle='--')
ax2.plot(t[:-1], u)
ax2.set_ylabel('Infusion Rate (mg/kg/h)')
ax3.plot(t, x[:, 3])
ax3.set_ylabel('Effect-site Concentration (µg/mL)')
ax3.set_xlabel('Time (min)')
plt.tight_layout()
print(f"Initial BIS: {bis[0]:.2f}")
print(f"Final BIS: {bis[-1]:.2f}")
print(f"Mean infusion rate: {np.mean(u):.2f} mg/kg/h")
print(f"Final effect-site concentration: {x[-1, 3]:.2f} µg/mL")Initial BIS: 100.00
Final BIS: 50.20
Mean infusion rate: 8.86 mg/kg/h
Final effect-site concentration: 3.39 µg/mL

Summary and Outlook¶
Parametric optimization treats successive MPC problems as members of one family rather than unrelated nonlinear programs. Sensitivity updates, predictor-corrector steps, and learned controller approximations trade online optimization time against approximation error and the need to detect a change of active set or operating regime.
MPC has now produced closed-loop behavior by solving a new finite-horizon problem after each observation. Can state-contingent decisions instead be computed across a family of possible states before the next state is known? Finite-horizon dynamic programming begins that second construction of feedback.
- Sawaguchi, Y., Furutani, E., Shirakami, G., Araki, M., & Fukuda, K. (2008). A Model-Predictive Hypnosis Control System Under Total Intravenous Anesthesia. IEEE Transactions on Biomedical Engineering, 55(3), 874–887. 10.1109/tbme.2008.915670