Add new environments

Please follow the steps provided in the gymnasium documentation when creating a new environment. After you create your environment, you can use the stable-gym/stable_gym/__init__.py file to register them to the stable_gym package.

stable_gym/stable_gym/envs/__init__.py

  1"""Entry_point that register the Stable Gym gymnasium environments."""
  2
  3import gymnasium as gym
  4from gymnasium.envs.registration import register
  5
  6from stable_gym.common.max_episode_steps_injection_wrapper import (
  7    MaxEpisodeStepsInjectionWrapper,
  8)
  9
 10# Make entry_point version available.
 11from .version import __version__, __version_tuple__
 12
 13# Available environments.
 14# TODO: Update reward thresholds.
 15ENVS = {
 16    "Oscillator-v1": {
 17        "entry_point": "stable_gym.envs.biological.oscillator.oscillator:Oscillator",
 18        "reward_threshold": 300,
 19        "max_episode_steps": 400,
 20    },
 21    "OscillatorComplicated-v1": {
 22        "entry_point": "stable_gym.envs.biological.oscillator_complicated.oscillator_complicated:OscillatorComplicated",
 23        "reward_threshold": 300,
 24        "max_episode_steps": 400,
 25    },
 26    "CartPoleCost-v1": {
 27        "entry_point": "stable_gym.envs.classic_control.cartpole_cost.cartpole_cost:CartPoleCost",
 28        "reward_threshold": 300,
 29        "max_episode_steps": 250,
 30    },
 31    "CartPoleTrackingCost-v1": {
 32        "entry_point": "stable_gym.envs.classic_control.cartpole_tracking_cost.cartpole_tracking_cost:CartPoleTrackingCost",
 33        "reward_threshold": 300,
 34        "max_episode_steps": 250,
 35    },
 36    "Ex3EKF-v1": {
 37        "entry_point": "stable_gym.envs.classic_control.ex3_ekf.ex3_ekf:Ex3EKF",
 38        "reward_threshold": 300,
 39        "max_episode_steps": 400,
 40    },
 41    "AntCost-v1": {
 42        "entry_point": "stable_gym.envs.mujoco.ant_cost.ant_cost:AntCost",
 43        "reward_threshold": 300,
 44        "max_episode_steps": 250,
 45    },
 46    "HalfCheetahCost-v1": {
 47        "entry_point": "stable_gym.envs.mujoco.half_cheetah_cost.half_cheetah_cost:HalfCheetahCost",
 48        "reward_threshold": 300,
 49        "max_episode_steps": 200,
 50    },
 51    "HopperCost-v1": {
 52        "entry_point": "stable_gym.envs.mujoco.hopper_cost.hopper_cost:HopperCost",
 53        "reward_threshold": 300,
 54        "max_episode_steps": 250,
 55    },
 56    "HumanoidCost-v1": {
 57        "entry_point": "stable_gym.envs.mujoco.humanoid_cost.humanoid_cost:HumanoidCost",
 58        "reward_threshold": 300,
 59        "max_episode_steps": 250,
 60    },
 61    "SwimmerCost-v1": {
 62        "entry_point": "stable_gym.envs.mujoco.swimmer_cost.swimmer_cost:SwimmerCost",
 63        "reward_threshold": 300,
 64        "max_episode_steps": 250,
 65    },
 66    "Walker2dCost-v1": {
 67        "entry_point": "stable_gym.envs.mujoco.walker2d_cost.walker2d_cost:Walker2dCost",
 68        "reward_threshold": 300,
 69        "max_episode_steps": 250,
 70    },
 71    "FetchReachCost-v1": {
 72        "entry_point": "stable_gym.envs.robotics.fetch.fetch_reach_cost.fetch_reach_cost:FetchReachCost",
 73        "reward_threshold": 300,
 74        "max_episode_steps": 50,
 75    },
 76    "QuadXHoverCost-v1": {
 77        "entry_point": "stable_gym.envs.robotics.quadrotor.quadx_hover_cost.quadx_hover_cost:QuadXHoverCost",
 78        "reward_threshold": 300,
 79        "max_episode_steps": 400,
 80    },
 81    "QuadXTrackingCost-v1": {
 82        "entry_point": "stable_gym.envs.robotics.quadrotor.quadx_tracking_cost.quadx_tracking_cost:QuadXTrackingCost",
 83        "reward_threshold": 300,
 84        "max_episode_steps": 400,
 85    },
 86    "QuadXWaypointsCost-v1": {
 87        "entry_point": "stable_gym.envs.robotics.quadrotor.quadx_waypoints_cost.quadx_waypoints_cost:QuadXWaypointsCost",
 88        "reward_threshold": 300,
 89        "max_episode_steps": 400,
 90    },
 91    # NOTE: The Minitaur environment is not compatible with gymnasium. See
 92    # https://github.com/bulletphysics/bullet3/issues/4369 for more details.
 93    "MinitaurBulletCost-v1": {
 94        "entry_point": "stable_gym.envs.robotics.minitaur.minitaur_bullet_cost.minitaur_bullet_cost:MinitaurBulletCost",
 95        "reward_threshold": 300,
 96        "max_episode_steps": 500,
 97        "compatible": False,
 98        "additional_wrappers": (MaxEpisodeStepsInjectionWrapper.wrapper_spec(),),
 99    },
100}
101
102for env, val in ENVS.items():
103    register(
104        id=env,
105        entry_point=val["entry_point"],
106        reward_threshold=val["reward_threshold"],
107        max_episode_steps=(
108            val["max_episode_steps"] if "max_episode_steps" in val else None
109        ),
110        disable_env_checker=not val["compatible"] if "compatible" in val else False,
111        apply_api_compatibility=not val["compatible"] if "compatible" in val else False,
112        additional_wrappers=(
113            val["additional_wrappers"] if "additional_wrappers" in val else ()
114        ),
115    )