PS2-RL · The math

Safety from rollouts, performance from gradients

This page collects the formulation and results of the paper in one place, from backup control barrier functions to the guarantees of the full pipeline. Numbers in parentheses, such as (10) or Theorem 4.3, match the arXiv paper. Proofs are summarized in collapsible blocks.

1Setting

We consider a control-affine, continuous-time system with bounded inputs,

$$\dot x = f(x) + g(x)\,u,\qquad x\in\mathcal X\subseteq\mathbb R^n,\quad u\in\mathcal U\subseteq\mathbb R^m, \tag{1}$$

where $\mathcal U$ is a compact set encoding actuator limits and $f,g$ are locally Lipschitz. For a state-feedback policy $\pi:\mathcal X\to\mathcal U$, the closed-loop vector field is $f_\pi(x):=f(x)+g(x)\pi(x)$, and $\Phi_\pi(x_0,t)$ denotes its flow: the state at time $t$ starting from $x_0$.

Safety is specified by a safe set $\mathcal S:=\{x\in\mathcal X: h_{\mathcal S}(x)\ge 0\}$ with $h_{\mathcal S}$ continuously differentiable. The complement $\mathcal F:=\mathcal X\setminus\mathcal S$ is the failure set.

Reinforcement learning

The task is a Markov decision process $(\mathcal X,\mathcal U,F,r,\gamma)$ with deterministic transitions $x_{k+1}=F(x_k,u_k)$, reward $r$, and discount $\gamma\in(0,1)$. A neural policy $\pi_\phi$ maximizes

$$J(\pi_\phi)=\mathbb E\Big[\sum_{k=0}^{\infty}\gamma^k r(x_k,u_k)\Big],\qquad Q^{\pi_\phi}_\gamma(x,u)=r(x,u)+\gamma\,Q^{\pi_\phi}_\gamma\big(F(x,u),\pi_\phi(F(x,u))\big),$$

with $x_0\sim\rho_0$ and $x_{k+1}=F(x_k,\pi_\phi(x_k))$.

Remark 3.1 (sampled data)

The policy is evaluated at sample times $t_k=k\Delta t$ and its output is held by zero-order hold (ZOH), so $F$ is the exact ZOH dynamics of (1) over one sampling interval. The guarantees below are for this sampled-data discrete system. Under standard Lipschitz regularity and a sufficiently fast control rate, BCBF conditions enforced at the sample instants imply continuous-time safety of the ZOH trajectory.

2Control invariance and control barrier functions

Not every state in $\mathcal S$ is safe in the dynamical sense: under bounded inputs, some states inside $\mathcal S$ inevitably leave it. Safe control therefore looks for an invariant subset of $\mathcal S$.

Definition C.1 (control invariance)

A set $\mathcal I\subseteq\mathcal S$ is control-invariant if there is a feedback policy $\pi:\mathcal X\to\mathcal U$ such that every closed-loop trajectory with $x(0)\in\mathcal I$ satisfies $x(t)\in\mathcal I$ for all $t\ge 0$.

Definition C.2 (control barrier function)

A continuously differentiable $h_{\mathcal C}$ is a CBF for $\mathcal C:=\{x:h_{\mathcal C}(x)\ge0\}\subseteq\mathcal S$ if, for an extended class-$\mathcal K_\infty$ function $\alpha$ and all $x\in\mathcal C$,

$$\sup_{u\in\mathcal U}\Big[\nabla h_{\mathcal C}(x)^\top\big(f(x)+g(x)u\big)+\alpha\big(h_{\mathcal C}(x)\big)\Big]\ \ge\ 0. \tag{20}$$

This makes the admissible set $\mathbb K_{\mathcal C}(x):=\{u\in\mathcal U:\nabla h_{\mathcal C}(x)^\top(f(x)+g(x)u)+\alpha(h_{\mathcal C}(x))\ge0\}$ nonempty. A CBF safety filter minimally modifies a nominal input,

$$u_{\text{safe}}(x)=\arg\min_{u\in\mathcal U}\ \|u-u_{\text{nom}}\|_2^2\quad\text{s.t.}\quad \nabla h_{\mathcal C}(x)^\top\big(f(x)+g(x)u\big)+\alpha\big(h_{\mathcal C}(x)\big)\ge 0, \tag{22–23}$$

a convex QP whenever $\mathcal U$ is convex, because the constraint is affine in $u$. If a locally Lipschitz policy satisfies $\pi(x)\in\mathbb K_{\mathcal C}(x)$ on $\mathcal C$, then $\mathcal C$ is forward invariant (Proposition C.1). The hard part is not using a CBF but finding one whose superlevel set is control-invariant under bounded inputs. Hamilton–Jacobi reachability computes maximal invariant sets but scales exponentially with $n$; sum-of-squares programs scale poorly with dimension and degree and are often conservative.

3Backup control barrier functions

Backup CBFs (Chen et al., 2021; Gurriet et al., 2020) avoid synthesizing a global invariant set. They start from a small, known control-invariant base set

$$\mathcal B:=\{x\in\mathcal X: h_{\mathcal B}(x)\ge 0\}\subseteq\mathcal S \tag{24}$$

with a certified base controller $\pi_{\mathcal B}$, and a deterministic backup policy $\pi_b$ that agrees with $\pi_{\mathcal B}$ on $\mathcal B$.

Definition 2.1 (backup-induced control-invariant set)

$\mathcal C_T(\pi_b)$ is the set of all states from which $\pi_b$ recovers to $\mathcal B$ within the backup horizon $T$ while keeping the trajectory in $\mathcal S$:

$$\begin{aligned}\mathcal C_T(\pi_b)&=\mathcal R\big(\mathcal B,\mathcal S,f_{\pi_b},T\big)\\ &:=\big\{x\in\mathcal X:\ \Phi_{\pi_b}(x,T)\in\mathcal B\ \wedge\ \Phi_{\pi_b}(x,t')\in\mathcal S\ \ \forall t'\in[0,T]\big\}.\end{aligned} \tag{2}$$

Proposition C.2 (backup-induced invariance)

If $\mathcal B$ is control-invariant under $\pi_{\mathcal B}$ and $\pi_b=\pi_{\mathcal B}$ on $\mathcal B$, then $\mathcal B\subseteq\mathcal C_T(\pi_b)\subseteq\mathcal S$ and $\mathcal C_T(\pi_b)$ is control-invariant. [Chen et al., Thm. 1]

The set is the zero-superlevel set of an implicit CBF, evaluated by simulation rather than stored:

$$h_{\mathcal C_T}(x)=\min\Big\{\min_{t'\in[0,T]} h_{\mathcal S}\big(\Phi_{\pi_b}(x,t')\big),\ h_{\mathcal B}\big(\Phi_{\pi_b}(x,T)\big)\Big\}. \tag{3}$$

From the implicit barrier to affine constraints

The $\min$ in (3) is nonsmooth, so BCBF enforces sufficient CBF inequalities pointwise along the backup rollout and at the horizon. Let the flow sensitivity be

$$\Psi_{\pi_b}(x,t'):=\frac{\partial\Phi_{\pi_b}(x,t')}{\partial x},\qquad \frac{d}{dt'}\Psi_{\pi_b}(x,t')=\frac{\partial f_{\pi_b}}{\partial x}\big(\Phi_{\pi_b}(x,t')\big)\,\Psi_{\pi_b}(x,t'),\quad \Psi_{\pi_b}(x,0)=I. \tag{28–29}$$

For a candidate current input $u$, the rollout and terminal derivative terms are

$$\begin{aligned} \mathcal D^{\mathcal S}_{t'}(x,u)&:=\nabla h_{\mathcal S}\big(\Phi_{\pi_b}(x,t')\big)^{\!\top}\Big[\Psi_{\pi_b}(x,t')\big(f(x)+g(x)u\big)-f_{\pi_b}\big(\Phi_{\pi_b}(x,t')\big)\Big],\\ \mathcal D^{\mathcal B}_{T}(x,u)&:=\nabla h_{\mathcal B}\big(\Phi_{\pi_b}(x,T)\big)^{\!\top}\,\Psi_{\pi_b}(x,T)\big(f(x)+g(x)u\big). \end{aligned}\tag{30–31}$$

The subtraction in $\mathcal D^{\mathcal S}_{t'}$ appears because the rollout constraints are indexed by future time: as real time advances, the same future point on the backup rollout moves closer at rate $f_{\pi_b}$. The terminal condition uses the fixed horizon $T$, so it has no such term. Given extended class-$\mathcal K_\infty$ functions $\alpha_{\mathcal S},\alpha_{\mathcal B}$, the BCBF-admissible input set is

$$\begin{aligned}\mathbb K_{\mathrm{BCBF}}(x;\pi_b):=\Big\{u\in\mathcal U:\ &\mathcal D^{\mathcal S}_{t'}(x,u)+\alpha_{\mathcal S}\big(h_{\mathcal S}(\Phi_{\pi_b}(x,t'))\big)\ge0\ \ \ \forall t'\in[0,T],\\ &\mathcal D^{\mathcal B}_{T}(x,u)+\alpha_{\mathcal B}\big(h_{\mathcal B}(\Phi_{\pi_b}(x,T))\big)\ge 0\Big\}.\end{aligned} \tag{6}$$

For fixed $x$ and $\pi_b$, the rollout and its sensitivity are constants with respect to $u$, so every constraint is affine in $u$, and $\mathbb K_{\mathrm{BCBF}}(x;\pi_b)$ is convex whenever $\mathcal U$ is.

Proposition C.3 (BCBF feasibility and safety)

For every $x\in\mathcal C_T(\pi_b)$, the set $\mathbb K_{\mathrm{BCBF}}(x;\pi_b)$ is nonempty; in particular $\pi_b(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b)$. Any locally Lipschitz policy with $\pi(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b)$ on $\mathcal C_T(\pi_b)$ renders $\mathcal C_T(\pi_b)$ forward invariant, and hence keeps the trajectory in $\mathcal S$. [Chen et al., Thm. 2]

BCBFs also sidestep high relative degree. The composed functions $h_{\mathcal S}\circ\Phi_{\pi_b}(\cdot,t')$ depend on the current input through $\Psi_{\pi_b}(x,t')g(x)$, and under mild controllability conditions they have relative degree one for positive rollout times. Safety can therefore be written directly in physical coordinates, such as altitude or lane position, without high-order CBF constructions.

The remaining difficulty. BCBF moves the burden from synthesizing an invariant set to designing a backup policy, and the size of $\mathcal C_T(\pi_b)$ depends critically on that policy. Hand-designed backups such as LQR are easy to certify but recover only a small part of the safe region. PS2-RL learns the backup instead.

4Problem formulation and decomposition

Problem 1 (PS2-RL formulation)

Given system (1) with ZOH discretization $F$, a safe set $\mathcal S$, an admissible input set $\mathcal U$, an initial distribution $\rho_0$ supported on $\mathcal X_0\subseteq\mathcal S$, a reward $r$ and $\gamma\in(0,1)$, find

$$\begin{aligned}\max_{\pi}\ \ & J(\pi)=\mathbb E_{\substack{x_0\sim\rho_0,\ u_k=\pi(x_k)\\ x_{k+1}=F(x_k,u_k)}}\Big[\sum_{k=0}^{\infty}\gamma^k r(x_k,u_k)\Big]\\ \text{s.t.}\ \ & x_k\in\mathcal S,\ \ u_k\in\mathcal U,\quad\forall k\ge 0,\ \forall x_0\in\mathcal X_0.\end{aligned} \tag{5}$$

Let $\Pi_{\text{safe}}$ be the feasible policy class of Problem 1: the constraints hold pointwise in $k$, for every trajectory and every initial state in $\mathcal X_0$. A policy is provably safe if it provably belongs to $\Pi_{\text{safe}}$. Constrained policy optimization methods (CMDPs, state-wise safe RL) may use similar formulations, but they do not certify membership in $\Pi_{\text{safe}}$.

Subproblem 1: optimize under a fixed backup policy

Subproblem 1 (BCBF-constrained policy optimization)

Fix a backup policy $\pi_b$ and horizon $T$, and assume $\mathcal X_0\subseteq\mathcal C_T(\pi_b)$. Find

$$\max_{\pi_\phi}\ J(\pi_\phi)\quad\text{s.t.}\quad \pi_\phi(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b)\quad\forall x\in\mathcal C_T(\pi_b). \tag{7}$$

Remark 4.1 (finite mesh)

In practice the constraints are enforced on a relative-time mesh $0=t'_0<t'_1<\dots<t'_N=T$. Under standard Lipschitz regularity and Remark 3.1, sampled BCBF enforcement at the instants $t_k$ implies continuous-time safety of the ZOH trajectory.

Subproblem 2: enlarge the certified set

The conservatism of Subproblem 1 is governed by $\mathcal C_T(\pi_b)$. PS2-RL anchors the backup policy to a certified base pair and learns only the part outside it:

$$\pi_b(x)=\begin{cases}\pi_{\mathcal B}(x), & x\in\mathcal B,\\ \pi_{\mathrm{SA}}(x), & x\notin\mathcal B.\end{cases} \tag{8}$$

Here $\pi_{\mathcal B}:\mathcal B\to\mathcal U$ renders $\mathcal B$ forward invariant, and the safe-arrival policy $\pi_{\mathrm{SA}}:\mathcal X\setminus\mathcal B\to\mathcal U$ steers states into $\mathcal B$ within $T$ while staying in $\mathcal S$. Only $(\mathcal B,\pi_{\mathcal B})$ must be certified; $\pi_{\mathrm{SA}}$ need not be.

Assumption 4.1 (local stabilizability)

There exist $x^\star\in\operatorname{int}(\mathcal S)$ and $u^\star\in\operatorname{int}(\mathcal U)$ such that (a) $f(x^\star)+g(x^\star)u^\star=0$, and (b) the linearization $(A,B)$ of (1) about $(x^\star,u^\star)$, with $A=\partial(f+gu^\star)/\partial x\,|_{x=x^\star}$ and $B=g(x^\star)$, is locally stabilizable.

Theorem 4.1 (existence of a certified local base set)

Under Assumption 4.1 there exist a gain $K\in\mathbb R^{m\times n}$, a matrix $P\succ0$ and $\bar c>0$ such that $\pi_{\mathcal B}(x)=u^\star-K(x-x^\star)$ and $\mathcal B_c=\{x:(x-x^\star)^\top P(x-x^\star)\le c\}$, $c\in(0,\bar c]$, satisfy: (i) $\mathcal B_c\subseteq\mathcal S$; (ii) $\pi_{\mathcal B}(x)\in\mathcal U$ for all $x\in\mathcal B_c$; (iii) $\mathcal B_c$ is control-invariant under $\pi_{\mathcal B}$; (iv) every trajectory with $x(0)\in\mathcal B_c$ stays in $\mathcal B_c$ and converges to $x^\star$.

Proof sketch

Pick $K$ with $A-BK$ Hurwitz and any $Q\succ0$; the Lyapunov equation $(A-BK)^\top P+P(A-BK)=-Q$ has a unique solution $P\succ0$. With $e=x-x^\star$ and $V(e)=e^\top Pe$, a Taylor expansion of the closed loop gives $\dot e=(A-BK)e+\rho(e)$ with $\|\rho(e)\|=o(\|e\|)$, so $\dot V\le-\tfrac12\lambda_{\min}(Q)\|e\|^2<0$ on a small ball. That yields invariance and convergence on a sublevel set $V\le c_1$. Since $x^\star\in\operatorname{int}(\mathcal S)$ and $u^\star\in\operatorname{int}(\mathcal U)$, smaller levels $c_2,c_3$ give $\mathcal B_c\subseteq\mathcal S$ and $\pi_{\mathcal B}(\mathcal B_c)\subseteq\mathcal U$. Take $\bar c=\min\{c_1,c_2,c_3\}$.

So any stabilizing linear feedback (pole placement, LQR, …) followed by a sublevel-set check for input feasibility and $\mathcal S$-containment produces a valid base pair, with no global search. With $(\mathcal B,\pi_{\mathcal B})$ fixed, $\mathcal C_T$ grows with $T$, but so does the number of constraints. A better safe-arrival policy enlarges it at a fixed horizon instead:

Subproblem 2 (safe-arrival set maximization)

Given $(\mathcal B,\pi_{\mathcal B})$ from Theorem 4.1, a horizon $T>0$, a compact design region $\Omega\subseteq\mathcal S$ and a finite measure $\mu$ on $\Omega\setminus\mathcal B$, find

$$\max_{\pi^\theta_{\mathrm{SA}}}\ \mu_{\mathrm{SA}}\big(\pi^\theta_{\mathrm{SA}};\Omega,\mathcal B\big):=\mu\big(\mathcal C_T(\pi^\theta_b)\cap(\Omega\setminus\mathcal B)\big)\quad\text{s.t.}\quad \pi^\theta_b(x)=\begin{cases}\pi_{\mathcal B}(x), & x\in\mathcal B,\\ \pi^\theta_{\mathrm{SA}}(x), & x\notin\mathcal B.\end{cases} \tag{9}$$

The decomposition is certified

For a fixed backup policy define the BCBF-feasible class $\Pi_{\mathrm{BCBF}}(\pi_b):=\{\pi:\mathcal X\to\mathcal U:\ \pi(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b)\ \forall x\in\mathcal C_T(\pi_b)\}$.

Theorem 4.2 (certified decomposition and exactness)

Suppose $(\mathcal B,\pi_{\mathcal B})$ satisfies Theorem 4.1, let $\pi_b^\star$ solve Subproblem 2 and $\pi_\phi^\star$ solve Subproblem 1 with $\pi_b^\star$, and assume the exact constraints (6) are enforced. Then

  1. $\Pi_{\mathrm{BCBF}}(\pi_b^\star)\subseteq\Pi_{\text{safe}}$, so $\pi_\phi^\star$ is feasible for Problem 1;
  2. $J(\pi_\phi^\star)=\sup_{\pi\in\Pi_{\mathrm{BCBF}}(\pi_b^\star)}J(\pi)\le\sup_{\pi\in\Pi_{\text{safe}}}J(\pi)$;
  3. if some globally optimal safe policy $\pi^\star_{\text{safe}}$ lies in $\Pi_{\mathrm{BCBF}}(\pi_b^\star)$, then $\pi_\phi^\star$ is globally optimal for Problem 1.

The two subproblems thus solve a certified inner approximation of Problem 1, and solve it exactly whenever the learned backup induces a feasible class containing an optimal safe policy.

Proof sketch

(i) Take $\pi\in\Pi_{\mathrm{BCBF}}(\pi_b^\star)$ and $x_0\in\mathcal X_0\subseteq\mathcal C_T(\pi_b^\star)$. The pointwise BCBF inequalities along the rollout and at the horizon are sufficient for the CBF condition on $h_{\mathcal C_T}$ (Chen et al., Prop. 2), so $\mathcal C_T(\pi_b^\star)\subseteq\mathcal S$ is forward invariant, and $\mathbb K_{\mathrm{BCBF}}\subseteq\mathcal U$ keeps the inputs admissible. (ii) follows from the definition of Subproblem 1 and (i). (iii) $J(\pi_\phi^\star)\ge J(\pi^\star_{\text{safe}})$ because $\pi_\phi^\star$ is optimal over a class containing $\pi^\star_{\text{safe}}$, and $J(\pi_\phi^\star)\le J(\pi^\star_{\text{safe}})$ by (i).

5The safe-arrival value function

Subproblem 2 needs an RL objective whose optimum enlarges $\mathcal C_T$. PS2-RL uses an indicator-style value that represents the reach-avoid event directly, rather than a dense geometric surrogate. Consider the deterministic system $x_{k+1}=F(x_k,u_k)$ with base set $\mathcal B$, failure set $\mathcal F=\mathcal X\setminus\mathcal S$, and continuation set $\mathcal H:=\mathcal X\setminus(\mathcal B\cup\mathcal F)$, assuming $\mathcal B\cap\mathcal F=\varnothing$. The indicators are

$$\mathbf b(x)=\mathbf 1_{\mathcal B}(x),\qquad \mathbf f(x)=\mathbf 1_{\mathcal F}(x),\qquad \mathbf c(x)=1-\mathbf b(x)-\mathbf f(x)=\mathbf 1_{\mathcal H}(x). \tag{38}$$

For a pair $(x,u)$ and a policy $\pi$, the rollout is $x_0=x$, $u_0=u$, $x_{k+1}=F(x_k,u_k)$ and $u_k=\pi(x_k)$ for $k\ge1$. The hitting times and the safe-arrival event are

$$\begin{gathered}\tau_{\mathcal B}=\inf\{k\ge0:x_k\in\mathcal B\},\qquad \tau_{\mathcal F}=\inf\{k\ge0:x_k\in\mathcal F\},\\ E_{\mathrm{SA}}:=\{\tau_{\mathcal B}<\tau_{\mathcal F},\ \tau_{\mathcal B}<\infty\}.\end{gathered} \tag{42–43}$$

Probability and expectation notation is kept even though the deterministic case gives laws concentrated on a single trajectory: the construction extends unchanged to stochastic dynamics and policies.

Undiscounted value: feasibility

Definition D.1 (undiscounted safe-arrival value)

$$Q^\pi_{\mathrm{SA}}(x,u):=\mathbb P^\pi_{x,u}\big(\tau_{\mathcal B}<\tau_{\mathcal F},\ \tau_{\mathcal B}<\infty\big),\qquad V^\pi_{\mathrm{SA}}(x):=Q^\pi_{\mathrm{SA}}(x,\pi(x)). \tag{44–45}$$

Propositions D.1–D.2 (indicator form, self-consistency)

$$\begin{gathered}Q^\pi_{\mathrm{SA}}(x,u)=\mathbb E^\pi_{x,u}\Big[\sum_{k=0}^{\infty}\Big(\prod_{i=0}^{k-1}\mathbf c(x_i)\Big)\mathbf b(x_k)\Big],\\ Q^\pi_{\mathrm{SA}}(x,u)=\mathbf b(x)+\mathbf c(x)\,Q^\pi_{\mathrm{SA}}\big(F(x,u),\pi(F(x,u))\big).\end{gathered} \tag{46, 49}$$

The product is a survival gate: it equals 1 only while the rollout stays in $\mathcal H$, so exactly one term, at $k=\tau_{\mathcal B}$, survives on the safe-arrival event and the sum is its indicator.

The optimal values satisfy $Q^\star_{\mathrm{SA}}(x,u)=\mathbf b(x)+\mathbf c(x)\max_{u^+}Q^\star_{\mathrm{SA}}(F(x,u),u^+)$, and they define the region where safe arrival is possible at all.

Definitions D.2–D.3 (safe-arrival region, minimum arrival time)

$$\begin{gathered}\mathcal R_{\mathrm{SA}}:=\{x:V^\star_{\mathrm{SA}}(x)=1\},\\ d(x):=\inf\Big\{k:\exists\,(u_0,\dots,u_{k-1})\ \text{with}\ x_i\in\mathcal H\ \forall i<k,\ x_k\in\mathcal B\Big\}.\end{gathered} \tag{58–59}$$

Proposition D.3 (finite-step characterization)

With $\mathcal R_0:=\mathcal B$ and $\mathcal R_{n+1}:=\mathcal R_n\cup\{x\in\mathcal H:\exists u\in\mathcal U,\ F(x,u)\in\mathcal R_n\}$,

$$\mathcal R_{\mathrm{SA}}=\bigcup_{n\ge0}\mathcal R_n=\{x:d(x)<\infty\},\qquad d(x)=\min\{n\ge0:x\in\mathcal R_n\}\ \ \text{for }x\in\mathcal R_{\mathrm{SA}}. \tag{62–63}$$

Discounted value: what PS2-RL trains

Definition 4.1 (safe-arrival value function)

For a deterministic safe-arrival policy $\pi_{\mathrm{SA}}$ and $\beta\in(0,1)$,

$$Q^{\pi_{\mathrm{SA}}}_{\mathrm{SA},\beta}(x,u):=\mathbb E^{\pi_{\mathrm{SA}}}_{x,u}\Big[\sum_{k=0}^{\infty}\beta^k\Big(\prod_{\tau=0}^{k-1}\mathbf c(x_\tau)\Big)\mathbf b(x_k)\Big],\qquad V^{\pi_{\mathrm{SA}}}_{\mathrm{SA},\beta}(x):=Q^{\pi_{\mathrm{SA}}}_{\mathrm{SA},\beta}\big(x,\pi_{\mathrm{SA}}(x)\big), \tag{10}$$

with the empty product equal to 1.

Proposition D.4 (two interpretations)

$$Q^{\pi}_{\mathrm{SA},\beta}(x,u)=\mathbb E^\pi_{x,u}\Big[\beta^{\tau_{\mathcal B}}\,\mathbf 1\{\tau_{\mathcal B}<\tau_{\mathcal F},\ \tau_{\mathcal B}<\infty\}\Big]=\big(\mathbb P^\pi_{x,u}\otimes\mathbb P_N\big)\big(\tau_{\mathcal B}<\tau_{\mathcal F},\ \tau_{\mathcal B}\le N\big), \tag{66, 68}$$

where $N$ is an independent geometric horizon, $\mathbb P_N(N=k)=(1-\beta)\beta^k$. Under deterministic dynamics the value is $\beta^{N}$ if the rollout reaches $\mathcal B$ safely in exactly $N$ steps and $0$ otherwise. $\beta$ acts as an urgency parameter.

Proposition D.5 (self-consistency) and the Bellman equation

$$Q^{\pi_{\mathrm{SA}}}_{\mathrm{SA},\beta}(x,u)=\mathbf b(x)+\beta\,\mathbf c(x)\,Q^{\pi_{\mathrm{SA}}}_{\mathrm{SA},\beta}\big(F(x,u),\pi_{\mathrm{SA}}(F(x,u))\big), \tag{11}$$
$$Q^\star_{\mathrm{SA},\beta}(x,u)=\mathbf b(x)+\beta\,\mathbf c(x)\max_{u^+\in\mathcal U}Q^\star_{\mathrm{SA},\beta}\big(F(x,u),u^+\big). \tag{81}$$

The operator $(\mathcal T_\beta Q)(x,u):=\mathbf b(x)+\beta\mathbf c(x)\max_{u^+}Q(F(x,u),u^+)$ is a $\beta$-contraction in the sup norm, since $|\mathcal T_\beta Q_1-\mathcal T_\beta Q_2|\le\beta\,\mathbf c(x)\max_{u^+}|Q_1-Q_2|\le\beta\|Q_1-Q_2\|_\infty$. The Bellman equation therefore has the unique bounded fixed point $Q^\star_{\mathrm{SA},\beta}$, and standard value-based and actor–critic RL applies.

Proposition D.6 (discounting preserves feasibility)

$$Q^\pi_{\mathrm{SA}}(x,u)=1\iff Q^\pi_{\mathrm{SA},\beta}(x,u)>0,\qquad \lim_{\beta\uparrow1}Q^\pi_{\mathrm{SA},\beta}(x,u)=Q^\pi_{\mathrm{SA}}(x,u). \tag{86–87}$$

Proposition D.7 (arrival-time optimality)

$$\begin{gathered}V^\star_{\mathrm{SA},\beta}(x)=\begin{cases}\beta^{d(x)}, & d(x)<\infty,\\ 0, & d(x)=\infty,\end{cases}\\[6pt] Q^\star_{\mathrm{SA},\beta}(x,u)=\begin{cases}1, & x\in\mathcal B,\\ \beta^{1+d(F(x,u))}, & x\in\mathcal H,\ d(F(x,u))<\infty,\\ 0, & \text{otherwise.}\end{cases}\end{gathered} \tag{89–90}$$

Consequently $\mathcal R_{\mathrm{SA}}=\{x:V^\star_{\mathrm{SA}}(x)=1\}=\{x:d(x)<\infty\}=\{x:V^\star_{\mathrm{SA},\beta}(x)>0\}$ for every $\beta\in(0,1)$, and $V^\star_{\mathrm{SA},\beta}\to V^\star_{\mathrm{SA}}$ as $\beta\uparrow1$.

What optimal safe-arrival actions do

Partition the state space as $\mathcal X=\mathcal B\,\dot\cup\,\mathcal F\,\dot\cup\,(\mathcal R_{\mathrm{SA}}\cap\mathcal H)\,\dot\cup\,(\mathcal H\setminus\mathcal R_{\mathrm{SA}})$ (Proposition D.8):

  • In $\mathcal B$ both values equal 1, and in $\mathcal F$ both equal 0; every action is equivalent.
  • In $\mathcal R_{\mathrm{SA}}\cap\mathcal H$, an action is optimal for the undiscounted value iff $F(x,u)\in\mathcal R_{\mathrm{SA}}$: it preserves feasibility but does not rank arrival times. It is optimal for the discounted value iff additionally $d(F(x,u))=d(x)-1$, so a discounted-optimal policy reaches $\mathcal B$ in exactly $d(x)$ steps.
  • In $\mathcal H\setminus\mathcal R_{\mathrm{SA}}$ no policy can safely arrive, and both values are 0.

The undiscounted value supplies the feasibility semantics ($\mathcal R_{\mathrm{SA}}$). The discounted value preserves that region and adds a contraction-based, time-sensitive training signal (Remark D.1).

6Phase I: training the safe-arrival policy

With a design distribution $\rho_{\mathrm{arr}}$ supported on $\Omega\setminus\mathcal B$, Phase I solves

$$\max_\theta\ J_{\mathrm{SA},\beta}(\theta):=\mathbb E_{x\sim\rho_{\mathrm{arr}}}\Big[Q^{\pi^\theta_{\mathrm{SA}}}_{\mathrm{SA},\beta}\big(x,\pi^\theta_{\mathrm{SA}}(x)\big)\Big]. \tag{12}$$

Algorithm 1 (safe-arrival policy training)

  1. Initialize the safe-arrival policy parameters $\theta$ and the value/Q-function parameters.
  2. Repeat until converged: sample $x_0\sim\rho_{\mathrm{arr}}$, and collect rollouts under $\pi^\theta_{\mathrm{SA}}$ until $x_k\in\mathcal B$ or $x_k\in\mathcal F$ (first-hit termination);
  3. label each $x_k$ with $\mathbf b(x_k)$, $\mathbf f(x_k)$, $\mathbf c(x_k)=1-\mathbf b(x_k)-\mathbf f(x_k)$;
  4. update the value/Q estimator with the Bellman recursion (11), and improve $\theta$ with the chosen RL backbone.
  5. Return $\pi^\theta_{\mathrm{SA}}$ and freeze the composed backup policy $\pi^\theta_b$ for Phase II.

The only ingredients specific to safe arrival are the indicators, first-hit termination, and objective (12); everything else comes from the RL backbone (actor–critic, Q-learning, fitted value iteration, …). In the experiments, a TD3-style off-policy backbone with twin critics trained by the recursion (11) under a Huber loss is used, with $\beta=0.92$ (unicycle) and $\beta=0.99$ (quadrotor). A mild curriculum that expands $\rho_{\mathrm{arr}}$ outward from $\mathcal B$ is an optimization heuristic, not a requirement.

7Phase II: the control-invariant layer

PS2-RL builds on HardNet-CVX (Min & Azizan), which projects a network's output onto a state-dependent convex set through a differentiable optimization layer.

Definition 2.2 (constraint projection layer)

$$\mathcal P(\pi_\phi)(x)=\arg\min_u\ \|u-\pi_\phi(x)\|_2^2\quad\text{s.t.}\quad u\in\mathbb K(x). \tag{4}$$

With $\pi^\star_{\mathrm{SA}}$ from Phase I, freeze $\pi_b^\star(x)=\pi_{\mathcal B}(x)$ on $\mathcal B$ and $\pi_b^\star(x)=\pi^\star_{\mathrm{SA}}(x)$ otherwise. Then $\mathcal C_T(\pi_b^\star)$ and $\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star)$ are fixed, and the latter is convex for every $x$ when $\mathcal U$ is.

Definitions 4.2–4.3 (control-invariant layer, PS2 policy)

$$\begin{gathered}\mathcal P_{\mathrm{CIL}}(\pi_\phi)(x):=\arg\min_u\ \|u-\pi_\phi(x)\|_2^2\quad\text{s.t.}\quad u\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star),\\ \pi^\phi_{\mathrm{PS2}}(x;\pi_b^\star):=\mathcal P_{\mathrm{CIL}}(\pi_\phi)(x).\end{gathered} \tag{13–14}$$

This reparameterization turns Subproblem 1 into unconstrained optimization over $\phi$, $\max_\phi J(\pi^\phi_{\mathrm{PS2}}(\cdot;\pi_b^\star))$, with gradients flowing through (13).

The QP, explicitly

Allow multiple constraints, $\mathcal S=\{x:h_{\mathcal S,j}(x)\ge0,\ j=1..n_{\mathcal S}\}$ and $\mathcal B=\{x:h_{\mathcal B,\ell}(x)\ge0,\ \ell=1..n_{\mathcal B}\}$, and a mesh $0=t'_0<\dots<t'_N=T$. For the current $x$ and the frozen $\pi_b^\star$, define

$$x^b_i:=\Phi_{\pi_b^\star}(x,t'_i),\qquad \Psi_i:=\frac{\partial\Phi_{\pi_b^\star}(x,t'_i)}{\partial x},\qquad f^b_i:=f_{\pi_b^\star}(x^b_i),\qquad f_0:=f(x),\ \ g_0:=g(x). \tag{109}$$

Each safety component and node gives an affine row $a^{\mathcal S\top}_{i,j}u\le b^{\mathcal S}_{i,j}$, and each terminal base-set component gives $a^{\mathcal B\top}_{\ell}u\le b^{\mathcal B}_{\ell}$, with

$$\begin{aligned} a^{\mathcal S\top}_{i,j}&=-\nabla h_{\mathcal S,j}(x^b_i)^\top\Psi_i\,g_0, &\quad b^{\mathcal S}_{i,j}&=\alpha_{\mathcal S}\big(h_{\mathcal S,j}(x^b_i)\big)+\nabla h_{\mathcal S,j}(x^b_i)^\top\big[\Psi_i f_0-f^b_i\big],\\ a^{\mathcal B\top}_{\ell}&=-\nabla h_{\mathcal B,\ell}(x^b_N)^\top\Psi_N\,g_0, &\quad b^{\mathcal B}_{\ell}&=\alpha_{\mathcal B}\big(h_{\mathcal B,\ell}(x^b_N)\big)+\nabla h_{\mathcal B,\ell}(x^b_N)^\top\Psi_N f_0. \end{aligned}\tag{112–117}$$

Stacking gives $A_{\mathrm{BCBF}}(x)u\le b_{\mathrm{BCBF}}(x)$ with $n_c=(N+1)n_{\mathcal S}+n_{\mathcal B}$ rows. With box limits $u_{\min}\le u\le u_{\max}$ written as $A_{\mathcal U}u\le b_{\mathcal U}$, the layer is the QP

$$\mathcal P_{\mathrm{CIL}}(\pi_\phi)(x)=\arg\min_u\ \|u-\pi_\phi(x)\|_2^2\quad\text{s.t.}\quad A_{\mathrm{BCBF}}(x)\,u\le b_{\mathrm{BCBF}}(x),\quad A_{\mathcal U}u\le b_{\mathcal U}. \tag{122}$$

Numerical safeguard: a heavily penalized slack

The implementation solves a slack-regularized version with a single scalar slack shared by the BCBF rows only. The input limits are never relaxed:

$$\begin{aligned}(u^\star,\delta^\star)=\arg\min_{u,\delta}\ \ &\|u-\pi_\phi(x)\|_2^2+\lambda_\delta\,\delta^2\\ \text{s.t.}\ \ &A_{\mathrm{BCBF}}(x)u-\mathbf 1_{n_c}\delta\le b_{\mathrm{BCBF}}(x),\ \ A_{\mathcal U}u\le b_{\mathcal U},\ \ \delta\ge0,\end{aligned} \tag{123}$$

with $\lambda_\delta=10^5$ (unicycle) and $10^6$ (quadrotor); the layer returns $u^\star$. The slack absorbs small artificial infeasibilities from the finite mesh, numerical integration and sampled-data implementation near $\partial\mathcal C_T$. The formal guarantees correspond to $\delta^\star=0$. In evaluation, mean and median slack are on the order of $10^{-5}$ or smaller, the 99th percentile is at most $5.1\times10^{-5}$, and $\delta>10^{-4}$ never occurs on the unicycle and occurs on at most 0.088% of quadrotor steps (Table 7).

Training through the layer

All quantities that build $A_{\mathrm{BCBF}},b_{\mathrm{BCBF}}$ (backup rollout, sensitivity propagation, row construction) and the QP solve itself (qpax, a differentiable primal–dual interior-point solver) are differentiable JAX operations, so the actor gradient contains the QP solution:

$$\nabla_\phi\mathcal L_{\text{actor}}=\frac{\partial\mathcal L_{\text{actor}}}{\partial u^\star}\,\frac{\partial u^\star}{\partial u_{\text{nom}}}\,\frac{\partial u_{\text{nom}}}{\partial\phi}.$$

For a stochastic actor, the nominal action is sampled, $u^{\text{nom}}_k\sim\pi_\phi(\cdot\mid x_k)$, and then projected deterministically, $u_k=\mathcal P_{\mathrm{CIL}}(u^{\text{nom}}_k)(x_k)$. The environment and replay buffer only ever see projected controls, the actor loss evaluates the critic at the projected action, and target-policy actions in Bellman backups are projected too. This is the difference from a post-hoc shield: the projection is present during both data collection and gradient-based improvement.

Theorem 4.3 (safety guarantee of PS2-RL)

Suppose $(\mathcal B,\pi_{\mathcal B})$ satisfies Theorem 4.1, let $\pi_b^\star$ be the fixed composed backup policy, and assume $\mathcal X_0\subseteq\mathcal C_T(\pi_b^\star)$. Then for any policy $\pi_\phi$, the PS2 policy satisfies $\pi^\phi_{\mathrm{PS2}}\in\Pi_{\mathrm{BCBF}}(\pi_b^\star)\subseteq\Pi_{\text{safe}}$: every realized input satisfies $u_k\in\mathcal U$ and the sampled closed-loop trajectory satisfies $x_k\in\mathcal S$ for all $k\ge0$ and all $x_0\in\mathcal X_0$. Under the sampled-data conditions, the continuous-time ZOH trajectory remains in $\mathcal S$ as well.

Proof

For every $x\in\mathcal C_T(\pi_b^\star)$ the layer returns the projection of $\pi_\phi(x)$ onto $\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star)$, so $\pi^\phi_{\mathrm{PS2}}(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star)$, which is the defining property of $\Pi_{\mathrm{BCBF}}(\pi_b^\star)$. The conclusion follows from Theorem 4.2(i).

Theorem 4.4 (universal approximation of PS2-RL)

Fix $\pi_b^\star$, assume $\mathcal U$ is convex, and let $\Omega\subseteq\mathcal C_T(\pi_b^\star)$ be compact. Let $C(\Omega,\mathcal U)$ carry the norm $\|\pi\|_\infty:=\sup_{x\in\Omega}\|\pi(x)\|_\infty$, and let $\mathcal G_{\mathrm{NN}}$ universally approximate $\mathcal G\subseteq C(\Omega,\mathcal U)$. Define

$$\begin{gathered}\Pi^{\mathcal G_{\mathrm{NN}}}_{\mathrm{PS2}}(\pi_b^\star;\Omega):=\{\mathcal P_{\mathrm{CIL}}(\pi_\phi):\pi_\phi\in\mathcal G_{\mathrm{NN}}\},\\ \Pi_{\mathrm{BCBF}}(\pi_b^\star;\Omega):=\{\pi\in\mathcal G:\pi(x)\in\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star)\ \forall x\in\Omega\}.\end{gathered} \tag{15–16}$$

Then $\Pi^{\mathcal G_{\mathrm{NN}}}_{\mathrm{PS2}}(\pi_b^\star;\Omega)$ universally approximates $\Pi_{\mathrm{BCBF}}(\pi_b^\star;\Omega)$ under $\|\cdot\|_\infty$. The same holds in $L^p(\Omega,\mathcal U)$.

Proof sketch

On $\Omega\subseteq\mathcal C_T(\pi_b^\star)$, $\mathbb K_{\mathrm{BCBF}}(x;\pi_b^\star)$ is nonempty (BCBF feasibility) and convex (affine rows, convex $\mathcal U$). So (13) is exactly a HardNet-CVX projection onto a state-dependent convex set, and the result follows from the HardNet-CVX universal approximation theorem (Min & Azizan, Thm. 12).

Together, Theorems 4.3 and 4.4 say the layer enforces safety without sacrificing expressivity: every projected policy is safe, and projection preserves the approximation power of the chosen architecture over the BCBF-feasible class.

8Scalability and extensions

PS2-RL reduces provably safe RL to rollouts and a control-space projection. The only object that must be certified is the local base pair $(\mathcal B,\pi_{\mathcal B})$, which Theorem 4.1 makes routine. The learned safe-arrival policy is certified implicitly: once frozen, rollouts extend the base set to $\mathcal C_T(\pi_b^\star)$ by construction.

  • Small QPs in high dimension. The layer has $m$ decision variables and $O(Nn_{\mathcal S}+n_{\mathcal B}+2m)$ affine rows, which grows linearly with the backup mesh and the number of constraints. Discretizing the Hamilton–Jacobi PDE instead costs exponentially in $n$.
  • Architecture-agnostic. The layer is appended after any policy network, and Theorem 4.4 preserves universal approximation. Unlike post-hoc network verification, no specific network family is required.
  • Differentiable simulators. The control-affine form is not essential. With a differentiable simulator $F_{\Delta t}$ and the candidate-input rollout $z_0(u)=F_{\Delta t}(x,u)$, $z_{i+1}(u)=F_{\Delta t}(z_i(u),\pi_b^\star(z_i(u)))$, each rollout condition $\ell_i(z_i(u))\ge0$ yields a local affine row $\ell_i(z_i(u_b))+a_i(x)^\top(u-u_b)\ge0$ with $a_i(x)=\nabla_u\ell_i(z_i(u))\big|_{u=u_b}$ and $u_b=\pi_b^\star(x)$, computable by automatic differentiation for only the safety-relevant outputs. These rows are first-order approximations, so conservative margins or a trust region around $u_b$ are advisable. This variant is future work.

9Experimental instantiation

Unicycle lane keeping

$$\begin{bmatrix}\dot y\\ \dot v\\ \dot\psi\end{bmatrix}=\begin{bmatrix}v\sin\psi\\0\\0\end{bmatrix}+\begin{bmatrix}0&0\\1&0\\0&1\end{bmatrix}\begin{bmatrix}a_{\text{cmd}}\\ r_{\text{cmd}}\end{bmatrix},\qquad a_{\text{cmd}}\in[-5,5]\,\mathrm{m/s^2},\ \ r_{\text{cmd}}\in[-1,1]\,\mathrm{rad/s}. \tag{125}$$

$\Delta t=0.05$ s (20 Hz). The safe set $\mathcal S=\{|y|\le1.8,\ |\psi|\le\pi/3\}$ gives four rows: $h_{\mathcal S,1}=y_{\max}+y$, $h_{\mathcal S,2}=y_{\max}-y$, $h_{\mathcal S,3}=\psi_{\max}+\psi$, $h_{\mathcal S,4}=\psi_{\max}-\psi$. The reference $y_{\text{ref}}(t)=2.5\sin(2\pi t/10)$, $v_{\text{ref}}=5$ is intentionally unsafe. The base pair is a discrete-time LQR about $x^\star=[0,5,0]^\top$ with $Q_d=\operatorname{diag}(1,1,1)$, $R_d=\operatorname{diag}(0.01,0.5)$ and $\mathcal B=\{e^\top Pe\le c_{\mathcal B}\}$, where $c_{\mathcal B}=0.3$ lies below the actuator-admissible level $\bar c\approx1.05$. With $T=1$ s and $N=20$, the layer has $4(N+1)+1=85$ BCBF rows, or 90 inequalities with the input box and slack.

Quadrotor powerloop

$$\begin{gathered}\dot{\mathbf p}=\mathbf v,\qquad \dot{\mathbf v}=-g\,\mathbf e_3+R(\mathbf q)\,(a_{\text{cmd}}\mathbf e_3),\qquad \dot{\mathbf q}=\tfrac12\,\Xi(\mathbf q)\,\boldsymbol\omega_{\text{cmd}},\\ x=[\mathbf p^\top,\mathbf v^\top,\mathbf q^\top]^\top\in\mathbb R^{10},\end{gathered}$$

with thrust $a_{\text{cmd}}\in[0,4g]$, body rates $\boldsymbol\omega_{\text{cmd}}\in[-18,18]^3$ rad/s, and $\Delta t=0.02$ s (50 Hz). The safe set is a hard ceiling, $h_{\mathcal S}(x)=z_{\text{ceil}}-p_z\ge0$ with $z_{\text{ceil}}=3$ m. It has relative degree 2 for thrust and higher for body rates. The base pair is a hover LQR on a reduced 7-D error state $x_e=[p_z-z_{\text{des}},v_x,v_y,v_z,2q_{\text{err},x},2q_{\text{err},y},2q_{\text{err},z}]^\top$ with $u^\star=[g,0,0,0]^\top$ and $c_{\mathcal B}=8.0$ (admissible level $\bar c\approx12.38$), placing the ellipsoid strictly below the ceiling. With $T=2$ s and $N=100$, the layer has $1\cdot(N+1)+1=102$ BCBF rows, or 111 inequalities.

UnicycleQuadrotor
Phase I backbone · stepsTD3-style · $3\times10^6$TD3-style · $5\times10^6$
Safe-arrival discount $\beta$ · horizon $T$0.92 · 1.0 s0.99 · 2.0 s
Phase II backbone · stepsSAC + CIL · $10^6$SAC + CIL · $1.5\times10^6$
Class-$\mathcal K_\infty$ gains $(\alpha_{\mathcal S},\alpha_{\mathcal B})$(4.0, 2.0)(4.0, 2.0)
Slack penalty $\lambda_\delta$ · QP solver$10^5$ · qpax$10^6$ · qpax
Warm startnonevanilla powerloop-tracking SAC

The quadrotor warm start follows the HardNet-CVX recipe of first training the nominal network without the projection. Because the layer projects every action during training and deployment, the safety guarantee holds regardless of how $\pi_\phi$ is initialized. Full hyperparameters are in Tables 8–9 of the paper.

References: Y. Chen, M. Jankovic, M. Santillo, A. D. Ames, "Backup control barrier functions: Formulation and comparative study," CDC 2021. T. Gurriet et al., "A scalable safety critical control framework for nonlinear systems," IEEE Access 2020. Y. Min, N. Azizan, "HardNet: Hard-constrained neural networks with universal approximation guarantees," 2025. K. Tracy, Z. Manchester, "On the differentiability of the primal-dual interior-point method," 2024.