microsoft / qlib

Qlib is an AI-oriented quantitative investment platform that aims to realize the potential, empower research, and create value using AI technologies in quantitative investment, from exploring ideas to implementing productions. Qlib supports diverse machine learning modeling paradigms. including supervised learning, market dynamics modeling, and RL.
https://qlib.readthedocs.io/en/latest/
MIT License
14.55k stars 2.53k forks source link

The official RL example got error #1750

Closed ghyzx closed 3 months ago

ghyzx commented 4 months ago

Copy and run these code from official RL example, but got below errors, please help check, thanks. https://github.com/microsoft/qlib/blob/main/examples/rl/simple_example.ipynb

Training started /Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/tianshou/env/venvs.py:66: UserWarning: You provided an environment generator that returned an OpenAI Gym environment. We strongly recommend transitioning to Gymnasium environments. Tianshou is automatically wrapping your environments in a compatibility layer, which could potentially cause issues. warnings.warn( /Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/utils/data_queue.py:98: RuntimeWarning: After 1 cleanup, the queue is still not empty. warnings.warn(f"After {repeat} cleanup, the queue is still not empty.", category=RuntimeWarning) Traceback (most recent call last): File "/Users/user/Desktop/ruc/paper/quant/Quant/rl/rl_example.py", line 166, in train( File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/trainer/api.py", line 63, in train trainer.fit(vessel) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/trainer/trainer.py", line 224, in fit self.vessel.train(vector_env) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/trainer/vessel.py", line 171, in train collector = Collector(self.policy, vector_env, VectorReplayBuffer(self.buffer_size, len(vector_env))) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/tianshou/data/collector.py", line 80, in init self.reset(False) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/tianshou/data/collector.py", line 131, in reset self.reset_env(gym_reset_kwargs) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/tianshou/data/collector.py", line 147, in reset_env obs, info = self.env.reset(**gym_reset_kwargs) File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/utils/finite_env.py", line 233, in reset for i, o in zip(request_id, super().reset(request_id)): File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/tianshou/env/venvs.py", line 280, in reset assert ( AssertionError: The environment does not adhere to the Gymnasium's API. Exception ignored in: <function DataQueue.del at 0x12b9f6280> Traceback (most recent call last): File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/utils/data_queue.py", line 148, in del self.cleanup() File "/Users/user/Desktop/ruc/paper/quant/Quant/venv/lib/python3.8/site-packages/qlib/rl/utils/data_queue.py", line 101, in cleanup self._queue.get(block=False) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/queues.py", line 111, in get res = self._recv_bytes() File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 216, in recv_bytes buf = self._recv_bytes(maxlength) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 414, in _recv_bytes buf = self._recv(4) File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/multiprocessing/connection.py", line 383, in _recv raise EOFError EOFError:

env python: 3.8 qlib: 0.9.3

yanzhengkim commented 3 months ago

Hello have you solved this bug? I have the same bug as well.

mrwang1992 commented 3 months ago

try use this version package

tianshou==0.4.10 gym==0.26.2 gymnasium==0.29.1

ghyzx commented 3 months ago

hi @mrwang1992, it works for me, thank you very much.