AI4Finance-Foundation / ElegantRL

Massively Parallel Deep Reinforcement Learning. 🔥
https://ai4finance.org
Other
3.74k stars 850 forks source link

'AgentPPO' object has no attribute 'traj_list' #181

Open HarryLukKF opened 2 years ago

HarryLukKF commented 2 years ago

There is an error when I try to excute the train function in Demo_MultiCrypto_Trading.ipynb

AttributeError: 'AgentPPO' object has no attribute 'traj_list' image

Please kindly advise how should I fix this error? Many thanks in advance

altosssss commented 2 years ago

same here!

AlexLiddiard commented 2 years ago

Also encountered this issue when running Demo_MultiCrypto_Trading.ipynb I spent quite a long time debugging it and finally got it working by changing these things:

  1. elegantrl/agents/AgentBase.py line 43, insert:

    self.traj_list = [
    [list() for _ in range(4 if self.if_off_policy else 5)]
    for _ in range(self.env_num)
    ]
  2. elegantrl/agents/AgentPPO.py line 88, change to: return self.convert_trajectory(traj_list, last_done), step_i

  3. elegantrl/train/evaluator.py line 60, comment it out

  4. finrl-meta/agents/elegantrl_models.py line 112, change to: environment.cash

  5. finrl-meta/agents/elegantrl_models.py line 114 change to: environment.price_array[environment.time] * environment.stocks

altosssss commented 2 years ago

Also encountered this issue when running Demo_MultiCrypto_Trading.ipynb I spent quite a long time debugging it and finally got it working by changing these things:

  1. elegantrl/agents/AgentBase.py line 43, insert:
self.traj_list = [
  [list() for _ in range(4 if self.if_off_policy else 5)]
  for _ in range(self.env_num)
]
  1. elegantrl/agents/AgentPPO.py line 88, change to: return self.convert_trajectory(traj_list, last_done), step_i
  2. elegantrl/train/evaluator.py line 60, comment it out
  3. finrl-meta/agents/elegantrl_models.py line 112, change to: environment.cash
  4. finrl-meta/agents/elegantrl_models.py line 114 change to: environment.price_array[environment.time] * environment.stocks

Thanks Alex. Wondering if you tried run it on Colab?

bassemfg commented 2 years ago

Also encountered this issue when running Demo_MultiCrypto_Trading.ipynb I spent quite a long time debugging it and finally got it working by changing these things:

  1. elegantrl/agents/AgentBase.py line 43, insert:
self.traj_list = [
    [list() for _ in range(4 if self.if_off_policy else 5)]
    for _ in range(self.env_num)
]
  1. elegantrl/agents/AgentPPO.py line 88, change to: return self.convert_trajectory(traj_list, last_done), step_i
  2. elegantrl/train/evaluator.py line 60, comment it out
  3. finrl-meta/agents/elegantrl_models.py line 112, change to: environment.cash
  4. finrl-meta/agents/elegantrl_models.py line 114 change to: environment.price_array[environment.time] * environment.stocks

Thanks Alex. Wondering if you tried run it on Colab?

Yes, I am getting the same error both on ubuntu and google Colab

mhdmyz commented 2 years ago

Same problem here! Solution mentioned by @AlexLiddiard solved the issue. But why it hasn't been fixed yet on elegantrl?!

bassemfg commented 2 years ago

Also, if when I try other agents like ddpg or td3 or sac, I get another error in the same line saying that init() expects 4 arguments but got 5. I spent a couple of hours trying to debug it but no luck. Anyone has any ideas?

shixun404 commented 2 years ago

I modified the question related to 'traj_list'. The file ' demo_A2C_PPO.py ' and ' demo_PPO_H.py ' could run correctly now!

shixun404 commented 2 years ago

By the way, demo_DDPG_TD3_SAC.py and demo_DDPG_H.py run correctly as well~