Skip to content

Conversation

Lixuyizhi
Copy link

Description

This PR upgrades the project from gym to gymnasium to resolve compatibility issues with NumPy 2.0+ and eliminate deprecation warnings. The upgrade maintains full API compatibility by using import gymnasium as gym throughout the codebase.

Key Changes:

  • Updated dependency configuration in pyproject.toml and scripts/collect_info.py
  • Replaced all from gym import statements with from gymnasium import
  • Updated documentation references from gym.Env to gymnasium.Env
  • Modified RL modules to use gymnasium while maintaining backward compatibility
  • All code continues to use gym. prefix for seamless transition

Motivation and Context

  • Related Issue: Fixes backtest module crash due to Gym and NumPy 2.0+ incompatibility
  • Problem: Gym has been unmaintained since 2022 and does not support NumPy 2.0, causing runtime warnings and potential crashes
  • Solution: Migrate to gymnasium, the maintained drop-in replacement that supports modern NumPy versions

How Has This Been Tested?

  • Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • If you are adding a new feature, test on your own test scripts.

Testing Details:

  • Verified all import statements work correctly with gymnasium
  • Confirmed dependency configuration is properly updated
  • Tested that import gymnasium as gym maintains API compatibility
  • Validated that all RL modules can be imported without errors

Screenshots of Test Results (if appropriate):

  1. Pipeline test: [Add screenshots when available]
  2. Your own tests: e916f9172ec3fd9e3a87ce70499340c4

Types of changes

  • Fix bugs
  • Add new feature
  • Update documentation

Additional Notes:

  • This is a non-breaking change that maintains full backward compatibility
  • All existing code using gym. prefix will continue to work unchanged
  • The upgrade resolves NumPy 2.0+ compatibility issues
  • No functional changes to the RL framework, only dependency updates

@Lixuyizhi
Copy link
Author

@microsoft-github-policy-service agree

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.

1 participant