timeolord / Reinforcement-Learning-Stock-Trader

Using a modified version of Werner Duvaud's MuZero implementation (https://github.com/werner-duvaud/muzero-general) this reinforcement agent learns to trade stocks based on Yahoo Finance data.
17 stars 7 forks source link

I couldn't get it to run properly. Why? #2

Closed widebowl closed 2 years ago

widebowl commented 3 years ago

Dear Timeolord. I appreciate your great work. I tried to run your code in Windows 10, VS Code environment. But it didn't work properly. Does it work if I run it on linux? I'm not very familiar with Linux. Below is the message displayed when running.

wideb@DESKTOP-CP6LF6P MINGW64 /d/Investment/AI-Trader-test/Reinforcement-Learning-Stock-Trader-main $ /usr/bin/env C:\Python\Python37\python.exe c:\Users\wideb\.vscode\extensions\ms-python.python-2021.6.944021595\pythonFiles\lib\python\debugpy\launcher 49532 -- d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\TradingBot.py 2021-06-22 00:54:27,672 INFO worker.py:641 -- Connecting to existing Ray cluster at address: 192.168.219.102:6379 (pid=21572) Windows fatal exception: access violation (pid=21572) 2021-06-22 00:54:36.591536: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll

Training... Run tensorboard --logdir ./results and go to http://localhost:6006/ to see in real time the training performance.

(pid=17416) 2021-06-22 00:54:43,702ep: 0ERROR worker.py:382 -- Exception raised in creation task: The actor died because of an error raised in its creation task, ray::Trainer.init() (pid=17416, ip=192.168.219.102) (pid=17416) File "python\ray_raylet.pyx", line 505, in ray._raylet.execute_task (pid=17416) File "python\ray_raylet.pyx", line 449, in ray._raylet.execute_task.function_executor (pid=17416) File "c:\python\python37\lib\site-packages\ray_private\function_manager.py", line 556, in actor_method_executor (pid=17416) return method(ray_actor, *args, *kwargs) (pid=17416) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\trainer.py", line 28, in init (pid=17416) self.model.to(torch.device("cuda" if self.config.train_on_gpu else "cpu")) (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 673, in to (pid=17416) return self._apply(convert) (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply (pid=17416) module._apply(fn) (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply (pid=17416) module._apply(fn) (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply (pid=17416) module._apply(fn) (pid=17416) [Previous line repeated 1 more time] (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 409, in _apply (pid=17416) param_applied = fn(param) (pid=17416) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 671, in convert (pid=17416) return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking) (pid=17416) File "c:\python\python37\lib\site-packages\torch\cuda__init.py", line 164, in _lazy_init (pid=17416) raise AssertionError("Torch not compiled with CUDA enabled") (pid=17416) AssertionError: Torch not compiled with CUDA enabled 2021-06-22 00:54:48,774 ERROR worker.py:1056 -- Possible unhandled error from worker: ray::Trainer.init() (pid=17416, ip=192.168.219.102) File "python\ray_raylet.pyx", line 505, in ray._raylet.execute_task File "python\ray_raylet.pyx", line 449, in ray._raylet.execute_task.function_executor File "c:\python\python37\lib\site-packages\ray_private\function_manager.py", line 556, in actor_method_executor
return method(
ray_actor,
args, **kwargs) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\trainer.py", line 28, in
init self.model.to(torch.device("cuda" if self.config.train_on_gpu else "cpu")) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 673, in to return self._apply(convert) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply module._apply(fn) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply module._apply(fn) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 387, in _apply module._apply(fn) [Previous line repeated 1 more time] File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 409, in _apply param_applied = fn(param) File "c:\python\python37\lib\site-packages\torch\nn\modules\module.py", line 671, in convert return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking) File "c:\python\python37\lib\site-packages\torch\cuda__init.py", line 164, in _lazy_init raise AssertionError("Torch not compiled with CUDA enabled") AssertionError: Torch not compiled with CUDA enabled 2021-06-22 00:54:49,784 ERROR worker.py:1056 -- Possible unhandled error from worker: ray::SelfPlay.continuous_self_play() (pid=12832, ip=192.168.219.102) File "python\ray_raylet.pyx", line 505, in ray._raylet.execute_task File "python\ray_raylet.pyx", line 449, in ray._raylet.execute_task.function_executor File "c:\python\python37\lib\site-packages\ray_private\function_manager.py", line 556, in actor_method_executor
return method(
ray_actor, *args, **kwargs) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\self_play.py", line 46, in continuous_self_play self.config.muzero_player) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\self_play.py", line 101, in play_game observation = self.game.reset() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\games\trading.py", line 188, in reset return self.env.reset() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\y_finance_env\envs\y_finance_env.py", line 88, in reset observation = self.getObservation() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\y_finance_env\envs\y_finance_env.py", line 186, in getObservation close = stock[0].iloc[self.index - self.historyLength: self.index]["Close"].to_numpy() File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 1767, in getitem return self._getitem_axis(maybe_callable, axis=axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 2117, in _getitem_axis return self._get_slice_axis(key, axis=axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 1748, in _get_slice_axis indexer = self._convert_slice_indexer(slice_obj, axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 744, in _convert_slice_indexer ax = self.obj._get_axis(min(axis, self.ndim - 1)) File "pandas_libs\indexing.pyx", line 19, in pandas._libs.indexing._NDFrameIndexerBase.ndim.
get File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr if self._info_axis._can_hold_identifiers_and_holds_name(name): File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr if self._info_axis._can_hold_identifiers_and_holds_name(name): File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr if self._info_axis._can_hold_identifiers_and_holds_name(name): [Previous line repeated 1486 more times] File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 493, in _info_axis return getattr(self, self._info_axis_name) File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5270, in getattr return object.getattribute(self, name) File "pandas_libs\properties.pyx", line 63, in pandas._libs.properties.AxisProperty.get File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5270, in getattr return object.getattribute(self, name) RecursionError: maximum recursion depth exceeded while calling a Python object 2021-06-22 00:54:49,789 ERROR worker.py:1056 -- Possible unhandled error from worker: ray::SelfPlay.continuous_self_play() (pid=19176, ip=192.168.219.102) File "python\ray_raylet.pyx", line 505, in ray._raylet.execute_task File "python\ray_raylet.pyx", line 449, in ray._raylet.execute_task.function_executor File "c:\python\python37\lib\site-packages\ray_private\function_manager.py", line 556, in actor_method_executor
return method(ray_actor, *args, **kwargs) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\self_play.py", line 39, in continuous_self_play self.config.temperature_threshold, False, "self", 0) File "d:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\self_play.py", line 101, in play_game observation = self.game.reset() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\muzero\games\trading.py", line 188, in reset return self.env.reset() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\y_finance_env\envs\y_finance_env.py", line 88, in reset observation = self.getObservation() File "D:\Investment\AI-Trader-test\Reinforcement-Learning-Stock-Trader-main\y_finance_env\envs\y_finance_env.py", line 186, in getObservation close = stock[0].iloc[self.index - self.historyLength: self.index]["Close"].to_numpy() File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 1767, in getitem__ return self._getitem_axis(maybe_callable, axis=axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 2117, in _getitem_axis return self._get_slice_axis(key, axis=axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 1748, in _get_slice_axis indexer = self._convert_slice_indexer(slice_obj, axis) File "c:\python\python37\lib\site-packages\pandas\core\indexing.py", line 744, in _convert_slice_indexer ax = self.obj._get_axis(min(axis, self.ndim - 1)) File "pandas_libs\indexing.pyx", line 19, in pandas._libs.indexing._NDFrameIndexerBase.ndim.
get File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr if self._info_axis._can_hold_identifiers_and_holds_name(name): File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr if self._info_axis._can_hold_identifiers_and_holds_name(name): File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5272, in getattr__ if self._info_axis._can_hold_identifiers_and_holds_name(name): [Previous line repeated 1486 more times] File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 493, in _info_axis return getattr(self, self._info_axis_name) File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5270, in getattr return object.getattribute(self, name) File "pandas_libs\properties.pyx", line 63, in pandas._libs.properties.AxisProperty.get File "c:\python\python37\lib\site-packages\pandas\core\generic.py", line 5270, in getattr return object.getattribute(self, name) RecursionError: maximum recursion depth exceeded while calling a Python object Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Saving modelward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00 Persisting replay buffer games to disk... Last test reward: 0.00. Training step: 0/50000000. Played games: 0. Loss: 0.00

timeolord commented 3 years ago

Hi, yeah unfortunately the ray package only works on Linux. If you're on windows and want to setup a Linux environment you could try WSL2, which is what I use, or if you wanna just try it out you can use virtual box. Here's a link on how to setup WSL 2: https://docs.microsoft.com/en-us/windows/wsl/install-win10.

widebowl commented 3 years ago

Hi. Your clear answer completely solved my difficulties. In fact, I spent a lot of time getting this code running. I will try again with reference to your answer. Thank you.