qlib
qlib copied to clipboard
fix: resolve backtest module crash due to Gym and NumPy 2.0+ incompat…
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.tomlandscripts/collect_info.py - Replaced all
from gym importstatements withfrom gymnasium import - Updated documentation references from
gym.Envtogymnasium.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.pyunder upper directory ofqlib. - [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 gymmaintains API compatibility - Validated that all RL modules can be imported without errors
Screenshots of Test Results (if appropriate):
- Pipeline test: [Add screenshots when available]
- Your own tests:
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
@microsoft-github-policy-service agree