Skip to content

feat(wrappers): add GymnasiumWrapper for Farama Gymnasium environments (#359) - #381

Open
reginaldalfret wants to merge 1 commit into
google-deepmind:masterfrom
reginaldalfret:feat/issue-359-gymnasium-wrapper
Open

reginaldalfret wants to merge 1 commit into
google-deepmind:masterfrom
reginaldalfret:feat/issue-359-gymnasium-wrapper

Conversation

@reginaldalfret

Copy link
Copy Markdown

Summary

Resolves #359

Modern reinforcement learning environments have largely transitioned from OpenAI Gym to Farama Foundation Gymnasium. Gymnasium introduces breaking API differences from legacy Gym:

  1. reset(seed=..., options=...) returns (observation, info) instead of only observation.
  2. step(action) returns 5 values (observation, reward, terminated, truncated, info) instead of 4 (observation, reward, done, info).
  3. Space classes reside under gymnasium.spaces.

Passing Gymnasium environments into GymWrapper caused unpacking errors (ValueError: too many values to unpack (expected 4, got 5)).

Changes

  • Implemented GymnasiumWrapper in acme/wrappers/gymnasium_wrapper.py:
    • Handles modern reset(seed=..., options=...) returning (observation, info).
    • Maps 5-tuple step returns into dm_env.TimeStep: terminated maps to dm_env.termination(reward, observation) (discount 0.0), truncated maps to dm_env.truncation(reward, observation) (discount 1.0), and normal transitions map to dm_env.transition(reward, observation).
    • Supports automatic reset when step() is called after episode termination/truncation.
    • Converts gymnasium.spaces (Discrete, Box, MultiBinary, MultiDiscrete, Tuple, Dict) into corresponding dm_env.specs.
    • Stores step and reset diagnostic metadata accessible via get_info().
  • Exported GymnasiumWrapper in acme/wrappers/__init__.py.
  • Gracefully handled optional legacy gym in acme/wrappers/__init__.py and optional launchpad in acme/utils/signals.py.
  • Added unit tests in acme/wrappers/gymnasium_wrapper_test.py.

Verification

  • Ran python -m unittest acme/wrappers/gymnasium_wrapper_test.py: 5 tests passed (covering spec conversion, reset with seeding, step transitions, termination, truncation, and auto-reset).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Gymnasium Wrapper for Acme (dm_env compatible)

1 participant