SGPC: Safety-Guiding Policy Constraint for Stable Off-Policy Safe Reinforcement Learning
Authors: Yifan Liu, Nan Zhang, Yang Cong
Organizations: School of Automation Science and Engineering, South China University of Technology, Guangzhou, 510641, China · China Southern Power Dispatching & Control Center, China Southern Power Grid Company Limited, Guangzhou, 510641, China
Off-policy safe reinforcement learning (RL) faces a challenging trade-off between task optimality and constraint feasibility. In primal-dual methods, the coupled optimization of cumulative reward and constraint penalties through adaptive Lagrange multipliers may induce oscillatory policy updates near the safety boundary and amplify the effect of unreliable reward estimates outside the safe set. To address these issues, we formulate a new constrained optimization problem (COP) for safe RL by introducing a Safety-Guiding Policy (SGP) and a corresponding Safety-Guiding Policy Constraint (SGPC). The proposed COP augments the standard COP in safe RL with a conditional safety-guidance constraint. During actor updates, the current actor is evaluated using the learned cost critic. If it is predicted to be outside the safe set, SGP provides a nearby lower-cost training reference, and SGPC guides actor optimization toward this reference. Once the policy enters the safe set, the added constraint becomes inactive, and the formulation reduces to the original COP. This formulation leads to a plug-in actor-training constraint that can be integrated into off-policy safe RL algorithms. By applying primal-dual optimization to the auxiliary COP, we finally derive an SGPC-based off-policy safe RL algorithm and implement it in two representative off-policy algorithms, yielding SAC-SGPC and TD3-SGPC. Experiments on multiple Safety-Gymnasium benchmarks demonstrate that SGPC achieves a better optimality-safety trade-off by substantially reducing constraint violations and cost oscillations while maintaining competitive or better task returns.
Figures & tables
Fig. 1: Overview of the SGPC-based algorithm, which incorporates SGPC as a plug-in constraint into the actor update of off-policy actor-critic safe RL.
Fig. 2: Reward and cost learning curves of comparative experiments under the default cost limit of 25. For readability, each task shows the two SGPC-based methods and the three best-performing baselines for that task.
Environment
Full Environment Name
SafeAnt
SafetyAntVelocity-v1
SafeHalfCheetah
SafetyHalfCheetahVelocity-v1
SafeHopper
SafetyHopperVelocity-v1
SafeWalker2d
SafetyWalker2dVelocity-v1
SafeHumanoid
SafetyHumanoidVelocity-v1
SafePointGoal1
SafetyPointGoal1-v0
TABLE I: Summary of environments used in our experiments
Algorithms
Metrics
Environment
SafeAnt
SafeHalfCheetah
SafeHopper
SafeWalker2d
SafeHumanoid
SafePointGoal1
SafeCarGoal1
SafePointButton1
SAC-Lag
Reward
1331.2 ± 1788.7
3321.7 ± 3430.0
931.7 ± 156.2
920.5 ± 535.6
5974.3 ± 362.4
20.6 ± 10.3
34.8 ± 4.4
32.6 ± 4.8
Cost
22.1 ± 32.9
195.3 ± 389.3
17.1 ± 34.1
27.1 ± 36.9
0.5 ± 4.3
21.3 ± 24.4
25.9 ± 25.5
26.9 ± 46.7
TD3-Lag
Reward
2539.9 ± 362.9
2186.4 ± 170.1
1095.7 ± 344.1
2679.9 ± 691.3
6085.4 ± 497.2
23.5 ± 3.0
29.9 ± 2.8
34.7 ± 5.0
Cost
20.0 ± 16.3
9.9 ± 5.4
72.9 ± 111.1
14.1 ± 19.6
28.6 ± 40.1
24.1 ± 22.0
27.3 ± 25.3
16.5 ± 29.4
SAC-PID
Reward
1617.6 ± 1557.8
2520.7 ± 390.1
1128.1 ± 230.3
1608.2 ± 981.3
5697.1 ± 965.7
26.2 ± 1.7
34.8 ± 4.0
33.2 ± 4.6
TABLE II: Evaluation results on Safety-Gymnasium tasks under the default cost limit of 25
Cost Limit
Algorithms
Metrics
Environment
SafeAnt
SafeHopper
SafeWalker2d
SafePointGoal1
5
SAC-Lag
Reward
1953.12 ± 1148.35
755.5 ± 510.67
577.97 ± 474.69
17.6 ± 10.0
Cost
0.45 ± 1.96
32.69 ± 65.06
10.39 ± 26.8
5.1 ± 10.4
TD3-Lag
Reward
1266.58 ± 1233.02
966.32 ± 77.84
2270.41 ± 643.58
22.7 ± 2.7
Cost
10.9 ± 21.69
390.2 ± 117.55
7.522 ± 14.92
4.1 ± 7.6
SAC-PID
Reward
1263.03 ± 1431.68
824.15 ± 216.44
838.99 ± 660.7
11.4 ± 13.7
TABLE III: Evaluation results on selected representative tasks under tighter cost limits of 5 and 15
Fig. 3: Reward and cost learning curves on SafeWalker2d under tighter cost limits.
Fig. 4: Reward and cost learning curves on SafePointGoal1 under tighter cost limits.
Fig. 5: Reward and cost learning curves comparing SGPC-based off-policy methods with representative on-policy safe RL methods
Algorithms
Metrics
Environment
SafeAnt
SafeHalfCheetah
SafeHopper
SafeWalker2d
SafeHumanoid
SafePointGoal1
SafeCarGoal1
SafePointButton1
CPO
Reward
2368.8 ± 586.7
1802.2 ± 202.8
1105.0 ± 428.5
1520.3 ± 665.8
5393.4 ± 1282.5
7.1 ± 5.8
12.1 ± 6.1
12.0 ± 5.2
Cost
35.2 ± 44.0
30.4 ± 25.7
61.1 ± 87.1
44.9 ± 87.9
1.74 ± 6.28
19.4 ± 41.4
29.6 ± 108.5
31.1 ± 36.4
CUP
Reward
2164.0 ± 406.8
1727.4 ± 428.8
1385.9 ± 233.6
2135.7 ± 597.1
3965.8 ± 1905.2
9.9 ± 5.2
17.2 ± 5.8
6.9 ± 4.8
Cost
51.5 ± 70.1
17.8 ± 19.1
10.9 ± 14.7
119.4 ± 119.2
13.79 ± 28.1
18.5 ± 24.6
11.9 ± 23.9
24.4 ± 59.3
SAC-SGPC
Reward
2886.0 ± 96.4
2658.0 ± 161.6
1120.8 ± 84.9
2831.3 ± 111.1
6005.9 ± 268.6
25.6 ± 1.4
31.8 ± 4.5
29.4 ± 9.2
TABLE IV: Comparison with representative on-policy safe RL methods under the default cost limit of 25.
Variants
Metrics
SAC-SGPC
TD3-SGPC
SafeAnt
SafeWalker2d
SafePointGoal1
SafeAnt
SafeWalker2d
SafePointGoal1
w/o Jπsgpc(ϕ)
Reward
1331.2 ± 1788.7
917.4 ± 509.1
20.5 ± 10.3
2543.5 ± 357.1
2654.8 ± 729.7
23.5 ± 3.0
Cost
22.1 ± 32.9
26.4 ± 37.3
22.4 ± 26.4
20.3 ± 16.4
12.4 ± 16.3
24.1 ± 22.0
w/o Jπorigin(ϕ)
Reward
2261.6 ± 1057.2
2869.1 ± 192.2
20.2 ± 10.2
1814.5 ± 1104.9
2749.2 ± 313.8
23.2 ± 1.7
Cost
1.5 ± 2.0
51.3 ± 101.8
13.0 ± 18.8
50.6 ± 89.9
17.2 ± 14.1
11.7 ± 13.9
w/o ∥Δa∥1
Reward
1580.0 ± 1213.2
860.7 ± 377.9
20.5 ± 10.3
902.7 ± 1807.1
2814.7 ± 650.6
23.3 ± 2.3
TABLE V: Ablation results of SGPC components under the default cost limit of 25
σsgp
Metrics
SAC-SGPC
TD3-SGPC
SafeHopper
SafeWalker2d
SafePointGoal1
SafeHopper
SafeWalker2d
SafePointGoal1
0.02
Reward
980.4 ± 300.8
2861.0 ± 181.0
19.0 ± 9.9
838.9 ± 331.8
2754.8 ± 279.3
23.3 ± 2.9
Cost
4.1 ± 20.3
5.6 ± 10.9
6.5 ± 13.6
9.9 ± 14.5
13.8 ± 9.7
13.0 ± 17.1
0.1
Reward
1120.8 ± 84.9
2831.3 ± 111.1
25.6 ± 1.4
826.9 ± 521.1
2850.7 ± 175.4
23.3 ± 2.4
Cost
4.0 ± 6.9
1.5 ± 3.1
12.6 ± 16.7
0.7 ± 1.3
11.7 ± 7.2
9.6 ± 12.6
0.5
Reward
1029.9 ± 15.3
2873.0 ± 177.1
24.0 ± 4.0
882.7 ± 384.8
2772.6 ± 245.5
23.3 ± 2.1
TABLE VI: Hyperparameter analysis of the SGP sampling range σsgp
n
Metrics
SAC-SGPC
TD3-SGPC
SafeHopper
SafeWalker2d
SafePointGoal1
SafeHopper
SafeWalker2d
SafePointGoal1
16
Reward
1120.8 ± 84.9
2831.3 ± 111.1
19.8 ± 10.1
826.9 ± 521.1
2850.7 ± 175.4
23.4 ± 1.8
Cost
4.0 ± 6.9
1.5 ± 3.1
8.0 ± 13.8
0.7 ± 1.3
11.7 ± 7.2
10.2 ± 14.0
64
Reward
1078.7 ± 152.4
2839.2 ± 160.5
25.6 ± 1.4
1119.0 ± 495.7
2794.4 ± 106.3
23.3 ± 2.4
Cost
41.9 ± 72.0
0.1 ± 0.3
12.6 ± 16.7
10.9 ± 20.8
21.8 ± 15.4
9.6 ± 12.6
256
Reward
1064.7 ± 107.3
2819.9 ± 152.4
20.0 ± 10.0
1126.5 ± 129.6
2770.7 ± 207.0
22.8 ± 2.5
TABLE VII: Hyperparameter analysis of the SGP sample number n
Appendix figures & tables2 assets
Supplementary material from the paper’s appendix.
Appendix
Environment
Velocity threshold vˉe
SafeAnt
2.6222
SafeHalfCheetah
3.2096
SafeHopper
0.7402
SafeWalker2d
2.3415
SafeHumanoid
1.4149
Appendix
TABLE B.1: Velocity thresholds for locomotion environments
Hyperparameter
Velocity Tasks
Navigation Tasks
Replay buffer size
106
106
Batch size
256
256
Discount factor γ
0.99
0.99
Soft update coefficient τ
0.005
0.005
Actor learning rate
3×10−4
5×10−6
Critic learning rate
3×10−4
10−3
Appendix
TABLE B.2: Default hyperparameters of SGPC-based methods