AI4Finance-Foundation / FinRL-Meta

FinRL­-Meta: Dynamic datasets and market environments for FinRL.
https://ai4finance.org
MIT License
1.2k stars 560 forks source link

TypeError: __init__() got an unexpected keyword argument 'agent' in elegantrl_models.py #212

Open mhdmyz opened 1 year ago

mhdmyz commented 1 year ago

I get the following error while running the elegantrl_models.py:

TypeError: init() got an unexpected keyword argument 'agent' in the 58th line of /agents/elegantrl_models.py

I understand "agent" argument in Arguments class of config.py has been changed to "agent_class"

So when I change the "agent" argument in the elegantrl_models.py to "agent_class", I get the following error:

ValueError: too many values to unpack (expected 2), in the 107th line of elegantrl/train/run.py

KevinMyDing commented 1 year ago

Has anyone solved?

mhdmyz commented 1 year ago

I traced the issue but not sure how to solve it yet. In the train_and_evaluate function in run.py, agent.explore_env() returns a list of 5 tensors while it's supposed to return 2 to set the trajectory and step variables.

mhdmyz commented 1 year ago

I solved the issue, I'll create a pull request shortly.

Burntt commented 1 year ago

Anyone solved this yet? Is there a PR already?

Burntt commented 1 year ago

it's easy, the attribute Arguments.agent in config.py should be Arguments.agent_class

They are/were equivalent.

Burntt commented 1 year ago

After that, you will get a module not callable error. To solve that, find elegantrl_models.py and replace the imports as :

# DRL models from ElegantRL: https://github.com/AI4Finance-Foundation/ElegantRL import torch from elegantrl.agents.AgentDDPG import AgentDDPG from elegantrl.agents.AgentPPO import AgentPPO from elegantrl.agents.AgentSAC import AgentSAC from elegantrl.agents.AgentTD3 import AgentTD3 from elegantrl.train.config import Arguments from elegantrl.train.run import init_agent from elegantrl.train.run import train_and_evaluate

mhdmyz commented 1 year ago

I created the required PRs to solve the issue.

mhdmyz commented 1 year ago

In addition to changing agent to agent_class in elegantrl_models.py, the run.py in elegantrl had to be modified as well.

BBiering commented 1 year ago

@mhdmyz did you ever publish a PR about this? I stil have the same issue.