Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gymnasium v1.0.0 support #2

Closed
wants to merge 7 commits into from
Closed

Gymnasium v1.0.0 support #2

wants to merge 7 commits into from

Conversation

drewmee
Copy link
Owner

@drewmee drewmee commented May 28, 2024

Description

This PR updates the monitor_gym integration to support the upcoming Gymnasium v1.0.0 release. The key changes include:

  • Added version checks for Gymnasium to handle breaking changes introduced in v1.0.0.
  • Updated the handling of RecordVideo for Gymnasium v1.0.0 and later versions.
  • Adjusted the logic to maintain backward compatibility with older versions of both Gym and Gymnasium.
  • Ensured that the path variable is set correctly based on the Gym/Gymnasium version.
  • I updated CHANGELOG.md, or it's not applicable

Testing

How was this PR tested?

I ran the "Stable Baselines 3 - Track Experiments with Weights and Biases" example Jupyter notebook using:

  • Gymnasium pre-v1.0.0: Specifically, gymnasium==0.29.1 with stable-baselines3==2.4.0a1.
    • ✅ Result: The notebook runs successfully, and videos of the RL agent training in Gymnasium environments are uploaded to Weights and Biases and viewable in the UI.
  • Gymnasium post-v1.0.0 pre-release: Specifically, gymnasium==1.0.0a2.
    • ⚠️ Result: It is not possible to pip install the stable-baselines3 dependency (specifically stable-baselines3<=2.4.0a1) since it requires gymnasium<0.30,>=0.28.1. However, one can now use monitor_gym=True in wandb.init() with post-v1.0.0 versions of Gymnasium.
    • Note: To ensure full functionality with the W&B-Gymnasium integration for post-v1.0.0 versions of Gymnasium, we will have to wait for other projects that depend on Gymnasium to support post-v1.0.0 versions. These projects are noted here: Projects updated to v1.0.0 Farama-Foundation/Gymnasium#944

…ed API changes

- Added `_gymnasium_version_gt_0_29_1` global variable to track gymnasium version.
- Updated `monitor` function to handle new `RecordVideo` API introduced in gymnasium v0.29.1+.
- Maintained compatibility with gym versions <0.26.0 by conditionally setting `path` and `recorder`.
- Patched appropriate video recorder based on the detected version of gym or gymnasium.
- Ensured proper cleanup and logging of video recordings.

This commit ensures that the wandb integration works seamlessly with both older and newer versions of gym and gymnasium libraries.
…gymnasium

- Changed from directly importing RecordVideo to using `getattr` to dynamically fetch the `RecordVideo` wrapper.
- Ensured compatibility with gymnasium v0.29.1+ by modifying how the `RecordVideo` class is accessed.

This update ensures a more flexible and error-free way of accessing the `RecordVideo` wrapper for newer gymnasium versions.
…gym <0.26

- Added support for gymnasium v1.0.0 by checking for the new `RecordVideo` wrapper.
- Maintained backward compatibility with older versions of gym and gymnasium.
- Implemented conditional logic to handle the breaking changes in gym 0.26.0.
- Updated `_gymnasium_version_lt_1_0_0` to check for gymnasium versions less than 1.0.0.
- Refactored the `close` function to include conditional logic for both new and old APIs.
…ersions

- Adjusted the `_gymnasium_version_lt_1_0_0` check to compare against `1.0.0a1` to include alpha versions.
- Deleted the duplicate `vcr = wandb.util.get_module` line before the global variable declarations.
@drewmee drewmee closed this May 28, 2024
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.

[CLI]: Gymnasium v1.0.0 incompatible with monitor_gym
1 participant