Learning Optimal Control with MPC Layer

Jicheng Shi, Yingzhao Lian, Colin N. Jones

Abstract

Both the optimal value function and the optimal policy can be used to model an optimal controller based on the duality established by the Bellman equation. Even with this duality, no parametric model has been able to output both policy and value function with a common parameter set. In this paper, a unified structure is proposed with a parametric optimization problem. The policy and the value function modelled by this structure share all parameters, which enables seamless switching among reinforcement learning algorithms while continuing to learn. The Q-learning and policy gradient based on the proposed structure is detailed. An actor-critic algorithm based on this structure, whose actor and critic are both modelled by the same parameters, is validated by both linear and nonlinear control.

Introduction

Traditional control and modern machine learning often sit on opposite sides of a fence. Model Predictive Control (MPC) is a powerhouse in industry because it handles system constraints beautifully, but it requires an accurate mathematical model of the system. On the other hand, Reinforcement Learning (RL) can learn complex behaviors from scratch (model-free), but it often requires massive amounts of data, struggles with hard constraints, and can be a "black box" that is difficult to interpret.

This paper introduces a way to embed MPC as a differentiable layer within RL frameworks. By treating optimization as a neural network layer, the authors create a hybrid controller that benefits from the structured planning of MPC and the adaptive learning of RL, leading to faster convergence and better handling of constraints.

The MPC Layer as a Function Approximator

The core innovation is the MPC Layer. Instead of using a standard Deep Neural Network (DNN) to decide actions, the authors use a differentiable optimization problem. Using the Cvxpy library, the authors formulate an MPC problem where the parameters—such as stage costs, terminal costs, and system dynamics—are learnable. Because the optimization is differentiable, gradients can flow backward through the solver, allowing standard RL algorithms to update the MPC parameters directly from experience.

Integration with RL Frameworks

The MPC layer can be plugged into three major RL categories:

  • Value-Based (Q-Learning): The MPC's optimal cost function is used to approximate the Q-value.
  • Policy Gradient: The MPC’s first optimal control action serves as the mean of a policy distribution (e.g., a Gaussian policy).
  • Actor-Critic (A2C): Two MPC layers (or one shared one) act as both the actor (deciding the move) and the critic (evaluating the state).
Algorithm 1: Q-learning by MPC layer.

To speed up training, the authors use the Lagrangian function of the MPC problem to compute derivatives more efficiently, avoiding the need to differentiate through every step of the optimization solver's internal iterations. They also suggest a practical trick of using simple linear regression on initial historical data to "warm-start" the dynamics matrices ($A$ and $B$).

Key Insights and Advantages

  • Physical Meaning: Unlike weights in a standard neural network, the parameters in an MPC layer have physical interpretations (e.g., fuel penalties or system dynamics). This makes the learned model more interpretable.
  • Seamless Switching: Because the policy and value functions share the same underlying MPC structure and parameters, an agent can theoretically switch between different RL algorithms (like moving from Q-learning to Actor-Critic) while continuing to learn from the same parameter set.
  • Constraint Awareness: By embedding constraints directly into the MPC layer, the RL agent is "born" with an understanding of system limits, rather than having to learn them through trial and error.

Results and Future Work

The authors evaluated their approach using OpenAI Gym and PyTorch on both linear and nonlinear control tasks. The MPC-based RL algorithms exhibited a faster convergence rate compared to standard model-free RL because the MPC structure provides a strong "inductive bias." Furthermore, the MPC-based Q-learning handles continuous action spaces naturally because the underlying solver can find the minimum of the Q-function directly.

Despite these strengths, computational complexity remains a challenge. Solving an optimization problem in every forward pass is more expensive than standard DNN matrix multiplications. Future work will focus on scaling this approach to high-dimensional systems and extending it to highly nonlinear, non-convex dynamics while maintaining differentiability.

Summary updated

Abstract

Both the optimal value function and the optimal policy can be used to model an optimal controller based on the duality established by the Bellman equation. Even with this duality, no parametric model has been able to output both policy and value function with a common parameter set. In this paper, a unified structure is proposed with a parametric optimization problem. The policy and the value function modelled by this structure share all parameters, which enables seamless switching among reinforcement learning algorithms while continuing to learn. The Q-learning and policy gradient based on the proposed structure is detailed. An actor-critic algorithm based on this structure, whose actor and critic are both modelled by the same parameters, is validated by both linear and nonlinear control.
BibTeX
@misc{shi2020learning,
  author = {Jicheng Shi and Yingzhao Lian and Colin N. Jones},
  title = {{Learning Optimal Control with MPC Layer}},
  year = {2020},
  eprint = {2002.06883},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2002.06883},
}
Figure