Effects of Safety State Augmentation on Safe Exploration
Abstract
Safe exploration is a challenging and important problem in model-free reinforcement learning (RL).
Often the safety cost is sparse and unknown, which unavoidably leads to constraint violations — a phenomenon ideally to be avoided in safetycritical applications.
We tackle this problem by augmenting the state-space with a safety state, which is nonnegative if and only if the constraint is satisfied.
The value of this state also serves as a distance toward constraint violation, while its initial value indicates the available safety budget.
This idea allows us to derive policies for scheduling the safety budget during training.
We call our approach Simmer (Safe policy IMproveMEnt for RL) to reflect the careful nature of these schedules.
We apply this idea to two safe RL problems: RL with constraints imposed on an average cost, and RL with constraints imposed on a cost with probability one.
Our experiments suggest that “simmering” a safe algorithm can improve safety during training for both settings.
We further show that Simmer can stabilize training and improve the performance of safe RL with average constraints.
Introduction
Reinforcement learning (RL) is a framework for sequential decision-making that makes minimal prior assumptions about the environment where the agent has to act or make the decisions [45].
The policy for taking actions is learned through interactions with the environment over time.
RL has seen recent successes in playing video games with a computer [32], board games with a human [41] and is on a path toward real-life applications such as video compression [46] and plasma control [20].
There are still, however, some unsolved challenges for a successful deployment of RL such as efficient learning of constrained or safe Markov Decision Processes (MDPs) [4].
The constraints are typically modeled by a discounted sum of nonnegative costs that have to be smaller than some pre-defined value we call the safety budget .
Exploration is a crucial component of RL and is still an active area of research [25, 40, 34].
In the context of safe RL, while exploring, we do not want to incur the safety cost and constraint violations, making exploration a harder task.
We can distinguish two main research directions for minimizing constraint violation in safe RL: a model-based approach (which includes partially and fully known environments) and a model-free approach.
In the model-free case, which we focus on, the agent would almost certainly visit unsafe regions to learn the safe policy, and therefore it is next to impossible to avoid constraint violations completely.
The general goal, in this case, is to minimize the number of violations during training.
For example, [10] use a conservative safety critic and rejection sampling to choose a “safer” action, [48] design a curriculum learning approach, where the teacher resets the student violating safety constraints, and [21] learns to reset the policy if the safety constraint is violated [21].
In this work, we aim to improve model-free safe reinforcement learning by augmenting the state-space with one state encapsulating the safety information.
This safety state is initialized with the safety budget and the value of the safety state can serve as a measure of distance to the unsafe region.
This form of the safety state was proposed in [18] and introduced in RL in [43], where a safe RL algorithm with probability one constraints was derived.
In this paper, we take a closer look at the purposes of the safety state in a broader context.
First, we claim that safety state augmentation is often crucial for the averaged constrained problem as well and provide examples of such occurrences.
In some particular problems, the use of safety state augmentation may potentially be avoided, however, this can be said about any state in the environment.
Second, our main suggestion is that scheduling the safety budget at different training epochs can improve the algorithm’s performance.
Our claim extends equally over averaged and almost surely constrained reinforcement learning problems.
In particular, we achieve state-of-the-art performance in some environments in the safety gym benchmark.
Further, we claim that scheduling the initial safety budget can lead to reducing safety constraint violations during training for safe RL with probability one constraints.
We design two algorithms that automatically tune the safety budget, one is based on a classical control engineering PI controller, while the other uses Q learning to decide on the safety budget.
Related work.
Many of the current safe RL methods are extensions of the most successful RL algorithms: Trust region policy optimization (TRPO)
[38], proximal policy optimization (PPO) [39], soft actor-critic (SAC) [23] etc.
Safe versions of TRPO, PPO, and SAC with a Lagrangian approach were first presented in [37], which is still considered to be one of the major baselines.
A direct extension of TRPO by adding constraints to the trust region update was proposed in [2].
Model-based approaches were also considered cf.
[36, 16, 27, 30] and most of them took a Bayesian approach to model one-step transitions.
To our best knowledge, the most successful approaches for safe reinforcement learning to date are PID-Lagrangian [44] and LAMBDA [5].
The former views the
Lagrangian multiplier update as another control problem and employs a PID controller to solve it (cf.
Specifically, the authors link the multiplier update to integral control and add proportional and derivative controllers to achieve a superior behavior.
On the other hand, [5] is a model-based approach that uses Bayesian world models to enhance safety.
A recent work [29] formulated safe RL as inference resulting in a sample efficient off-policy approach.
Other formulations of safe RL were considered in the literature.
For example, [14, 16, 51] proposed to use conditional-value-at risk (CVaR) constraints, while [43, 12] proposed to enforce constraints with probability one.
Further, as we discussed above eliminating the number of constraint violations typically requires strong assumptions, e.g., finite state space [47], [50] [42], knowledge of a partial model [28] or initial safe policy [8].
These results are in the spirit of safe RL with control-theoretic notions [15, 9, 33, 13, 3, 19, 22], which make significant prior assumptions to guarantee safety.
Finally, the closest algorithm in the literature to our method is the curriculum learning approach to Safe RL from [48].
Due to space limitations we discuss this approach in detail in Appendix.
We finally mention that [31] proposed a two-player framework with the cooperating task agent and safety agents, [17] proposed a safety layer that would be applied after the action is computed using a classical policy, [24] defined a probabilistic shield for safety.
We also note [52, 26] that considered safe deployment of RL policies in real-life settings.
Simmer: Safe policy improvement for reinforcement learning 2.1 MDP with safety state augmentation
We consider a constrained reinforcement learning setting defined for a Markov Decision Process (MDP) M = ⟨S , A , P , r, γ r ⟩ with transition probability P : S ×
A × S → [0 , 1] acting on state S and A spaces, with the reward r : S ×
A × S → R and the discount factor γ r ∈ (0 , 1] .
The MDP is endowed with the following optimization problem
[Equation]
with the time horizon T > 0 , the safety discount factor γ l ∈ (0 , 1] , the safety cost l : S × A × S → [0 , + ∞ ) .
The statistic g ( · ) : R → R is a design choice (e.g., Mean, CVaR, chance constraints etc [14]).
In this paper, we consider two most relevant options, from our point of view: a) a constraint with probability one, i.e., g po ( z ) =
P ( z ≥ 0) − 1 , b) a constraint on average g av ( z ) =
E z .
Similarly to [43], we augment the safety state information into the state-space by introducing the state z t = γ − t ( d − (cid:80) t − 1 k =
γ kl l ( s k , a k , s k +1 )) , which has the following update z t +1 =
( z t − l ( s t , a t , s t +1 ))
/γ l , with z 0 = d .
Noting that the update is Markovian this state can be easily augmented into the MDP.
The variable z t has the interpretation of the remaining safety budget, and by definition enforcing the constraint on z T is equivalent to enforcing the constraint on the accumulated cost.
Now we can rewrite the safe RL problem as follows:
[Equation]
While [43] considered only the case g po ( z ) , we argue that the case of g av ( z ) deserves additional attention in the context of safety state augmentation.
For completeness, we review the main points of the approach [43] in Appendix.
Note that the policy now also depends on the safety state z and this feature deserves a more thorough discussion.
2.2 Do we need the safety state?
As a simple demonstration consider the cartoon in Figure 1.
A robot needs to reach the goal while crossing the hazard region, which is marked by the red circle, and the safety cost is acquired for every time unit spent in the region.
Both green and blue paths are safe, i.e., satisfy the constraint.
However, at the crossing of these paths robot needs to know which path it took to this state.
Switching from the green path to the blue one will lead to a constraint violation.
Standard safe RL algorithms will have trouble with such scenarios while adding the safety state solves the issue.
We confirm this observation in our experiments.
Let us now discuss how this logic can be mathematically formalized.
In the deterministic case, this problem is well studied in the optimal control literature in the context of problems with known dynamics and with terminal or end-point constraints [49].
Further, the authors [43] showed that the policy dependence on the remaining safety budget is crucial for safe reinforcement learning with probability one constraints.
The problem was also studied in the context of stochastic diffusions [35], where the authors derived the representation of the optimal value function.
In both cases, it was shown that the optimal policy depends on the whole state including the safety state z .
While in some cases one may not need to augment the safety state, in many situations it is critical.
2.3 Simmering Safe Reinforcement Learning
In this paper, we propose to use the initial safety budget d as another tuning dial for the algorithms.
Specifically, we will exploit the link between the safety budget d with the initial state of the safety state.
We argue that adjustment of d during training from some initial value d start to the target value d target can lead to improved exploration in terms of safety and performance.
Let us now present the mathematical formulation.
At every epoch k we pick a test safety budget d k , collect the data set D k , compute the returns E D k (cid:80) T − 1 t =
γ tr r ( s t , a t ) and the costs ˆ g D k ( z T ) , where the function ˆ g D k ( · ) is the empirical mean or the maximum for the averaged and the probability one constrained problems, respectively.
Using this information we aim at solving the following problem at every epoch (but we only apply a pre-determined number of gradient steps):
[Equation]
subject to
[Equation]
D
[Equation]
where s 0 ∈ S 0 and z
=
d k are the initial states of the augmented MDP.
Note that for off-policy algorithms the data set D k can potentially grow with epochs, while for on-policy algorithms the data set D k will be emptied on every epoch.
The key assumptions of our approach are as follows:
• There is a finite number of test safety budgets,
i
e., we assume that d k can take the values { d ref k } with d ref0 ≤ · · · ≤ d ref K − 1 with d start = d ref0 and d target =
d ref K − 1 ; • We assume that the values { d ref k } are such that the task can be solved; • At for every k we perform only one epoch of optimization solving Problem 3.
The intuition behind our formulation is based on our empirical observations, where lower safety budgets usually caused lower bursts in accumulated safety costs.
We hypothesize that the policy can quickly learn “extremely unsafe” actions thus providing low safety cost bursts for low safety budgets.
Therefore if we start with a very strict safety budget d start , then by gradually increasing the safety budget d from d start to d target , we can reduce the number of constraint violations during training.
We will show that the problem of safety during training can be formalized as a two-level decision-making problem, however, even a na¨ıve approach of scheduling d k can lead to improvement in performance and safety .
We see this formulation as the first step toward eliminating safety violations during training.
2.4 Application: Simmering for safety during training
Exploration can often lead to constraint violation during training due to the inherent stochasticity of exploration.
While there is a significant effort in research for safe exploration it typically requires significant prior assumptions on MDPs.
We propose to embrace the philosophy of classical reinforcement learning and proceed with minimal assumptions.
We propose to choose the test safety budget d k using another decision-making problem:
[Equation]
where z kT ( d target ) is the violation of the target constraint obtained as a result of solving one epoch of
Problem 3, the action set is [ − δd, δd ] and δd is pre-determined, clip ( x, y, z ) clips the value x to a lower bound y and an upper bound z , i.e., the function returns y if x ≤ y , z if z ≤ x and x otherwise.
We formalized our problem as reinforcement learning over a partially observable process with the non-stationary observations of the learning process.
This two-level RL problem allows us to use a broad spectrum of tools available in sequential decision-making differing our approach from the existing in the literature.
However, solving Problem 4 appears to be a daunting task, especially in the online setting as we intend.
Hence, we will employ heuristic solutions, which may prove more effective than the quest to find an optimal solution.
Intuitively, a gradual increase in d k by assigning scheduling increasing reference values (denoted by d ref k ) would less likely lead to constraint violation due to stricter exploration constraints.
However, fixing the schedule a priori limits the ability of the algorithm to react to constraint violations.
To alleviate this issue we propose two approaches:
PI Simmer (PI-controlled safety budget) and Q Simmer (Online Q-learning with non-stationary rewards).
In both algorithms the intuition is again is based on our empirical observations that lower safety budgets cause lower bursts in accumulated safety costs.
In particular, if the current accumulated costs are well below the safety budget d ref k , then we are very safe and the safety budget can be further increased.
If the accumulated costs are around the safety budget, then we could stay at the same level or increase the safety budget.
If the current accumulated costs are well above the safety budget d ref k , then the safety budget should be decreased.
PI Simmer.
The idea for the PI controller is quite intuitive it takes the error term e = d ref − c and uses it for action computation.
P stands for proportional control and links the error terms with actions by multiplying the error term by the gain K .
The proportional part delivers brute force control by having a large control magnitude for large errors, but it is not effective if the instantaneous error values become small.
Proportional control cannot achieve zero error e tracking.
This happens since zero error results in a zero proportional action and hence the control over the error is lost.
To deliver zero error, integral control is typically used, which sums up previous error terms and uses this sum to determine actions instead of the error.
The integral term can be seen as an “action acceleration” (or “momentum”) term which is large if the past errors are large.
This can potentially cause unwanted behaviors (such as oscillations) if the corresponding gain K i is too large.
Both gains K , and K i are usually chosen by tuning, but there are rules of thumb for tuning and choosing the gains, which we discuss in Appendix.
PI controller can solve many hard control problems, but there are some implementation and engineering tricks and improvements.
We introduce a simplified version in
Algorithm 1 and provide a full version of the algorithm and our ablation studies in Appendix.
Algorithm 1: PI SIMMER (basic version)
Inputs: { d ref k } N − 1 k =0 - safety budget schedule, hyper-parameters - K p , K i , δd .
Set d 0 = d ref0 ; for k = 0 , . . .
, N − 1 do
Perform one epoch of learning for the safe policy with d k and get the statistic ˆ g
( z T ( d k )) ;
Compute the error term
e k
=
d ref k − ˆ g ( z T ( d k )) ;
Compute action u raw k
=
K p e k
(cid:124)
(cid:123)(cid:122) (cid:125) P-Part + K i (cid:88) k
i = k − T
i e i (cid:124) (cid:123)(cid:122) (cid:125) I-Part ;
Set d k +1 =
clip ( u raw k , − δd, δd ) + d k ; end
Q Simmer.
Consider an MDP with the states { d ref0 , . . .
, d ref K − 1 } , which for simplicity of notation we denote { 0 , . . .
, K − 1 } , with the actions { a − 1 , a 0 , a +1 } , where the action a +1 moves the state s =
i to the state s =
i + 1 , a − 1 moves the state s =
i to the state s =
i − 1 and the action a 0 does not transfer the state.
Note that the action a +1 is defined for all i < K − 1 and the action a − 1 is defined for all i > 0 .
Our design for the rewards of this MDP is guided by the following intuition.
We are not safe
We are borderline safe
We are very safe
[Equation]
where o
= ˆ g ( z T ( d k )) is a safety violation statistic (over an epoch) of the safe RL algorithm, δ is a significance violation threshold.
We use a Q-learning update to learn the Q function:
[Equation]
where l r is the learning rate and get the action with ε -greedy exploration strategy:
[Equation]
We summarize the approach as Algorithm 2.
Experiments 3.1 Baselines, environments and code base
Environments: We use the safe pendulum environment defined in [16], and we also use the custom-made safety gym environment with deterministic constraints, which we call static point goal [51].
In this environment with 46 states and 2 actions, a large hazard circle is placed before the goal and forces the agent to go around it to reach the goal similarly to our cartoon in Figure 1.
Input ref k
K − 1 k = chosen state space; hyper parameters
N ε ; end
[Figure]
We provide additional details in Figure 2 and Appendix.
The rest of our tests are performed on the safety gym benchmarks [37].
Code base: Our code is based on two repositories: safety starter agents [37], and PID Lagrangian [44].
The code for PI Simmer and Q Simmer is available at https://github.com/huawei-noah/HEBO/ tree/master/SIMMER .
We use default parameters for both code bases unless stated otherwise.
Computational resources: We performed all computations on a PC equipped with 512GB of RAM, two Intel Xeon E5 CPUs, and four 16GB NVIDIA Tesla V100 GPUs.
Baselines ( • ) and our algorithms ( ■ ):
• CPO, Lagrangian PPO (L-PPO), and TRPO (L-TRPO); Standard baselines from [37]; • PID-Lagrangian.
An algorithm stabilizing L-PPO learning [44]; • LAMBDA.
A model-based method showing great performance on Safety Gym [5]; • PO-PPO PPO-based algorithm with probability one constraints from [43]; ■ PI-Simmer - Scheduling safety budget using PI controller for PO-PPO; ■ Q-Simmer - Scheduling safety budget using Q learning for PO-PPO; ■ L-PPO (PID-L) w SA - L-PPO (PID-L) solving Problem 2 with safety state augmentation; ■ Simmer L-PPO (PID-L) - L-PPO (PID-L) w SA and safety budget scheduling.
3.2 Improving Safety During Training for Pendulum Swing-Up
Improving safety during training is more suited for almost surely safe RL and we will take PO PPO as our baseline.
In this setting, we can aim to reduce the number of individual trajectories that violate the constraints, and thus we can avoid estimating the statistic g .
For PI Simmer we chose the following hyper-parameters K = 0 .
01 , K i = 0 .
005 , K
aw = 0 .
01 and τ = 0 .
The parameter K aw resets the integral term avoiding the accumulation of error - the higher the value the more aggressive is reset.
The parameter τ is the Polyak update for the error term, which pre-processes the error term for the PI controller.
We discuss these parameters in detail in Appendix.
We also note that except for an initial burst of violations both our approaches manage to keep the number of violations quite low.
Overall we found that low values for K and K i are beneficial to avoid overreaction to constraint violations.
In this case, keeping the value of K aw low is advisable as the action saturation does not occur too often.
Finally, keeping τ close to one will force the controller to react to most of the constraint violations.
For Q
Simmer we chose δ = 1 , τ = 0 .
995 , l r = 0 .
05 , and ε = 0 .
It appears that a fast learning rate here can allow for learning, sufficiently fast forgetting of past rewards, but also to avoid catastrophic forgetting.
As we consider a finite state MDP we can avoid using sophisticated techniques for online learning and use the simplest one — tuning learning rate.
We chose δ and τ to avoid frequent state transitions.
[Figure]
We compare our algorithm to PO PPO in terms of the number of trajectories with constraint violations, and returns, and compare the progression of the schedule d test k .
Naturally, some individual trajectories still violate the constraint, but the number can be significantly reduced using Simmer RL as Figuresuggests.
While PI Simmer outperforms Q Simmer in these runs, it is worth mentioning that PI
Simmer uses more prior information than Q Simmer.
Indeed, while composing a schedule is not hard, we still have to identify the switch points, which are learned by Q Simmer.
We perform ablation studies on the parameters and discuss their choice in more detail in Appendix.
3.3 Guiding Exploration by Scheduling Safety Constraints
[Figure]
We now turn our attention to safe RL with constraints imposed on average costs.
We test the performance of Simmer L-PPO and L-PPO w SA on the swing-up pendulum environment and present training results in Figure 4.
Here we use safety starter agents as a base learner for all algorithms.
The major observations are that L-PPO w SA delivers almost no constraint violations with respect to the mean cost estimate, and therefore using Q Simmer and PI Simmer is not necessary.
In the meantime, L-PPO has even trouble converging.
Note that we have used the same hyper-parameters for all algorithms , which are default parameters in safety starter agents and the learning rate 0 .
While the behavior of the L-PPO algorithm can certainly be improved with tuning, we note that simply augmenting the safety state leads to improved performance as well as stability of the algorithm.
Further, we observe that Simmer L-PPO leads to a fewer number of violations, however, the rate of violations for the safety budget of 35 is fairly similar to L-PPO w SA.
Interestingly, a similar picture occurs with more advanced baselines such as PID Lagrangian [44] and more complicated environments.
Here, we used the static point goal environment designed in [51], where a large static hazard region is placed in front of the goal, which is similar to our motivational example in Figure 1.
The results for PID-L and PID-L with state augmentation are depicted in Figures 5a and 5b, respectively, suggest that the presence of the safety state stabilizes training and leads
[Figure]
to a more consistent constraint satisfaction for different safety budgets d .
Note that hyper-parameters for all the runs are the same for both algorithms.
We further apply the na ¨ ıve simmer approach to both baselines with results depicted in Figure 5c.
In both cases, the safety budget takes values of 1 , 5 , 10 , 15 , and 20 , and increased after equal time intervals.
Note that in both cases now training curves are quite stable, although state augmentation delivers an extra boost.
In all our experiments we used the same hyper-parameters for all versions of PID-L, i.e., K = 0 .
1 , K i = 0 .
01 , γ l = 0 . 99 .
Overall, our experiments suggest that safety during training with constraints imposed on average costs becomes a much easier problem with safety state augmentation.
Indeed, even intuitively every outlier trajectory with a large constraint violation should bias the average cost and should instruct the algorithm not to follow this path.
We note that in both cases above we have sparse costs, i.e., the agent encounters unsafe regions and incurs costs while navigating toward the goal.
While an algorithm without the safety state will receive information on constraint violation after an episode, the safety state would constantly inform the algorithm of the distance toward a violation.
This is one of the reasons why safety state augmentation can learn the task better.
Note that simmering additionally offers fewer constraint violations while training.
These results suggest that simmering safe RL together with state augmentation delivers overall safer solutions with stable training curves.
3.4 Tests on safety gym benchmarks
We finally test our approach on more challenging environments from the safety gym benchmark:
PointPush1, PointGoal1, PointButton1 in Figures 6a, 6b, and 6c, respectively, and CarPush1,
CarGoal1 and CarButton1 in Figures 7a, 7b, and 7c, respectively.
The hyper-parameters and the tuning specifics can be found in Appendix.
Again we use a na¨ıve schedule increasing the safety budget from 10 to 25 in 5 unit increments.
We observe that Simmer PID-L and PID-L outperform other baselines significantly in terms of the return while delivering safe policies.
Simmer PID-L does perform very similarly to PID-L in terms of returns but generally outperforms PID-L in terms of safety costs and cost rates.
We note that our results for PointGoal1 are consistent with the results from [44].
Conclusion
We augment the safety information into the state space and show how we can effectively use it to improve safe exploration.
The safety state is nonnegative if and only if the constraint is satisfied and therefore it can serve as a distance toward constraint violations.
We argue that the optimal policy must depend on this information to achieve safe performance.
We validate this argument using
[Figure]
L-PPO L-TRPO
CPO Lambda
Simmer PID-L
Safety budget
PID
[Figure]
L
[Figure]
L-PPO L-TRPO
CPO Lambda
Simmer PID-L
Safety budget
PID
[Figure]
L
[Figure]
L
[Figure]
L
[Figure]
Lambda
Simmer PID
[Figure]
Safety
[Figure]
intuitive examples, references to theoretical results, and experiments.
We do not doubt that safety state augmentation is needed for effective safe RL.
Safety state augmentation and simmering show superior performance on pendulum swing-up and static point goal tasks for average constrained problems.
We further tuned PID Lagrangian to show very strong performance on safety gym benchmarks, which has not been previously reported.
Simmer PID Lagrangian shows competitive performance in terms of returns to PID Lagrangian and outperforms all baselines (including PID Lagrangian) in terms of the cost rate and the costs.
Further, using state augmentation for the average constrained problems appears to be quite beneficial as well.
Scheduling the safety budget can stabilize safe algorithms without state augmentation, but using both state augmentation and simmering improves performance and safety.
We achieve this performance and safety boost at the expense of sample efficiency since we effectively learn a series of safe policies.
Simmering RL algorithms with probability one constraints can significantly reduce safety violations during training.
We illustrate this feature by developing two algorithms for safe learning.
The first one is based on a PI controller and allows for the adjustment of a pre-defined learning schedule depending on the estimated training cost.
The second one is based on online Q learning and learns to adjust the safety budget automatically.
Both approaches have some advantages and limitations.
PI simmering is more effective if there is a reasonable safety budget schedule, while Q simmering requires less prior knowledge to learn.
We have tested PI-Simmer and Q-Simmer on a rather simple in terms of the state and action spaces environments.
We foresee that in a more complex setting the main problem would be learning the agent’s behavior, but our algorithmic development would remain valid.
Nevertheless, it would be interesting to extend this approach to a more complex setting.
Our algorithmic development is focused on probability one constraints for two reasons.
First, since probability one constraints have to be imposed on all trajectories the empirical estimate of violations
[Figure]
is simpler than in the average constrained case (i
[Figure]
e., maximum vs empirical average).
Second, it appears that in the average constrained case with “simple” environments (such as pendulum swing-up and static point goal), we can track the constraint quite efficiently after the initial (and unavoidable) burst in constraint violations.
Our experiments suggest that PI Simmer and Q Simmer can be redundant for the average constrained RL.
Augmenting the safety state and scheduling the safety budget does not solve all the problems in safe exploration.
First, an initial burst of constraint violations is an inevitable reality of using our model-free approach.
It appears that lowering the initial safety budget lowers the initial burst of constraint violations, but does not completely solve the problem.
We do not see how to address this limitation without making further assumptions about the environment.
Second, it is noticeable that the performance on the PointPush1 environment is quite noisy for both PID-L and Simmer PID-L.
This is because some seeds achieve very good performance (return of 15) and some seeds do not (return of 5), while the learning curves appear to be stable.
This suggests that the learning procedure finds local maxima.
In our point of view, this calls for a more sophisticated algorithm for exploration maximizing return, which may help achieve stable performance in this environment.
Beyond these limitations, one can also list safety violations caused by variance and disturbances, lack of provable safety guarantees, etc.
Studying these limitations is outside of the scope of this paper.
Acknowledgement
This work was performed while the first two authors were with Huawei R&D UK.
The authors thank Dr. Zimmer from Huawei R&D UK for helpful discussions and suggestions, as well as, the anonymous referees whose suggestions and comments significantly improved the paper.
Checklist
For all authors... (a) Do the main claims made in the abstract and introduction accurately reflect the paper’s contributions and scope?
[Yes] (b) Did you describe the limitations of your work?
[Yes] (c) Did you discuss any potential negative societal impacts of your work?
[N/A] (d) Have you read the ethics review guidelines and ensured that your paper conforms to them?
[Yes] 2.
If you are including theoretical results... (a) Did you state the full set of assumptions of all theoretical results?
[N/A] (b) Did you include complete proofs of all theoretical results?
[N/A] 3.
If you ran experiments... (a) Did you include the code, data, and instructions needed to reproduce the main experimental results (either in the supplemental material or as a URL)?
[Yes] (b) Did you specify all the training details (e.g., data splits, hyperparameters, how they were chosen)?
[Yes] (c) Did you report error bars (e.g., with respect to the random seed after running experiments multiple times)?
[Yes] We reported the error bars over all the runs across different seeds (d) Did you include the total amount of compute and the type of resources used (e.g., type of GPUs, internal cluster, or cloud provider)?
[Yes] We use a PC equipped with 512GB of RAM, two Intel Xeon E5 CPUs, and four 16GB
If you are using existing assets (e.g., code, data, models) or curating/releasing new assets... (a) If your work uses existing assets, did you cite the creators?
[Yes] We use the code from safety starter agents, safety gym by open AI [37], PID Lagrangian method [44].
(b) Did you mention the license of the assets?
[No] All the libraries are under MIT Licence.
(c) Did you include any new assets either in the supplemental material or as a URL?
[Yes] We published the code at https://github.com/huawei-noah/HEBO/tree/ master/SIMMER (d) Did you discuss whether and how consent was obtained from people whose data you’re using/curating?
[N/A] (e) Did you discuss whether the data you are using/curating contains personally identifiable information or offensive content?
[N/A] 5.
If you used crowdsourcing or conducted research with human subjects... (a) Did you include the full text of instructions given to participants and screenshots, if applicable?
[N/A] (b) Did you describe any potential participant risks, with links to Institutional Review Board (IRB) approvals, if applicable?
[N/A] (c) Did you include the estimated hourly wage paid to participants and the total amount spent on participant compensation?
[N/A]
Appendices
A1 Related work a
A1.1 Safe Reinforcement Learning Using Curriculum Induction
a
A1.2 RL with probability one constraints
a
A2 Additional algorithm details
a
A2.1 PI-Simmer
a
A2.2 Q Simmer
a
A
Implementation details
a
A4 Further Experiments
a
A
Safety Gym
a
A
Ablation for PI Simmer
a
Ablation for Q Simmer
a
A5 Illustrations a
A Related work A1.1 Safe Reinforcement Learning Using Curriculum Induction
Here we review the work from [48].
Consider the Safe RL problem M = ⟨S , A , P , r, D⟩ with the following objective:
[Equation]
where ρ π is the distribution of trajectories induced by π , I is the indicator function and D is the unsafe set.
Note that this safe RL problem is less general than the standard formulation of safe RL.
The authors introduce a teacher-student hierarchy.
The student tries to learn a safe policy, while the teacher is guiding the student through interventions I .
The interventions I are represented by pairs ⟨D
i , T i ⟩ that modify the safe RL problem into a student’s problem M i = ⟨S , A , P i , r i , D , D i ⟩ , where we make the following modifications to the safe RL problem.
The state transitions are modified as P i ( s ′ | s , a ) =
P ( s ′ | s , a ) for all s ̸∈ D
i and P i ( s ′ | s , a ) =
T i ( s ′ | s ) for all s ∈ D i .
This means that the teacher changes the probability transition for the student if they enter the set D i .
The reward is modified as well: r i ( s , a , s ′ )
=
r ( s , a , s ′ )
if s ̸∈ D i and r i ( s , a , s ′ )
=
if s ∈ D i .
Therefore, the student does not get any reward in the unsafe set.
The student incorporates the interventions into their objective as follows:
[Equation]
where κ i and τ i are intervention-specific tolerances set by the teacher.
To learn the teacher’s policy the following constraints are followed: a
• The unsafe set is contained in the intervention set
D ⊆ D i •
If κ i + τ i ≤ κ , then the set of feasible policies of the student is a subset of the set of feasible policies of the safe RL problem
Π M i ∈
Π M .
The teacher learns when to intervene and to switch between different interventions.
The teacher is modeled by a POMDP ⟨S T , A T , P T , R T , O T ⟩ , where the state-space is the set of all student policies
S T =
Π M (not only feasible ones), the action space is the space of all interventions A T
=
I , i.e., the teacher chooses the index i for the student problem, the state transitions P T : Π M ×I × Π M → [0 , 1] is governed by the student’s algorithms, the observation space O T =
Φ is the space of evaluation statistics of student policies π .
Finally the reward function is defined through the policy improvement
R T ( n ) =
ˆ V ( π n,i ) − ˆ V ( π n − 1 ,i ) , where the index i denotes the student.
The total reward for an episode is ˆ V ( π N s ,i ) =
N s (cid:80) n =1 R T ( n
Now the policy is transferred from the trial
n −
to the next n .
Note also the student index i can be understood as an episode of learning teacher’s policy in this case.
The major difference of our work is its online nature, while [48] pre-train teacher’s policies deciding the curriculum, we do not pre-train our safety budget schedules d k explicitly, but use rules-of-thumb to determine the parameters of our online learning procedures.
Our approach is preferable when a new task needs to be learned with minimal prior information about it, while the method from [48] is preferable when the policy of choosing the constraints can be transferred from another task.
We also note that we do not reset our environment, but let it train further if the constraints are violated.
Hence our approach can further be improved by adding reset policies similarly to [48] and [21].
A1.2 RL with probability one constraints
We have introduced the safety state to the environment as follows:
[Equation]
This means we have
[Equation]
) and
[Equation]
Now we can sum up the left and the right-hand sides and obtain:
[Equation]
This means that the constraint can now be rewritten as g ( z T ) ≥ 0 resulting in the following optimization problem:
[Equation]
If we consider the problem with probability one constraints then as a constraint we get z T ≥
almost surely (or equivalently with probability one).
It was noted that z T ≥ 0 almost surely is equivalent to z t ≥ 0 for all t ≥ 0 .
Now the reward is reshaped to get: a
(cid:98) r ( s t , s z , a t , s t +1 , z t +1 ) = (cid:26) r
( s t , a t , s t +1 )
if z t ≥ 0 , − ∆ if z t < 0 .
(A2)
This problem can be solved using off-the-shelf RL algorithms for any finite ∆ .
Finally, it was noted in [43] that with ∆ → + ∞ , the problem converges to safe RL with probability one constraints.
The main difference to [43] is that we investigate the effect of the safety state on safety during training for both probability one constrained RL and average constrained RL.
A Additional algorithm details A2.1 PI-Simmer
[Figure]
First, we discuss our design for the PI controller and discuss the necessary parts for it.
Our main source for this discussion are the control engineering textbooks [7, 6].
The idea for the PI controller is quite intuitive: it takes the error term d test − c and uses it for action computation.
P stands for the proportional control and multiplies the error term by the gain K proportionally linking the error terms with actions.
The proportional part delivers brute force control by having a large control magnitude for large errors, but it is not effective if the instantaneous error values become small.
Proportional control cannot achieve zero error tracking, which is achieved by integral control and summing previous error terms.
If the action values are clipped, however, integral control can lead to the unwanted phenomenon called wind-up and catastrophic effects [6].
This is specifically the case when the errors become large leading to large values of the integral, which in turn leads to saturated actions (actions take the clipped values) for a long time.
There are several ways of dealing with wind-up, e.g., resetting the integral, and limiting the integration time, but we will take the feedback control approach where the previous saturation errors are fed back and used to determine the current action [6, 1].
Finally, we use a low pass filter for the error to avoid reacting to high-frequency fluctuations and acting only on the trends.
The reader familiar with optimization algorithms may recognize the loss pass filter as the Polyak update.
a
Inputs: { d ref k } N − 1 k =0 - safety budget schedule, hyper-parameters - τ , K p , K i , K aw , δd .
Set d 0 = d ref0 ; for k = 0 , . . .
, N − 1 do
Perform one epoch of learning for the safe policy with d k and get the statistic ˆ g
( z T ( d k )) ;
Compute and smooth the error term by e k =
d ref k − ˆ g ( z T ( d k )) , w k
=
(1 − τ ) w k − 1 + τe k ;
Compute action: u raw k
= K p w k
(cid:124) (cid:123)(cid:122) (cid:125) P-Part
+ K i k (cid:88)
i = k − T
i w i (cid:124) (cid:123)(cid:122) (cid:125)
I-Part
+ K
aw ( u k − 1 − u raw k − 1 ) (cid:124) (cid:123)(cid:122) (cid:125)
Anti-windup ;
Set d k +1 =
clip ( u raw k , − δd, δd ) + d k ; end
We propose the following update for the safety budget:
Error term
Low-pass filter
P-part e
[Equation] [Equation]
P
[Equation]
e
[Equation]
I-part
Anti-windup
Raw signal
I =
K i
[Equation]
i
[Equation]
u
[Equation]
, u raw [Equation] =
[Equation]
Clipping
New safety budget u
[Equation]
A
[Equation]
where e k is the current constraint violation, w k is the filtered error term e k , P , I , AW are the proportional, integral and anti-windup parts of the controller.
The gains K p , K i , K
aw , as well as T i , δd and τ are hyper-parameters.
A2.2 Q Simmer
We're very safe!
We can risk it!
We're not safe!
No risk!
We're borderline safe...
Can we risk?
Our design for the Q learning approach is guided by the intuition depicted in Figure A2 and presented in what follows.
If the current accumulated costs are well below the safety budget d ref , then we are very safe and the safety budget can be further increased.
If the accumulated costs are around the safety budget, then we could stay at the same level or increase the safety budget.
If the current accumulated costs are well above the safety budget d ref , then the safety budget should be decreased to ensure that the policy is incentivized to be safer.
a
Consider an MDP with the states { d 0 , . . .
, d K − 1 } , for simplicity of notation we consider the state space { 0 , . .
, K − 1 } with the actions { a − 1 , a 0 , a +1 } , where the action a +1 moves the state s =
i to the state s =
i + 1 , a − 1 moves the state s =
i to the state s =
i − 1 and the action a 0 does not transfer the state.
Note that the action a +1 is defined for all i < K − 1 and the action a − 1 is defined for all i > 0 .
The reward for this MDP is non-stationary and defined as follows:
We are not safe We are borderline safe
We are very safe
[Equation]
A4)
[Equation]
where o is the maximum accumulated cost (over an episode) of the constrained algorithm.
We use a
Q-learning update to learn the Q function:
[Equation]
and get the action with ε -greedy exploration strategy:
[Equation]
with probability
[Equation]
random with probability
[Equation]
A Implementation details
Pendulum Swing-up.
Our first environment is a safe pendulum swing-up defined in [16] and built upon the Open AI Gym environment [11].
The reward is defined as
[Equation]
, while the safety cost
[Equation]
otherwise, where θ is the deviation of the pole angle from the upright position.
Effectively, we want to force the pendulum to swing up from one side.
See Figure A3a.
Safety Gym.
We use several safety gym environments [37].
We use the benchmark environments
PointGoal1, PointButton1, PointPush1, CarGoal1, CarPush1 (see Figures A3c-A3h), but we also use a custom-made one from [51] (the environment is schematically depicted in Figure A3b.).
In the custom-made environment called static point goal, a large static hazard region is placed in front of the goal.
This is similar to our motivational example in Figure 1.
This environment confirms our intuition.
We use two robots, the point robot has 46 states and 2 actions, while the car robot hasstates and 2 actions.
Code base and hyper-parameters.
Our code is based on two repositories: safety starter agents [37], and PID Lagrangian [44].
We have implemented the safety state augmentation following the description in [43].
We use default parameters for both code bases unless stated otherwise.
We performed a parameter search where we set the batch size for all the environments to 512 .
We then tried a few runs with K i ∈ [0 . 001 , 0 .
and determined that K i = 0 .
05 generally performs better for the goal and button tasks, while K i = 0 .
01 appears to perform well for the push tasks.
We then tested K p ∈ [0 . 01 , 0 . 05 , 0 . 1 , 0 .
5 , 1 , 5] and our best results are presented in Table A1.
The simmering schedule changes the safety budget every 200 epochs, where the length of the epoch depends on the batch size and is presented in Table A1.
A Further Experiments A4.1 Safety Gym
We present numerical results for the car and the point robot experiments in Table A2.
a
[Figure]
a
[Table] [Table]
A4.2 Ablation for PI Simmer
First, we conduct the ablation study over the parameter of the low pass filter τ in Figure A4a, while we set K = 0 .
1 , K i = 0 .
005 , K
aw = 0 .
We notice that smaller values of τ deliver small deviations from the schedule, while larger values have more freedom to decide on an appropriate schedule.
However, it is noticeable that the runs with small τ ( 0 .
and 0 .
005 ) are constantly acquiring constraint violations, which happens less often for large values of τ ( 1 and 0 . 995 ).
We believe this is because the controller with smaller values of τ ignores (filters out) spurious constraint violations, but with larger values of τ this is not happening.
At the same time, PI Simmer with large τ changes the safety budget quite aggressively in the early stages due to constant constraint violations, which can be avoided if a small τ is chosen.
Ultimately the choice of τ is up to the user, but we would recommend starting with large values.
We observed that it is probably most prudent to choose a small value for K as our deviations from schedule d test k are bounded and there is no need for drastic changes in the safety budget that proportional control can achieve.
Indeed, we set K
aw = 0 .
1 , K i = 0 .
005 , τ = 0 .
995 and change the parameter K and the results in Figure A4c supports our claims.
We now turn our attention to the gain K i of the integral control, while we set K = 0 .
1 , K
aw = 0 .
01 , τ = 1 .
We stress that the choice of the gains K i , K aw is somewhat interconnected, i.e., with increasing K i the gain
K aw should increase as well to counteract saturation.
However, it appears the choice of K i can have a more significant effect on performance.
Figure A4b suggests that large values of K i lead to aggressive changes in the safety budget and, more importantly, later lead to saturation in control limiting the ability of PI Simmer to react to violations.
Smaller values of K i allow for a balanced approach.
Finally, ablation over K
aw in Figure A4d with K = 0 .
1 , K i = 0 .
04 , τ = 1 . 0 shows that while large values of K
aw decrease the risk of saturation they also diminish the efficacy of integral control.
On the other hand, with zero anti-windup gain, the actions are always saturated leading to more constraint violations without any reaction from the controller.
Therefore, again a balanced approach is preferable.
A4.3 Ablation for Q Simmer
We perform ablation on the following parameters the learning rate l r , the Polayk’s update τ , and the reward threshold r thr .
Figure A5a suggest that large learning rates preferable.
This is perhaps due to the ability to fast learning, but also fast forgetting may be important since the process is non-stationary.
Ablation with respect to τ is performed in Figure A5b suggesting that higher values of τ are preferable, but τ = 1 forces the algorithm to oscillate between two adjacent values too often.
a
[Figure]
Number of violations
[Figure]
Similarly the value for r thr needs to be chosen so that oscillations between adjacent safety budget does not occur as Figure A5c suggests
[Figure]
a
[Figure]
A Illustrations
Parts of the illustrations in Figure 1 are designed by gstudioimagen, macrovector official, Flaticon
[Figure]
and downloaded from http://www.freepik.com .
The illustrations in Figures 2 and A3 are from [43, 37]
[Figure]
a