qlib icon indicating copy to clipboard operation
qlib copied to clipboard

fix: resolve backtest module crash due to Gym and NumPy 2.0+ incompat…

Open Lixuyizhi opened this issue 2 months ago • 1 comments

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?

  • [x] Pass the test by running: pytest qlib/tests/test_all_pipeline.py under upper directory of qlib.
  • [x] 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

  • [x] Fix bugs
  • [ ] Add new feature
  • [x] 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 avatar Sep 28 '25 02:09 Lixuyizhi

@microsoft-github-policy-service agree

Lixuyizhi avatar Sep 28 '25 02:09 Lixuyizhi