Skip to main content

Gymnasium environments for UPPAAL hybrid-system benchmark models

Project description

uppaal-gym

Gymnasium environments for classic UPPAAL hybrid-system benchmark models. Designed for research at the intersection of reinforcement learning and formal methods.

Installation

pip install uppaal-gym

Or from source:

git clone https://github.com/andreashhpetersen/uppaal-gym
cd uppaal-gym
pip install -e .

Environments

All environments follow the standard Gymnasium API and are registered automatically on import uppaal_gym.

ID Observation Actions Termination
BouncingBall-v0 position, velocity (2D continuous) 0: do nothing, 1: hit ball Ball stops (low position and velocity)
CruiseControl-v0 ego velocity, front velocity, distance (3D continuous) 0: decelerate, 1: accelerate, 2: neutral Collision (distance ≤ 0)
DCDCBoostConverter-v0 inductor current, capacitor voltage, resistance (3D continuous) 0: switch off, 1: switch on Safety constraint violated
OilPump-v0 cycle time, oil volume, pump status, latency (4D continuous) 0: pump off, 1: pump on Oil volume outside [4.9, 25.1]
RandomWalk-v0 position, time (2D continuous) 0: slow, 1: fast Goal reached (x ≥ 1) or timeout (t ≥ 1)
Spiral-v0 agent position, destination position (4D continuous) 0: move outward, 1: move inward, 2: stay course Rock collision or destination reached

PasswordGuessing-v0 is also registered but requires words and options arguments — instantiate it directly via PasswordEnv(words, options).

Environment details

BouncingBall-v0 — A ball bounces under gravity. The agent can hit the ball to add velocity. The episode ends when the ball loses enough energy to stop. The agent is penalised for hitting (-1) and heavily for termination (-1000).

CruiseControl-v0 — An ego vehicle follows a front vehicle with stochastic acceleration. The agent controls ego acceleration to maintain a safe following distance. Reward is -distance each step; collision gives -10000.

DCDCBoostConverter-v0 — A DC-DC boost converter must keep inductor current x1 ∈ [0, 4] A and capacitor voltage x2 ∈ [14.5, 15.5] V despite a randomly fluctuating load resistance. Reward is negative distance from target values (x1_ref=0.35, x2_ref=15).

OilPump-v0 — An oil pump refills a tank consumed at varying rates over a 20-second cycle. The pump has a 2-second switching latency. The agent must keep oil volume within [4.9, 25.1].

RandomWalk-v0 — A 2D random walk where the agent must reach x = 1 before t = 1. Fast moves cost more (-3) but advance position more; slow moves cost less (-1). Timeout incurs an extra penalty of -20.

Spiral-v0 — An agent moves on a spiral trajectory in 2D space and must reach a randomly generated destination while avoiding five fixed obstacles (rocks). Actions adjust the radius of the spiral.

Usage

import gymnasium as gym
import uppaal_gym  # registers all environments

env = gym.make("BouncingBall-v0")
obs, info = env.reset(seed=42)

for _ in range(200):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        obs, info = env.reset()

env.close()

All environments expose two additional methods beyond the standard Gymnasium API:

# Check which actions are safe in a given state
safe_actions = env.allowed_actions(obs)

# Compute a transition without updating internal state (useful for planning)
next_state, reward, terminated = env.step_from(obs, action)

UPPAAL Models

The original UPPAAL model files (.xml) for each environment are included in the models/ directory. UPPAAL is available at uppaal.org.

Deviations from the original models

The gym environments are faithful adaptations but include deliberate deviations where necessary for use as RL benchmarks.

BouncingBall-v0 — The initial position range is [8, 10) rather than the original [7, 10). States in [7, 8) cannot be guaranteed safe even under a perfect strategy, so they are excluded to ensure the task is feasible.

CruiseControl-v0 — Two differences: (1) the sensor range is doubled from 100 to 200 to give the agent more time to react when the front car reappears; (2) the minimum velocity of the front car is −8 instead of −10, matching the observation space used in experiments.

DCDCBoostConverter-v0 — Several differences: (1) x1 and x2 are initialised at their target values (0.35 A, 15 V) rather than 0, since starting at 0 immediately violates the safety constraints; (2) the load resistance R is initialised at 73 Ω and may vary over [30, 200] Ω with fluctuations of ±30 per step, compared to [60, 80] Ω and ±10 in the original — this substantially increases task difficulty; (3) the safety region is widened to x1 ∈ [0, 4], x2 ∈ [14.5, 15.5] from the tighter query targets x1 ∈ [0, 0.7], x2 ∈ [14.8, 15.2] used in the original model.

OilPump-v0 — The consumption schedule, fluctuation range, inflow rate, latency, and time step all match the original exactly. The only deviation is in the termination condition: in the original model, a safety violation resets the oil volume to 10 and increments a death counter so the run continues; in the gym, a violation terminates the episode.

RandomWalk-v0 — No significant deviations. The UPPAAL model has been updated to use the same step sizes (Δd: 0.17 fast, 0.10 slow; Δt: 0.05 fast, 0.12 slow) and noise magnitude (±0.04) as the gym implementation. Action indices also match: 0 = slow, 1 = fast.

Citation

If you use uppaal-gym in your research, please cite:

@software{hoeeg-petersen_uppaal_gym_2026,
  author    = {Høeg-Petersen, Andreas Holck},
  title     = {uppaal-gym: Gymnasium Environments for UPPAAL Hybrid-System Benchmarks},
  year      = {2026},
  url       = {https://github.com/andreashhpetersen/uppaal-gym},
  version   = {1.0.0},
}

A Zenodo DOI will be added here after the first tagged release. To register: go to zenodo.org, sign in with GitHub, enable the repository, then create a GitHub release tagged v1.0.0. Zenodo mints a DOI automatically and the BibTeX above will update with it.

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uppaal_gym-1.0.0.tar.gz (48.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uppaal_gym-1.0.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file uppaal_gym-1.0.0.tar.gz.

File metadata

  • Download URL: uppaal_gym-1.0.0.tar.gz
  • Upload date:
  • Size: 48.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for uppaal_gym-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4327c005883f26aa65927473b00869c2ce17b7c8948816eafd4520996a350836
MD5 7ddb4453cfb19ab2dfda2f69f96195ea
BLAKE2b-256 99082a88df21d8b1219d11048004ce31e29406aef26ad2c3546dbc6141471fda

See more details on using hashes here.

Provenance

The following attestation bundles were made for uppaal_gym-1.0.0.tar.gz:

Publisher: publish.yml on andreashhpetersen/uppaal-gym

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file uppaal_gym-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: uppaal_gym-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for uppaal_gym-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fab87f6e52dea03045a39741515536566474cd43af395ebe5ec932772489e709
MD5 2ce081e66e39344b60f597c656a5840e
BLAKE2b-256 fdde2dbce68d6f99b20af707cd59222bb437dd55c41cdd603e360b56d6c91fd6

See more details on using hashes here.

Provenance

The following attestation bundles were made for uppaal_gym-1.0.0-py3-none-any.whl:

Publisher: publish.yml on andreashhpetersen/uppaal-gym

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page