{
 "artifacts": [
  {
   "name": "bench_report.json",
   "url": "https://synthcore.org/code/1094/bench_report.json"
  },
  {
   "name": "report.md",
   "url": "https://synthcore.org/code/1094/report.md"
  },
  {
   "name": "report_bench_2026-09-02T015040.md",
   "url": "https://synthcore.org/code/1094/report_bench_2026-09-02T015040.md"
  },
  {
   "name": "results.json",
   "url": "https://synthcore.org/code/1094/results.json"
  },
  {
   "name": "sos_backup_shield.py",
   "url": "https://synthcore.org/code/1094/sos_backup_shield.py"
  },
  {
   "name": "sos_shield_bench.py",
   "url": "https://synthcore.org/code/1094/sos_shield_bench.py"
  }
 ],
 "category": "dynamics",
 "description": "Wrap a neural policy with a backup controller synthesized by finite-horizon SOS backward reachability. The neural policy is used whenever it remains inside the certified feasible region; otherwise, a time-indexed backup controller drives the state into a terminal-safe set while respecting actuator limits.",
 "download_zip": "https://synthcore.org/download/1094",
 "formulas_latex": [
  "$$\\dot{x}=f(x)+g(x)u,\\qquad \\mathcal{B}_t=\\{x\\in\\mathcal{X}:V(t,x)\\leq1\\},$$",
  "$$\\frac{d}{dt}V(t,x(t))=\\partial_tV(t,x)+\\nabla_xV(t,x)^\\top\\left[f(x)+g(x)k_b(t,x)\\right]\\leq0\\quad\\text{for }x\\in\\mathcal{B}_t,$$",
  "$$\\mathcal{B}_T\\subseteq\\mathcal{S}_{\\mathrm{term}},\\qquad -\\dot V(t,x)=\\sigma_0(t,x)+\\sum_{i=1}^{r}\\sigma_i(t,x)q_i(x),\\quad \\sigma_i\\in\\Sigma[x,t],$$",
  "$$u(x)=\\begin{cases}\\pi_\\theta(x),\u0026\\displaystyle\\max_{u\\in\\mathcal{U}}\\nabla h(x)^\\top[f(x)+g(x)u]+\\alpha(h(x))\\geq0,\\\\ k_b(\\tau(x),x),\u0026\\text{otherwise},\\end{cases}$$"
 ],
 "id": 2779,
 "implementation": "1. Exact integration point: place the shield after the neural policy forward pass in a continuous-control RL agent, learned robot controller, or neural world-model rollout. Let $x$ be the state, $\\pi_\\theta(x)$ the nominal action, and $h(x)\\geq0$ a known instantaneous safety function. Fit polynomial approximations $\\hat f,\\hat g$ to the dynamics on a compact operating box, or use a polynomial simulator. Choose a terminal safe set $\\mathcal{S}_{\\mathrm{term}}$ with a simple certified controller and solve an offline SOS program for polynomial $V(t,x)$ and polynomial backup feedback $k_b(t,x)$ over horizon $T$. 2. Pseudocode: at each step compute $u_\\pi=\\pi_\\theta(x)$ and the margin $m=\\nabla h(x)^\\top[\\hat f(x)+\\hat g(x)u_\\pi]+\\alpha(h(x))$. If $m\\geq0$ and $V(0,x)\\leq1$, execute $u_\\pi$; otherwise compute remaining backup time $\\tau$ and execute the saturated $k_b(\\tau,x)$. During SOS synthesis enforce $-\\partial_tV-\\nabla V^\\top(\\hat f+\\hat gk_b)\\geq0$, input-polytope constraints, and terminal inclusion through SOS multipliers. 3. Computed from the paper: the certificate, backup controller, and certified sublevel geometry. Estimated empirically: dynamics approximation error, actual derivative of $V$, barrier margin, certificate violations under the true simulator, and certified-set volume. Add a robustness margin $\\varepsilon$ by requiring the derivative to be at most $-\\varepsilon\\|x\\|^2$ when model error is bounded. 4. First cheap experiment: use a 2-D Dubins car or torque-limited pendulum and compare PPO or SAC with no shield, a hand-designed backup controller, and the SOS shield. Train policies identically and test 1,000 random initial states near the safety boundary. The falsifiable prediction is that every rollout initialized inside the certified $\\mathcal{B}_0$ remains safe and reaches $\\mathcal{S}_{\\mathrm{term}}$ under backup control, subject to the measured model-error margin. Outside $\\mathcal{B}_0$, failure probability should rise sharply. The main quantitative signature is a certified-set volume larger than the original terminal backup set, empirical safety violations below the robustness tolerance, and a switch boundary matching the predicted contour $V(0,x)=1$ within 10-20%.",
 "math_summary": "Assume a polynomial or locally polynomial control-affine plant $\\dot{x}=f(x)+g(x)u$, state domain $\\mathcal{X}$, and polytope input set $\\mathcal{U}$. Let $V(t,x)$ be a polynomial certificate and define the time-dependent sublevel sets $\\mathcal{B}_t=\\{x:V(t,x)\\leq1\\}$. A backup feedback $k_b(t,x)$ must satisfy $k_b(t,x)\\in\\mathcal{U}$ and $\\partial_tV+\\nabla_xV^\\top[f(x)+g(x)k_b(t,x)]\\leq0$ on $\\mathcal{B}_t$, so trajectories starting in $\\mathcal{B}_0$ remain in the evolving tube. The terminal condition $\\mathcal{B}_T\\subseteq\\mathcal{S}_{\\mathrm{term}}$ guarantees arrival in a pre-certified safe set. Each nonnegativity condition is imposed over a semialgebraic domain using SOS multipliers, for example $-\\dot V=\\sigma_0+\\sum_i\\sigma_iq_i$ where $q_i(x)\\geq0$ define the domain and $\\sigma_i$ are sum-of-squares polynomials. A learned policy $\\pi_\\theta(x)$ is accepted only when a barrier feasibility margin is nonnegative; otherwise the controller switches to $k_b$.",
 "math_tags": [
  "control-theory",
  "dynamical-systems",
  "optimization"
 ],
 "ml_areas": [
  "rl",
  "world-model",
  "training-dynamics"
 ],
 "paper": {
  "arxiv_id": "2608.27916",
  "arxiv_url": "https://arxiv.org/abs/2608.27916",
  "summary_what_math_gives_to_ml": "The paper provides a constructive finite-horizon SOS backward-reachability mechanism for synthesizing a larger backup set and backup controller, rather than prescribing them manually. Its transferable asset is a polynomial certificate: a time-dependent sublevel set is made invariant under a feasible controller and is constrained to enter an already certified terminal-safe set at the horizon. In neural systems, this can become a runtime safety shield for a learned policy or a certified reachable region for a neural ODE or world model, with the SOS certificate determining exactly when the nominal network must yield to a backup controller.",
  "title": "Backup Control Barrier Function Synthesis using Sum-of-Squares Reachability",
  "year": "2026"
 },
 "ratings": {
  "difficulty": 7,
  "novelty": 7,
  "usefulness": 7
 },
 "solves": [
  "stability",
  "accuracy",
  "generalization"
 ],
 "title": "SOS Backup Shield for Learned Policies",
 "url": "https://synthcore.org/idea/2779/sos-backup-shield-for-learned-policies",
 "verification": {
  "benchmark": {
   "track": "robust_cbf_pendulum_policy",
   "model": "local_mlp_tiny",
   "n_seeds": 8,
   "metric_direction": "lower is better",
   "comparison": {
    "baseline_mean": 0.0019978795608039945,
    "idea_mean": 0.05749530019238591,
    "delta_mean": 0.05549742063158192,
    "per_seed_diffs": [
     0.06062707200180739,
     0.06630686286371201,
     0.04712441214360297,
     0.05151062528602779,
     0.039590626023709774,
     0.06266988487914205,
     0.05227660946547985,
     0.06387327238917351
    ],
    "idea_wins": 0,
    "n_pairs": 8,
    "p_value": 0.0081,
    "mde": 0.007832081629823283,
    "mde_rel_pct": 392.0197084688862,
    "verdict": "idea worse (significant)",
    "system_worked": false
   },
   "baseline": {
    "best_cfg": {
     "epochs": 15,
     "eps": 0,
     "lr": 0.006
    },
    "sweep": [
     {
      "cfg": {
       "epochs": 15,
       "eps": 0,
       "lr": 0.001
      },
      "mean": 0.021794200874865055
     },
     {
      "cfg": {
       "epochs": 15,
       "eps": 0,
       "lr": 0.003
      },
      "mean": 0.002334954886464402
     },
     {
      "cfg": {
       "epochs": 15,
       "eps": 0,
       "lr": 0.006
      },
      "mean": 0.0018331437022425234
     }
    ],
    "full": {
     "mean": 0.0019978795608039945,
     "std": 0.0005495084055684182,
     "per_seed": [
      0.0015628907131031156,
      0.0015461408765986562,
      0.0021467802580446005,
      0.0020767629612237215,
      0.0030877823010087013,
      0.0011752876453101635,
      0.0020312685519456863,
      0.0023561231791973114
     ],
     "n": 8
    }
   },
   "idea": {
    "mean": 0.05749530019238591,
    "std": 0.00835564815799482,
    "per_seed": [
     0.06218996271491051,
     0.06785300374031067,
     0.04927119240164757,
     0.05358738824725151,
     0.042678408324718475,
     0.06384517252445221,
     0.05430787801742554,
     0.06622939556837082
    ],
    "n": 8
   },
   "mechanism_signature": {
    "confirmed": true,
    "observed_from_trained_models": {
     "feasible_fraction_mean": 1,
     "lower_shift_mean": 1,
     "margin_slope_mean": -2,
     "mean_intervention": 1.705237858260225,
     "n_models": 8
    },
    "prediction": {
     "lower_bound_shift_per_epsilon": 1,
     "margin_slope": -2
    }
   },
   "custom_track": {
    "domain": "dynamics",
    "file": "robust_cbf_bench.py",
    "name": "robust_cbf_pendulum_policy"
   }
  },
  "mechanism_confirmed": true,
  "peer_reviewed": false,
  "practical_verdict": "harms",
  "stage1_mechanism_check": {
   "worked": true,
   "confidence": 8,
   "verdict": "Built a finite-horizon backup shield prototype for a torque-limited double integrator using an explicit quadratic Lyapunov/SOS-style certificate and saturated PD backup controller. The mechanism manifested: the dissipation identity error was 1.1e-16, observed decay bound 0.759653 versus predicted 0.759653, certificate area scaled exactly as terminal_radius^2 (ratios 0.25, 1, 4, 9), and reachable volume increased monotonically with horizon. All 500 sampled states inside the certificate remained safe and reached the terminal set; on a broader near-boundary learned-policy test, violations fell from 96.2% baseline to 22.8% with shielding, though the shield is not universally safe outside its certified region.",
   "metrics": {
    "baseline": "Near-boundary nominal policy: violation rate 0.962; mean violation 14.9417",
    "idea": "Near-boundary shielded policy: violation rate 0.228; mean violation 0.08638; mean switches 628.568. Certified-set audit: 500/500 safe and 500/500 terminal. Dissipation observed/predicted: 0.759653/0.759653. Certificate-area ratios for terminal radii 0.03/0.06/0.12/0.18: 0.25/1/4/9, exactly predicted."
   },
   "how_to_run": "python3 sos_backup_shield.py",
   "files": [
    "sos_backup_shield.py",
    "results.json",
    "results.txt"
   ],
   "limitations": "This is an analytic quadratic certificate toy, not a full numerical SOS synthesis or neural RL training experiment. The shield comparison uses a fixed noisy proxy policy, simplified barrier logic, nominal exact dynamics, and sampled initial states; model uncertainty, disturbances, high-dimensional plants, PPO/SAC training, and formal terminal-set certification were not tested."
  },
  "status": "mech_ok_no_baseline",
  "status_label": "Mechanism confirmed, baseline not beaten",
  "updated_at": "2026-09-02T01:50:40",
  "verdict_source": "deterministic test code (paired-seed permutation statistics)"
 }
}
