Shimmy

2.0.1 · active · verified Thu Apr 16

Shimmy is an API conversion tool that provides Gymnasium and PettingZoo bindings for popular external reinforcement learning environments. It allows users to access a wide range of single and multi-agent environments under a single standard API. The current version is 2.0.1, with releases occurring a few times a year to ensure compatibility with new versions of Gymnasium and PettingZoo, as well as to add support for new external environments.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to wrap a single-agent DeepMind Control environment for Gymnasium and a multi-agent DeepMind Control Soccer environment for PettingZoo using Shimmy. Note the explicit `import shimmy` which became necessary with Gymnasium 1.0.0a1. [8, 9, 15]

import gymnasium as gym
import shimmy # This import is now necessary for environment registration in Gymnasium v1.0+

# Example for a single-agent DeepMind Control environment
env = gym.make("dm_control/acrobot-swingup_sparse-v0", render_mode="human")

observation, info = env.reset(seed=42)
for _ in range(100):
    action = env.action_space.sample()
    observation, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        observation, info = env.reset()
env.close()

# Example for a multi-agent DeepMind Control Soccer environment (PettingZoo API)
from shimmy.dm_control_multiagent_compatibility import DmControlMultiAgentCompatibilityV0
from dm_control.locomotion import soccer as dm_soccer

multi_agent_env = dm_soccer.load(team_size=2)
multi_agent_env = DmControlMultiAgentCompatibilityV0(multi_agent_env, render_mode="human")

observations, infos = multi_agent_env.reset()
while multi_agent_env.agents:
    actions = {agent: multi_agent_env.action_space(agent).sample() for agent in multi_agent_env.agents}
    observations, rewards, terminations, truncations, infos = multi_agent_env.step(actions)
multi_agent_env.close()

view raw JSON →