Safe Reinforcement Learning using Action Projection: Safeguard the Policy or the Environment?

Hannah Markgraf, Shambhuraj Sawant, Hanna Krasowski, Lukas Schäfer, Sebastien Gros, Matthias Althoff

TL;DR

This paper provides a theoretical and empirical comparison of two main approaches for making Reinforcement Learning (RL) safe using action projection: Safe Environment RL (SE-RL) and Safe Policy RL (SP-RL). They reveal that action aliasing, a common issue in projection, is more detrimental to SP-RL, but propose a novel penalty critic for SP-RL that can match or exceed SE-RL performance.

What Problem Does This Paper Address?

Reinforcement Learning (RL) agents often need to operate in safety-critical environments, where violating safety constraints can have severe consequences. A common technique to ensure safety is "projection-based safety filters," which take potentially unsafe actions proposed by an RL policy and "project" them onto the nearest safe action. However, there are two primary ways to integrate these filters into the RL training loop:

  1. Safe Environment RL (SE-RL): The safety filter is treated as part of the environment. The RL agent learns an "unsafe" policy, but the environment itself ensures that only safe actions are executed. The agent's "critic" (which estimates the value of states and actions) must implicitly learn the effects of the safeguard.
  2. Safe Policy RL (SP-RL): The safety filter is integrated directly into the policy. The agent learns a "safe" policy, and the gradients from the safety filter are backpropagated through the policy to update its parameters.

While both approaches are practically relevant, there's been a lack of formal understanding of their differences, particularly concerning how they handle "action aliasing." Action aliasing occurs when multiple different unsafe actions are mapped to the same safe action by the projection filter. This can lead to a loss of information crucial for learning. This paper aims to bridge this gap by providing a theoretical framework and empirical validation to understand these differences and their implications.

Methods

The authors develop a unified theoretical framework for both SE-RL and SP-RL, formalizing them within the context of actor-critic RL algorithms. They analyze the policy gradient estimates for both deterministic and stochastic policies. A key focus is on understanding the impact of action aliasing:

  • SE-RL: Action aliasing leads to a "flat-lining critic," where the critic cannot distinguish between different unsafe actions that map to the same safe action. This means gradients related to the direction of unsafe actions are lost.
  • SP-RL: Action aliasing results in a rank-deficient Jacobian of the safeguard during backpropagation, leading to the "zero-gradient problem." This directly affects the policy gradient computation.

To address the issues caused by action aliasing, the paper compares existing mitigation strategies and proposes a novel one for SP-RL:

  • SE-RL Mitigation: Typically involves adding a penalty to the reward function when the safeguard intervenes.
  • SP-RL Mitigation (Existing): Often uses additional policy loss terms that penalize the distance between unsafe and safe actions.
  • SP-RL Mitigation (Proposed): A penalty critic is introduced. This is a separate critic network trained to estimate the cumulative penalty incurred by unsafe actions. This approach aims to re-establish theoretical equivalence with improved SE-RL by providing a more holistic view of long-term safety costs.

The authors also use the implicit function theorem to derive the sensitivity of the safeguard with respect to the unsafe action, which is crucial for SP-RL's backpropagation.

Datasets

The paper does not introduce new datasets. Instead, it uses standard benchmarks for evaluation:

  • Classic Control Tasks: Pendulum stabilization and Quadrotor stabilization.
  • Navigation Task: A "seeker" robot navigating to a goal while avoiding obstacles.
  • Energy Management System (EMS) Task: Optimizing battery and heat pump usage in a building to balance comfort and cost.

These tasks are chosen to represent different scenarios, including those where safety and performance are aligned and those where they are not.

Key Insights and Ideas

  • Theoretical Equivalence (Stochastic Policies): For RL algorithms using stochastic policies and Generalized Advantage Estimation (GAE), SE-RL and SP-RL are theoretically equivalent. This means they will converge to the same policies and value functions if initialized identically.
  • Practical Divergence (Deterministic Policies): For deterministic policies, SE-RL and SP-RL can converge to different local optima. This is due to how they handle action aliasing: SE-RL's critic implicitly learns the safeguard's effect, while SP-RL's direct gradient backpropagation is more sensitive to the safeguard's structure.
  • Action Aliasing is More Detrimental to SP-RL: The "zero-gradient problem" in SP-RL, caused by action aliasing, is a fundamental issue that directly impacts gradient computation. In SE-RL, the "flat-lining critic" is an approximation issue that can be alleviated by imperfect value function approximations.
  • Novel Penalty Critic for SP-RL: The proposed penalty critic for SP-RL offers a principled way to incorporate long-term safety costs, similar to SE-RL's reward penalties. This approach can lead to better convergence and performance, especially when safety and task objectives align.
  • Trade-off between Performance and Computation: Improved SP-RL variants can match or exceed SE-RL performance, but at the cost of significantly higher computation time (3-12x) due to the need for sensitivity computations.

Key Results

  • Vanilla SE-RL vs. SP-RL: For deterministic policies (using TD3), vanilla SE-RL generally outperformed SP-RL, especially in more complex environments, with SP-RL sometimes exhibiting convergence issues. For stochastic policies (using A2C), they performed equivalently.
  • Improved Approaches:
    • For TD3, both per-sample loss (PSL) and the proposed penalty critic (PenC) for SP-RL improved performance over vanilla SP-RL and often matched or exceeded SE-RL with penalties. The penalty critic was particularly effective when safety and task objectives aligned.
  • For A2C, the penalty critic for SP-RL and penalties for SE-RL showed similar improvements, especially in pendulum and quadrotor tasks.
  • Computational Cost: SP-RL variants are significantly slower than SE-RL due to the need for computing safeguard sensitivities. This gap is larger for more complex environments.
  • Action Aliasing Impact: Empirical results confirmed that action aliasing is more problematic for SP-RL, leading to convergence issues in deterministic settings.

Limitations and Future Work

  • Computational Cost of SP-RL: The primary limitation of SP-RL, especially improved variants, is its significantly higher computational cost compared to SE-RL. The authors suggest that future advances in differentiable optimization layers and parallelization of dynamics could mitigate this.
  • Alignment of Safety and Performance: The effectiveness of improvement strategies (penalty critic vs. per-sample loss) depends on how well safety and task performance objectives align. The paper notes that in scenarios where optimal actions are inherently unsafe (seeker task), both methods converge to boundary actions, and the per-sample loss can be more efficient.
  • Future Work: The authors suggest that their theoretical framework can be extended to other RL algorithms beyond actor-critic methods and that further research into optimizing differentiable projection layers could reduce the computational overhead of SP-RL. They also highlight the potential for decoupling complex dynamics into subproblems for parallel processing.

Summary updated

BibTeX
@article{markgraf2025safe,
  author = {Hannah Markgraf and Shambhuraj Sawant and Hanna Krasowski and Lukas Schäfer and Sebastien Gros and Matthias Althoff},
  title = {{Safe Reinforcement Learning using Action Projection: Safeguard the Policy or the Environment?}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=DDrGSEYxGU},
}
Figure