AI4Finance-Foundation / FinRL

FinRL: Financial Reinforcement Learning. 🔥
https://ai4finance.org
MIT License
9.39k stars 2.28k forks source link

no attribute 'if_off_policy' #716

Open hokhay opened 1 year ago

hokhay commented 1 year ago

Hi all,

I just install and run the main.py for the first time. I bump on to the Arguments(agent_class=agent) error then I change agent_class to agent. After this I get another error as the following:

File "/home/jason/FinRL/FinRL-Library/finrl/main.py", line 68, in main
    train(
  File "/home/jason/FinRL/FinRL-Library/finrl/train.py", line 59, in train
    model = agent.get_model(model_name, model_kwargs=erl_params)
  File "/home/jason/FinRL/FinRL-Library/finrl/agents/elegantrl/models.py", line 63, in get_model
    model = Arguments(agent=agent, env=env)
  File "/home/jason/FinRL/FinRL-Library/venv/lib/python3.9/site-packages/elegantrl-0.3.3-py3.9.egg/elegantrl/train/config.py", line 127, in __init__
    self.if_off_policy = agent.if_off_policy  # agent is on-policy or off-policy
AttributeError: module 'elegantrl.agents.AgentPPO' has no attribute 'if_off_policy'

I notice that self.if_off_policy is assigned one line after this error line. How can I solve this problem

Thanks

Yonv1943 commented 1 year ago

The training pipeline needs to know about "the agent is off-policy or on-policy DRL algorithm".

self.if_off_policy = agent.if_off_policy

change this line to

name = agent_class.__name__
self.if_off_policy = all((name.find('PPO') == -1, name.find('A2C') == -1))

It means that PPO and A2C is on-policy (self.if_off_policy = False)

https://github.com/AI4Finance-Foundation/ElegantRL/blob/98b83959cc6e62f17e7c2ad104c5050e84bd7297/elegantrl/train/config.py#L102-L105