Home

Awesome

Status: Archive (code is provided as-is). For actively maintained safe RL repos, please see: <a href="https://github.com/PKU-Alignment/safety-gymnasium">Safety Gymnasium</a> and <a href="https://github.com/utiasDSL/safe-control-gym">Safe Control Gym</a>

Bullet-Safety-Gym

<p align="center"> • <a href="https://github.com/SvenGronauer/Bullet-Safety-Gym#technical-report-and-benchmark-results">Technical Report</a> • <a href="https://github.com/SvenGronauer/Bullet-Safety-Gym#installation">Installation</a> • <a href="https://github.com/SvenGronauer/Bullet-Safety-Gym#getting-started">Getting Started</a> • </p>

"Bullet-Safety-Gym" is a free and open-source framework to benchmark and assess safety specifications in Reinforcement Learning (RL) problems.

Technical Report and Benchmark Results

Baseline results and comparisons can be found in the technical report (PDF)

If you like this repo, please use the following citation:

<pre> @techreport{Gronauer2022BulletSafetyGym, author = {Gronauer, Sven}, institution = {mediaTUM}, title = {Bullet-Safety-Gym: A Framework for Constrained Reinforcement Learning}, year = {2022}, doi = {10.14459/2022md1639974}, bdsk-url-1 = {https://mediatum.ub.tum.de/1639974}} </pre>

Yet another Gym?

Benchmarks are inevitable in order to assess the scientific progress. In recent years, a plethora of benchmarks frameworks has emerged but we felt that the following points have not been sufficiently answered yet:

Implemented Agents

Bullet-Safety-Gym is shipped with the following four agents:

BallCarDroneAnt
BallCar AgentDrone AgentAnt Agent

Tasks

CircleGatherReachRun
CircleGatherReachRun

Installation

Here are the (few) steps to follow to get our repository ready to run.

Clone the repository and install the Bullet-Safety-Gym package via pip. Use the following three lines:

git clone https://github.com/SvenGronauer/Bullet-Safety-Gym.git

cd Bullet-Safety-Gym

pip install -e .

Supported Systems

We currently support Linux and OS X running Python 3.5 or greater. Windows should also work (but has not been tested yet).

Note: This package has been tested on Mac OS Mojave and Ubuntu (18.04 LTS, 20.04 LTS), and is probably fine for most recent Mac and Linux operating systems.

Dependencies

Bullet-Safety-Gym heavily depends on two packages:

Getting Started

After the successful installation of the repository, the Bullet-Safety-Gym environments can be simply instantiated via gym.make. See:

>>> import gym
>>> import bullet_safety_gym
>>> env = gym.make('SafetyCarGather-v0')

The functional interface follows the API of the OpenAI Gym (Brockman et al., 2016) that consists of the three following important functions:

>>> observation = env.reset()
>>> random_action = env.action_space.sample()  # usually the action is determined by a policy
>>> next_observation, reward, done, info = env.step(random_action)

Besides the reward signal, our environments provide an additional cost signal, which is contained in the info dictionary:

>>> info
{'cost': 1.0}

A minimal code for visualizing a uniformly random policy in a GUI, can be seen in:

import gym
import bullet_safety_gym

env = gym.make('SafetyAntCircle-v0')

while True:
    done = False
    env.render()  # make GUI of PyBullet appear
    x = env.reset()
    while not done:
        random_action = env.action_space.sample()
        x, reward, done, info = env.step(random_action)

Note that only calling the render function before the reset function triggers visuals.

List of environments

The environments are named in the following scheme: Safety{#agent}{#task}-v0 where the agent can be any of {Ball, Car, Drone, Ant} and the task can be of {Circle, Gather, Reach, Run,}.

There exists also a function which returns all available environments of the Bullet-Safety-Gym:

from bullet_safety_gym import get_bullet_safety_gym_env_list

env_list = get_bullet_safety_gym_env_list()

Reach Environments

Circle Run Environments

Run Environments

Gather Environments

References