Constrained MDPs & Lagrangian Methods
Cost constraints, the primal–dual method and constrained policy optimization.
Add a single expected-cost constraint to an MDP and three classical facts fail at once: the optimal policy may have to randomize, it depends on where the agent starts, and Bellman's optimality equation over states no longer characterizes it. Yet the problem stays tractable: it is a linear program over occupancy measures, and its Lagrangian dual has no gap. This lesson proves both facts, follows the primal–dual dynamics that many deep safe-RL methods run and shows why they cycle, and derives the trust-region bound behind constrained policy optimization.
What you’ll learn
- Write a constrained MDP as a linear program over discounted occupancy measures, and prove that some optimal stationary policy randomizes in at most states when there are constraints.
- Prove that CMDPs have zero duality gap under Slater's condition from the convexity of the set of occupancy measures, and state the error term for parameterized policies.
- Explain why gradient descent–ascent on the bilinear Lagrangian cycles in the last iterate while its average converges, and derive how a proportional term damps the multiplier.
- Derive CPO's bound on a new policy's cost from the performance-difference lemma, and evaluate its worst-case constraint violation.
The linear program, and why optimal policies randomize
1. The objective and constraints are linear, and the feasible set is a nonempty polytope, bounded because summing the flow constraints forces . So an optimum exists. Any policy, history-dependent or not, has an occupancy measure satisfying the flow constraints, and the stationary policy built from it has the same occupancy measure, hence the same reward and costs:
2. Turn each cost constraint into an equality with a slack variable . There are now equality constraints, so a basic optimal solution, which exists whenever an optimum does and which the simplex method returns, has at most nonzero variables, slacks included:
Assume for every . Then every state has occupancy at least , so each uses at least one action. Subtracting one entry per state leaves the extra actions:
With this is the classical fact that some optimal policy is deterministic. Each binding constraint can cost one randomization; a constraint with slack costs none, since its positive slack uses up one of the places.
Part 3 is why there is no Bellman optimality equation over states alone. The budget is spent wherever the occupancy measure puts weight, so how much cost a state may incur depends on how often it will be visited, which depends on . In an unconstrained MDP a greedy policy is optimal from every state at once; in a CMDP the states compete for one shared budget.
One might hope to bypass all this: find the optimal multiplier , then run value iteration on . That gives the right value but not the right policy. At the Lagrangian is typically maximized by several deterministic policies, some infeasible, and the optimum is a particular mixture of them that only the constraints themselves pin down. In the three-route example of Safe & Robust RL, both route A (infeasible) and route B (suboptimal) maximize the Lagrangian at , and only the mixture with A one third of the time is optimal.
A CMDP has 50 states, 4 actions per state and 2 cost constraints, and gives every state positive probability. The simplex method returns a basic optimal solution of its linear program. At most how many states can the induced policy randomize in?
- 0: optimal policies can always be taken deterministic
- 4
- 2
- 50
Show the answer
C. 2
A basic solution has at most nonzero variables. All 50 states are visited, so each uses at least one action, which leaves at most 2 extra positive entries: two states mixing two actions each, or one state mixing three.
Strong duality without convexity
For finite CMDPs, linear-programming duality already gives . Deep RL works with continuous states and actions and with policies parameterized by networks, where and are non-concave in the parameters. It is not obvious that the dual, which every Lagrangian method solves, still has the right value.
Perturb the budgets by and record the optimal value as a function of the perturbation. , is nondecreasing in each , and where the perturbed problem is infeasible:
Concavity. Take near-optimal policies for and . Flip one coin with bias at the start of the episode and follow or throughout: this policy's occupancy measure is the mixture, and every is linear in the occupancy measure. (The set of occupancy measures is convex, so a stationary policy achieves the same mixture.)
Supporting hyperplane. Slater's policy is feasible for every slightly negative , so is interior to the domain of the concave , and has a non-vertical supporting hyperplane at . Its slope is nonnegative because is nondecreasing:
No gap. Any policy is feasible for its own perturbation , so . Rearranged, for every ; with weak duality:
The proof never uses convexity in the policy's parameters. What is convex is the set of achievable occupancy measures, and the objective and constraints are linear on it. Multipliers are also sensitivities: is a slope of at , the marginal value of loosening budget .
Paternain et al. extend the result to a parameterization that is -universal: every policy is matched by some to within in distance at every state. The proof rests on a lemma: policies -close at every state have normalized occupancy measures within in . A value is such an integral divided by , so values then differ by up to for rewards bounded by . With and , the parameterized dual value satisfies
where solves the dual of the problem with budgets tightened by . The paper prints in both places; with values defined as unnormalized discounted sums, one step of its proof appears to drop the factor that turns a normalized occupancy measure into a value. A two-state check shows the square is needed. If a fatal action that ends all reward is forced with probability at every step, the best policy in the class earns instead of at , , : a gap of 33, against and .
Rewards and costs lie in , , the network class matches every policy to within in at every state, and . How far below can the parameterized dual value be, according to the bound?
Show the answer
5
, out of a largest possible return of . The gap is linear in , but it is amplified by the square of the effective horizon and by the multipliers: at the same bound is 500, larger than any return, and a tightly binding constraint, with a large , makes small policy-approximation errors expensive.
Primal–dual learning: a game that cycles
Every Lagrangian method alternates a policy step on with a multiplier step. In occupancy coordinates the Lagrangian is bilinear (dropping the factor ),
so the method is gradient play in a zero-sum game between a policy player choosing in the occupancy polytope and a price player choosing . Its saddle points are exactly the pairs . Bilinear games are the hard case for gradient dynamics (Learning Dynamics in Games).
The smallest bilinear game: , with maximizing and minimizing, and its saddle at . Simultaneous gradient steps of size :
The update is a rotation scaled by (eigenvalues ); expanding the squares, the cross terms cancel:
The distance to the saddle grows geometrically for every step size, and in continuous time the iterates circle forever. The averages converge anyway: with step sizes shrinking like (or tuned to the horizon ), projected gradient steps on bounded domains have regret for each player, and in a zero-sum game the average strategies of two no-regret players form an -saddle point with
In constrained RL the cycling appears as a cost that swings above and below the budget, with violations during training long after the average has settled. Three remedies are in use.
- Averaging. Report the mixture of past policies, a randomized policy, which is what a CMDP may need anyway. Natural policy gradient primal–dual methods come with guarantees for the averaged iterates (Ding et al., 2020).
- Optimism. Correct each step by the change in the gradient, as optimistic mirror descent does. ReLOAD (Moskovitz et al., 2023) proves last-iterate convergence in the convex occupancy formulation and carries the idea to deep RL.
- Damping. Treat the multiplier as a feedback controller and add proportional and derivative terms (Stooke, Achiam & Abbeel, 2020). A toy model shows why this works.
Let be the violation, in continuous time. Suppose that near the saddle the learning policy lowers its cost in proportion to how far the price exceeds . The standard multiplier update is pure integral control:
Differentiate the first equation and substitute the second: an undamped oscillator. The violation swings with angular frequency and never decays, so the constraint is broken half of the time, forever:
Add a proportional term, . Now , and the same substitution gives a damped oscillator with damping ratio :
For the violation decays without overshoot. The model is a caricature (a real policy responds with delays, its cost is estimated from noisy samples, and the multiplier is clipped at 0), but it explains what is observed: integral-only multipliers overshoot, and a term proportional to the violation reacts before the integral has built up. Stooke et al. also add a derivative term that reacts to how fast the cost is rising.
In the toy model with and , which proportional gain gives critical damping, ?
Show the answer
2
, so . The characteristic equation then has a double root at : the violation decays like without oscillating.
Constrained policy optimization
Averaged or damped Lagrangian methods satisfy the constraint eventually or on average. Constrained policy optimization (CPO; Achiam, Held, Tamar & Abbeel, 2017) aims for every iterate to be approximately feasible. That needs a way to predict a new policy's cost from data collected by the old one, and the tool is the one behind TRPO (TRPO & Monotonic Improvement). Below, is the normalized discounted state distribution from .
The performance-difference lemma for the cost, with the old policy's cost advantage:
The expectation is over the unknown . Swap in and pay for the swap: with the error is at most , and state distributions move at most in proportion to the per-state policy change (Achiam et al., 2017, Lemma 3):
Together they bound the new cost by quantities estimable from the old policy's data, plus a penalty for moving:
Pinsker's inequality and Jensen's inequality trade the TV penalty for a KL trust region. CPO maximizes the reward surrogate subject to the cost surrogate and the trust region:
If the update is solved exactly, the surrogate constraint holds, and the penalty term, with , bounds the violation (Achiam et al., 2017, Proposition 2):
With , and , how large is CPO's worst-case constraint violation ?
Show the answer
14
, times , divided by : about 14.0, in units of discounted cost, where costs in allow at most 100. The makes the worst case loose at long horizons; the bound explains the shape of the update, not the size of the violations seen in practice.
In practice CPO linearizes both surrogates around and replaces the KL by its quadratic approximation (the Fisher matrix). What remains is a convex problem with one linear and one quadratic constraint, whose two-variable dual is solved in closed form. If is infeasible, CPO instead takes a recovery step that only decreases the cost within the trust region. With sampled advantages and these approximations the guarantee is approximate, and violations during training still occur; on Safety Gym (Ray, Achiam & Amodei, 2019), Lagrangian versions of PPO and TRPO were the baselines beside CPO.
Key takeaways
- A finite CMDP is a linear program over occupancy measures: stationary policies suffice, and some optimal policy mixes in at most extra actions, but the optimum depends on and no Bellman equation over states characterizes it.
- Under Slater's condition there is no duality gap even for non-convex policy classes, because the set of occupancy measures is convex; multipliers are sensitivities to the budgets, and a parameterization costs at most (the paper prints ).
- Knowing gives the optimal value, not the optimal policy, which is a particular mixture of Lagrangian maximizers.
- Primal–dual learning is gradient play on a bilinear game: its last iterate cycles while averages converge; averaging, optimism, PID damping and regularization are the remedies.
- CPO bounds the next policy's cost from current data through the performance-difference lemma and a TV trust region; an exact update violates the budget by at most .
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
The zero-duality-gap theorem applies to CMDPs with network policies whose returns are non-concave in the parameters. Which property does its proof rest on?
- Concavity of in the policy parameters
- Convexity of the set of achievable occupancy measures, on which reward and costs are linear
- Finiteness of the state and action spaces
- The existence of a deterministic optimal policy
Show the answer
B. Convexity of the set of achievable occupancy measures, on which reward and costs are linear
Mixing two policies' occupancy measures is achievable and mixes their rewards and costs linearly, so the perturbation function is concave; Slater's condition then gives a supporting hyperplane, whose slope is . The parameterization enters only through a separate approximation error.
You know the optimal multiplier of a one-constraint CMDP exactly. Is every policy that maximizes the return for the reward optimal for the CMDP?
- Yes: encodes everything about the constraint
- Yes, provided the policy is deterministic
- No: is only an upper bound on the optimal value
- No: the maximizers at can include infeasible policies, and the optimum is a specific mixture of them
Show the answer
D. No: the maximizers at can include infeasible policies, and the optimum is a specific mixture of them
At the Lagrangian is typically maximized by several policies with different costs. They all have the same Lagrangian value , but only a mixture whose cost meets the budget with complementary slackness is optimal. In the three-route example, routes A and B both maximize it, and only one third A, two thirds B is optimal.
In Lagrangian PPO, the cost swings above and below the budget for thousands of iterations, while the average of the policy iterates is nearly feasible and optimal. What explains this?
- The step sizes are too small; larger steps would stop the oscillation
- Simultaneous gradient play on a bilinear saddle problem cycles in its last iterate while the averages of no-regret iterates converge
- The duality gap must be positive
- The constraint is infeasible
Show the answer
B. Simultaneous gradient play on a bilinear saddle problem cycles in its last iterate while the averages of no-regret iterates converge
The Lagrangian is bilinear in occupancy coordinates, and simultaneous gradient steps rotate around the saddle, spiraling out by per step in the simplest case. Averages converge at the rate set by the players' regret. Optimism, damping and regularization target the last iterate.
In CPO's worst-case violation , what happens to the bound if the trust-region radius is quadrupled, all else equal?
- It doubles
- It quadruples
- It is unchanged
- It halves
Show the answer
A. It doubles
The bound grows like , because Pinsker's inequality turns a KL radius into a TV radius by a square root. The horizon enters far more strongly: from to the factor grows a hundredfold.
Further reading
- E. Altman, Constrained Markov Decision Processes (Chapman & Hall/CRC, 1999).
- S. Paternain, L. Chamon, M. Calvo-Fullana & A. Ribeiro, "Constrained reinforcement learning has zero duality gap," NeurIPS (2019).
- J. Achiam, D. Held, A. Tamar & P. Abbeel, "Constrained policy optimization," ICML (2017).
- A. Stooke, J. Achiam & P. Abbeel, "Responsive safety in reinforcement learning by PID Lagrangian methods," ICML (2020).
- T. Moskovitz, B. O'Donoghue, V. Veeriah, S. Flennerhag, S. Singh & T. Zahavy, "ReLOAD: Reinforcement learning with optimistic ascent-descent for last-iterate convergence in constrained MDPs," ICML (2023).