---
title: 'Uppaal Coshy: Automated Safety Shield Synthesis'
url: https://www.emergentmind.com/topics/uppaal-coshy
type: topic
---

# Uppaal Coshy: Automated Safety Shield Synthesis

Uppaal Coshy is a tool for automatic synthesis of a safety strategy, or shield, for Markov decision processes over continuous state spaces and complex hybrid dynamics. Its general methodology is to partition the state space and then solve a two-player safety game, while approximating hard-to-obtain solutions using simulations. The implementation is fully automatic and supports the expressive formalism of Uppaal models, which encompass stochastic hybrid automata. A central feature is an algorithm called Caap, which computes a compact representation of a shield in the form of a decision tree and yields significant reductions [2508.16345].

## 1. Problem setting and synthesis objective

The setting is a possibly stochastic hybrid system modeled as a Euclidean Markov decision process (EMDP) whose state space \(S \subseteq \mathbb{R}^k\) is conceptually infinite [2508.16345]. Given a safety invariant \(\varphi \subseteq S\), the goal is to automatically synthesize a nondeterministic shield \(\sigma\) that maps each state \(s\) to a set of safe control actions, so that under \(\sigma\) all executions remain in \(\varphi\).

The paper defines the target artifact as a nondeterministic “shield” or safety strategy rather than a single prescribed controller. This distinction is technically important: the shield restricts actions to those that are safe, but it does not necessarily determine one unique action in each state. Applications include enforcing safety at run-time while leaving freedom for optimization or learning within the shielded system. This suggests a separation between a safety envelope and whatever optimization or learning mechanism operates inside that envelope.

A common misunderstanding would be to treat the synthesis problem as a purely finite-state task. The paper instead starts from continuous state spaces and complex hybrid dynamics, and only then introduces a finite abstraction through partitioning. Another misconception would be to assume that exact hybrid reachability is computed throughout; the paper explicitly states that exact computation is undecidable or infeasible for general nonlinear or stochastic hybrid dynamics.

## 2. Formal model: EMDPs, partitions, and the safety game

An EMDP is defined as a tuple \(\mathcal{M} = (S, A, T)\), where \(S \subseteq \mathbb{R}^k\) is closed and bounded, \(A\) is a finite set of actions, and \(T \colon S \times A \to (S \to \mathbb{R}_{\ge 0})\) maps \((s,a)\) to a probability density \(T(s,a)(\cdot)\) on \(S\) [2508.16345]. A run is an infinite sequence
\[
s_0 a_0 s_1 a_1 \dots
\]
with \(T(s_i, a_i)(s_{i+1}) > 0\). A nondeterministic strategy is \(\sigma \colon S \to 2^A\); a run is safe if \(a_i \in \sigma(s_i)\) and \(s_i \in \varphi\).

The abstraction step partitions \(S\) into finitely many rectangular cells \(\mathcal{C}\). This induces a labeled transition system by
\[
(C,a,C') \in \xrightarrow{} \quad\iff\quad \exists\, s \in C,\ s' \in C' : T(s,a)(s') > 0.
\tag{1}
\]
The zero-step safe cells are
\[
C^0 = \{\, C \mid C \subseteq \varphi \,\}.
\]
The greatest-fixed-point characterization of the safe region is
\[
\mathit{SafeCells}
\;=\;
\bigl\{\, C \in \mathcal{C}^0 \;\bigm|\; \exists a \in A.\; \forall C'.\, C \xrightarrow{a} C' \implies C' \in \mathit{SafeCells} \bigr\}.
\tag{2}
\]
The corresponding most-permissive shield on cells is
\[
\sigma^*(C) = \{\, a \mid \forall C'.\, C \xrightarrow{a} C' \implies C' \in \mathit{SafeCells} \,\}.
\]

By mapping each continuous state \(s\) to its cell \([s]\), the construction yields a shield for the original EMDP; the paper attributes this statement to Theorem 2.1. Once \(\mathcal{C}\) is computed, the safety game is solved via fixed point (2) in time polynomial in \(|\mathcal{C}|\) and \(|A|\). The abstraction therefore relocates the main difficulty from game solving to the construction of a sufficiently informative finite transition relation.

## 3. Partition-based abstraction and simulation-driven approximation

The partition is a regular rectangular grid over \(S\), parameterized by a granularity vector \(\gamma \in \mathbb{R}^k_{>0}\) and an offset \(\beta \in \mathbb{R}^k\). Each cell is
\[
C = \bigtimes_{i=1}^k
\bigl[\beta_i + p_i \gamma_i,\; \beta_i + (p_i+1)\gamma_i\bigr)
\qquad (p \in \mathbb{N}^k).
\]
Finer \(\gamma\) yields more cells and, in principle, a more precise abstraction, but at higher computational cost [2508.16345].

The principal algorithmic obstacle is that exact computation of the transition relation in (1) is undecidable or infeasible for general nonlinear or stochastic hybrid dynamics. Uppaal Coshy addresses this by systematic sampling and simulation. Within each cell \(C\), it systematically samples \(n^k\) points on an \(n\)-grid, where \(n\) is a user parameter. For each sample \(s\) and action \(a\), it applies \(a\) and invokes the Uppaal simulator to run until the next controller decision point; this yields a successor sample \(s''\), and hence a successor cell \([s'']\). Each sample–action pair is repeated \(m\) times, where \(m\) is another user parameter, to cover stochastic outcomes.

The union of discovered transitions underapproximates the ideal transition relation. Cells whose samples never violate \(\varphi\) are taken as initial safe cells. Empirically, increasing \(n\) and \(m\) improves precision; final safety can be checked by Uppaal’s statistical model checking. The paper’s general philosophy is therefore not to solve hybrid reachability exactly, but to approximate it through simulator-driven evidence. A plausible implication is that synthesis quality depends materially on the informativeness of the sampling regime and on the model’s stochastic structure.

## 4. Caap and compact shield representation

A direct shield stores \(\sigma^*(C)\) for each cell, and the paper notes that this can involve millions of cells [2508.16345]. Since many adjacent cells allow the same action set, Uppaal Coshy introduces Caap to compute a coarser, axis-aligned partition and thereby obtain a compact representation.

The compact representation is defined through a decision tree whose internal predicates have the form \(s_i < c\), with sorted cut-points \(M_{i,1} < M_{i,2} < \dots\) per dimension \(i\). A region is represented by index bounds \((p^{\min}, p^{\max}) \in \mathbb{N}^k \times \mathbb{N}^k\), corresponding to a hyperrectangle in \(\mathbb{R}^k\).

A candidate expansion \(R'\) of a region is legal only if three rules hold:

1. Uniformity: all cells in \(R'\) share the same \(\sigma^*(\cdot)\).
2. Non-overlap: \(R'\) does not intersect already fixed regions.
3. Non-splitting: for any original region \(R\), \(R \setminus R'\) is either empty or a single rectangle.

The greedy expansion procedure initializes \(\Delta_p = p^{\max} - p^{\min}\) and iteratively tries to increase \(\Delta_{p,i}\) in each dimension \(i\). If Rule 1 or 2 fails, the algorithm reverts and marks \(i\) exhausted. If Rule 3 fails, it attempts a one-dimensional “repair” by more aggressive expansion; if impossible, it reverts and exhausts \(i\). When all dimensions are exhausted, it records the maximal region and repeats until the whole space is covered.

The resulting regions are then converted back into a much smaller decision tree through a heuristic splitting procedure that balances number of cut regions and region counts while ensuring functional equivalence. Repeated Caap\(\to\)tree cycles often yield further minor reductions. The compactness result is thus not merely a storage optimization; it is a structural post-processing step that preserves the shield while changing its representation.

## 5. Tool workflow and implementation in Uppaal

The workflow begins by modeling the hybrid system in Uppaal using piecewise ODEs, discrete modes, and synchronizations [2508.16345]. Shield synthesis is then initiated by a query of the form:

```text
strategy shield = acontrol: A[] !ErrorLocation
{ var₁[low₁,high₁]:N₁, …, varₖ[…], DiscreteLoc }
```

Uppaal Coshy then automatically performs three synthesis stages: it builds the grid \(\mathcal{C}\), samples and simulates to approximate transitions, and solves the finite safety game to compute \(\sigma^*\). The raw shield can optionally be saved per cell to JSON. Caap can then be run on the saved shield JSON to obtain a compact decision tree, which can be loaded back in Uppaal. The compact shield can be used in reinforcement-learning or strategy-improvement queries via Uppaal Stratego.

Several implementation details are emphasized. Unbounded state spaces are handled by a special “out-of-bounds” cell; the user can choose to treat it as always safe, always unsafe, or decide automatically by sampling. Dimensions irrelevant to safety, including clocks, cost variables, and always-fixed discrete locations, may be omitted; their values are fixed to the initial state during sampling. The simulator is used both for nondeterministic hybrid flows and stochastic draws, which frees the implementation from re-implementing arbitrary C calls or complex distributions. All steps are fully automated from the Uppaal GUI, with no manual model changes needed except optional state-space transformations.

This implementation profile suggests that the tool is designed to exploit the simulator as a unifying interface for both dynamics and randomness, rather than to encode bespoke symbolic procedures for each model class.

## 6. Experimental findings, limitations, and extensions

The evaluation uses four benchmarks: the bouncing ball, boost converter, random walk, and water tank [2508.16345]. The reported synthesis and Caap metrics are as follows.

| Benchmark | Configuration and synthesis | Caap result |
|---|---|---|
| Bouncing Ball | \(n=3, m=1\); synthesis 218 s; raw cells 1 430 000 | 53 s; 2 972 regions |
| Boost Converter | \(n=3, m=20\); synthesis 1 430 s; raw cells 136 800 | 21 s; 571 regions |
| Random Walk | \(n=4, m=20\); synthesis 82 s; raw cells 40 000 | 1.5 s; 60 regions |
| Water Tank | \(n=3, m=1\); synthesis 0.1 s; raw cells 168 | 0.1 s; 24 regions |

All synthesized shields were confirmed via 10 000 SMC runs at 99% confidence to violate safety in fewer than 0.03% of trials, and in practice zero. The paper also states that state-space transformations, for example using mechanical energy for the ball, can reduce raw grid size by orders of magnitude.

The limitations are explicit. Reachability is underapproximated, so corner cases may be missed unless \(n\) and \(m\) are large; statistical checking is recommended post-synthesis. Randomness in Uppaal is not systematically sampled, and future work may detect and sample over discrete distributions. Caap is currently a separate post-processing step, and tighter integration into Uppaal would simplify usability. Improved visualizations, including why a state is unsafe, and debug support could aid modelers. Proposed extensions include cost-aware shields through multi-objective synthesis and on-the-fly shield refinement during learning.

Taken together, these results position Uppaal Coshy as a partition-based, simulation-driven framework for automatic safety synthesis in stochastic and hybrid models, with Caap serving as the mechanism that converts large per-cell shields into compact deployable decision trees.

Source: https://www.emergentmind.com/topics/uppaal-coshy