Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Adjoints and the Discrete-Time Pontryagin Principle

Finite-horizon optimal control produces a structured nonlinear program and the KKT conditions characterize its local solutions. How do those multipliers organize themselves when the equality constraints are a forward dynamical recursion?

If we take the Bolza formulation of the DOCP and apply the KKT conditions directly, we obtain an optimization system with many multipliers and constraints. Written in raw form, it looks like any other nonlinear program. But in control, this structure has a long history and a name of its own: the Pontryagin principle. In fact, the discrete-time version can be seen as the structured KKT system that results from introducing multipliers for the dynamics and collecting terms stage by stage.

We work with the Bolza program

min{xt,ut}cT(xT)  +  t=1T1ct(xt,ut)s.t.xt+1=ft(xt,ut),t=1,,T1,gt(xt,ut)0,utUt,h(xT)=0(optional terminal equalities).\begin{aligned} \min_{\{\mathbf{x}_t,\mathbf{u}_t\}} \quad & c_T(\mathbf{x}_T)\;+\;\sum_{t=1}^{T-1} c_t(\mathbf{x}_t,\mathbf{u}_t) \\ \text{s.t.}\quad & \mathbf{x}_{t+1}=\mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t),\quad t=1,\dots,T-1,\\ & \mathbf{g}_t(\mathbf{x}_t,\mathbf{u}_t)\le \mathbf{0},\quad \mathbf{u}_t\in \mathcal{U}_t,\\ & \mathbf{h}(\mathbf{x}_T)=\mathbf{0}\quad\text{(optional terminal equalities)}. \end{aligned}

Introduce costates λt+1Rn\boldsymbol{\lambda}_{t+1}\in\mathbb{R}^n for the dynamics, multipliers μt0\boldsymbol{\mu}_t\ge \mathbf{0} for path inequalities, and ν\boldsymbol{\nu} for terminal equalities. The Lagrangian is

L=cT(xT)+t=1T1ct(xt,ut)+t=1T1λt+1 ⁣(ft(xt,ut)xt+1)+t=1T1μtgt(xt,ut)+νh(xT).\mathcal{L} = c_T(\mathbf{x}_T) + \sum_{t=1}^{T-1} c_t(\mathbf{x}_t,\mathbf{u}_t) + \sum_{t=1}^{T-1} \boldsymbol{\lambda}_{t+1}^\top\!\big(\mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t)-\mathbf{x}_{t+1}\big) + \sum_{t=1}^{T-1} \boldsymbol{\mu}_t^\top \mathbf{g}_t(\mathbf{x}_t,\mathbf{u}_t) + \boldsymbol{\nu}^\top \mathbf{h}(\mathbf{x}_T).

It is convenient to package the stagewise terms in a Hamiltonian

Ht(xt,ut,λt+1,μt):=ct(xt,ut)+λt+1ft(xt,ut)+μtgt(xt,ut).H_t(\mathbf{x}_t,\mathbf{u}_t,\boldsymbol{\lambda}_{t+1},\boldsymbol{\mu}_t) := c_t(\mathbf{x}_t,\mathbf{u}_t) + \boldsymbol{\lambda}_{t+1}^\top \mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t) + \boldsymbol{\mu}_t^\top \mathbf{g}_t(\mathbf{x}_t,\mathbf{u}_t).

Then

L=cT(xT)+νh(xT)+t=1T1[Ht(xt,ut,λt+1,μt)λt+1xt+1].\mathcal{L} = c_T(\mathbf{x}_T)+\boldsymbol{\nu}^\top \mathbf{h}(\mathbf{x}_T) + \sum_{t=1}^{T-1}\Big[H_t(\mathbf{x}_t,\mathbf{u}_t,\boldsymbol{\lambda}_{t+1},\boldsymbol{\mu}_t) - \boldsymbol{\lambda}_{t+1}^\top \mathbf{x}_{t+1}\Big].

Necessary conditions

How do state feasibility, costate recursion, control stationarity, and complementarity emerge from the stagewise Lagrangian?

Taking first-order variations and collecting terms gives the discrete-time adjoint system, control stationarity, and complementarity. At a local minimum {xt,ut}\{\mathbf{x}_t^\star,\mathbf{u}_t^\star\} with multipliers {λt,μt,ν}\{\boldsymbol{\lambda}_t^\star,\boldsymbol{\mu}_t^\star,\boldsymbol{\nu}^\star\}:

State dynamics (primal feasibility)

xt+1=ft(xt,ut),t=1,,T1.\mathbf{x}_{t+1}^\star=\mathbf{f}_t(\mathbf{x}_t^\star,\mathbf{u}_t^\star),\quad t=1,\dots,T-1.

Costate recursion (backward “adjoint” equation)

λt=xHt(xt,ut,λt+1,μt)=xct(xt,ut)+[xft(xt,ut)]λt+1+[xgt(xt,ut)]μt,\boldsymbol{\lambda}_t^\star = \nabla_{\mathbf{x}} H_t\big(\mathbf{x}_t^\star,\mathbf{u}_t^\star,\boldsymbol{\lambda}_{t+1}^\star,\boldsymbol{\mu}_t^\star\big) = \nabla_{\mathbf{x}} c_t(\mathbf{x}_t^\star,\mathbf{u}_t^\star) + \big[\nabla_{\mathbf{x}} \mathbf{f}_t(\mathbf{x}_t^\star,\mathbf{u}_t^\star)\big]^\top \boldsymbol{\lambda}_{t+1}^\star + \big[\nabla_{\mathbf{x}} \mathbf{g}_t(\mathbf{x}_t^\star,\mathbf{u}_t^\star)\big]^\top \boldsymbol{\mu}_t^\star,

with the terminal condition

λT=xcT(xT)+[xh(xT)]ν(and ν=0 if there are no terminal equalities).\boldsymbol{\lambda}_T^\star = \nabla_{\mathbf{x}} c_T(\mathbf{x}_T^\star) + \big[\nabla_{\mathbf{x}} \mathbf{h}(\mathbf{x}_T^\star)\big]^\top \boldsymbol{\nu}^\star \quad\text{(and \(\boldsymbol{\nu}^\star=\mathbf{0}\) if there are no terminal equalities).}

Control stationarity (first-order optimality in ut\mathbf{u}_t) If Ut=Rm\mathcal{U}_t=\mathbb{R}^m (no explicit set constraint), then

uHt(xt,ut,λt+1,μt)=0.\nabla_{\mathbf{u}} H_t\big(\mathbf{x}_t^\star,\mathbf{u}_t^\star,\boldsymbol{\lambda}_{t+1}^\star,\boldsymbol{\mu}_t^\star\big)=\mathbf{0}.

If Ut\mathcal{U}_t imposes bounds or a convex set, the condition becomes the variational inequality

0uHt()  +  NUt(ut),\mathbf{0}\in \nabla_{\mathbf{u}} H_t(\cdot)\;+\;N_{\mathcal{U}_t}(\mathbf{u}_t^\star),

where NUt()N_{\mathcal{U}_t}(\cdot) is the normal cone to Ut\mathcal{U}_t. For simple box bounds, this reduces to standard KKT sign and complementarity conditions on the components of ut\mathbf{u}_t^\star.

Path-constraint multipliers (primal/dual feasibility and complementarity)

gt(xt,ut)0,μt0,μt,igt,i(xt,ut)=0for all i,t.\mathbf{g}_t(\mathbf{x}_t^\star,\mathbf{u}_t^\star)\le \mathbf{0},\quad \boldsymbol{\mu}_t^\star\ge \mathbf{0},\quad \mu_{t,i}^\star\, g_{t,i}(\mathbf{x}_t^\star,\mathbf{u}_t^\star)=0\quad \text{for all }i,t.

Terminal equalities (if present)

h(xT)=0.\mathbf{h}(\mathbf{x}_T^\star)=\mathbf{0}.

The triplet “forward state, backward costate, control stationarity” is the discrete-time Euler–Lagrange system tailored to control with dynamics. It is the same KKT logic as before, but organized stagewise through the Hamiltonian.

Recap. The discrete-time Pontryagin principle is the KKT system for trajectory optimization, organized to exploit temporal structure. It has a forward-backward decomposition: states propagate forward through the dynamics, while costates propagate backward through the adjoint equation. The Hamiltonian HtH_t packages together the stage cost, the dynamics (weighted by the next costate), and any path constraints (weighted by their multipliers). Control stationarity says that optimal controls minimize the Hamiltonian at each stage. Complementarity ensures that only binding constraints carry nonzero multipliers. This structure underlies both analytical solution methods (such as LQR) and numerical algorithms (such as the adjoint method for gradient computation).

The adjoint equation as reverse accumulation

The costate equations characterize stationarity, but can the same backward recursion compute every control derivative with one reverse sweep?

Optimization needs sensitivities. In trajectory problems we adjust decisions (controls or parameters) to reduce an objective while respecting dynamics and constraints. First‑order methods in the unconstrained case (e.g., gradient descent, L‑BFGS, Adam) require the gradient of the objective with respect to all controls, and constrained methods (SQP, interior‑point) require gradients of the Lagrangian, i.e., of costs and constraints. The discrete‑time adjoint equations provide these derivatives in a way that scales to long horizons and many decision variables.

Consider

J=cT(xT)+t=1T1ct(xt,ut),xt+1=ft(xt,ut).J = c_T(\mathbf{x}_T) + \sum_{t=1}^{T-1} c_t(\mathbf{x}_t,\mathbf{u}_t), \qquad \mathbf{x}_{t+1}=\mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t).

A single forward rollout computes and stores the trajectory x1:T\mathbf{x}_{1:T}. A single backward sweep then applies the reverse‑mode chain rule stage by stage.

Defining the costate by

λT=xcT(xT),λt=xct(xt,ut)+[xft(xt,ut)]λt+1,t=T1,,1,\boldsymbol{\lambda}_T = \nabla_{\mathbf{x}} c_T(\mathbf{x}_T),\qquad \boldsymbol{\lambda}_t = \nabla_{\mathbf{x}} c_t(\mathbf{x}_t,\mathbf{u}_t) + \big[\nabla_{\mathbf{x}} \mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t)\big]^\top \boldsymbol{\lambda}_{t+1},\quad t=T-1,\dots,1,

yields exactly the discrete‑time adjoint (PMP) recursion.

The gradient with respect to each control follows from the same reverse pass:

utJ=uct(xt,ut)+[uft(xt,ut)]λt+1.\nabla_{\mathbf{u}_t} J = \nabla_{\mathbf{u}} c_t(\mathbf{x}_t,\mathbf{u}_t) + \big[\nabla_{\mathbf{u}} \mathbf{f}_t(\mathbf{x}_t,\mathbf{u}_t)\big]^\top \boldsymbol{\lambda}_{t+1}.

This reverse accumulation produces every control gradient with one forward rollout and one backward adjoint pass. The costate λt\boldsymbol{\lambda}_t measures the marginal effect of perturbing the state at time tt on the total objective. Each control gradient combines a direct contribution from ctc_t with an indirect contribution through the next state. Backpropagation through an unrolled dynamical system performs the same calculation.

Finite differences instead perturb one decision at a time and rerun the system. They require on the order of pp rollouts for p=(T1)mp=(T-1)m control variables and introduce a finite-difference step size. Forward-mode sensitivities propagate a separate Jacobian-vector product for each parameter direction, so their work also scales with pp. Reverse mode propagates one costate vector backward and reads all partial derivatives from that sweep. For a scalar objective, this replaces one rollout per parameter by one forward-backward pass, at the cost of storing or checkpointing the state trajectory.

The adjoint recursion is therefore the reverse-mode derivative of the trajectory objective. States carry the nominal trajectory forward, costates carry its sensitivity backward, and the local control derivatives combine the two at each stage.

Summary and Outlook

The KKT conditions organize local optimality into primal feasibility, stationarity, dual feasibility, and complementarity. Applied along a trajectory, they give the discrete-time Pontryagin principle. States propagate forward, costates propagate backward, and the Hamiltonian supplies the local control stationarity condition. The same backward recursion computes all control gradients with one reverse pass.

The necessary conditions do not choose how states and actions should be exposed to a numerical solver. Should the states remain decision variables, be eliminated by forward simulation, or appear only at segment boundaries? Numerical trajectory optimization compares those formulations.

Exercises

Solution to Exercise 1

By definition, Vt(xt)V_t(x_t) is the minimum future cost starting from xtx_t. At the optimal trajectory, the envelope theorem gives xtVt=λt\nabla_{x_t} V_t = \lambda_t, the marginal value of the state. Economically, λt\lambda_t measures how much the optimal cost would decrease if we could perturb the state xtx_t by a small amount—it is the “shadow price” of the state at time tt.


Solution to Exercise 2

For controls u=[0,0,0]u = [0, 0, 0]: forward simulation gives x1=0.5x_1 = 0.5, x2=0.25x_2 = 0.25, x3=0.0625x_3 = 0.0625, x4=0.00390625x_4 = 0.00390625.

Adjoint: λ4=1\lambda_4 = 1, λ3=2(0.0625)(1)=0.125\lambda_3 = 2(0.0625)(1) = 0.125, λ2=2(0.25)(0.125)=0.0625\lambda_2 = 2(0.25)(0.125) = 0.0625, λ1=2(0.5)(0.0625)=0.0625\lambda_1 = 2(0.5)(0.0625) = 0.0625.

Control gradients: utJ=λt+1\nabla_{u_t} J = \lambda_{t+1}, so uJ=[λ2,λ3,λ4]=[0.0625,0.125,1.0]\nabla_u J = [\lambda_2, \lambda_3, \lambda_4] = [0.0625, 0.125, 1.0].

Finite differences should match. The adjoint is O(T)O(T) work regardless of the number of controls; finite differences require O(Tm)O(T \cdot m) rollouts for mm-dimensional control.