Home

Awesome

<div align="center"> <h1> Bullet-Safety-Gym </h1> </div> <div align="center">

<a>Python 3.8+</a> <a href="https://pypi.org/project/bullet-safety-gym">PyPI</a> Downloads <a href="https://github.com/liuzuxin/Bullet-Safety-Gym/blob/master/LICENSE">License</a>

</div>

:warning: Notes: This repo requires gymnasium>=0.26.3 API version due to the major changes in the reset and step functions. Check this release note for details. For gym>=0.26 version, please use the gym-v26 branch. For the old API (gym<0.26) version, please use the old_api branch which requires gym==0.23.1.

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

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

You may simple install the latest version by running:

pip install bullet-safety-gym

Alternatively, here are the (few) steps to follow to install this repository manually.

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

cd Bullet-Safety-Gym

pip install -e .

Supported Systems

We currently support Linux and OS X running Python 3.8 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 gymnasium as gym
>>> import bullet_safety_gym
>>> env = gym.make('SafetyCarCircle-v0')

The functional interface follows the API of the OpenAI Gym that is or greater than the 0.26.0 version. There are major changes of the reset and step functions. Check this release note for details. For the old API version, please use the old branch which requires gym==0.20.0.

>>> observation, info = env.reset()
>>> random_action = env.action_space.sample()  # usually the action is determined by a policy
>>> next_observation, reward, terminated, truncated, 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 gymnasium as gym
import bullet_safety_gym

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

while True:
    done = False
    env.render()  # make GUI of PyBullet appear
    o, info = env.reset()
    while not done:
        random_action = env.action_space.sample()
        o, reward, terminated, truncated, 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