FinRL-Meta icon indicating copy to clipboard operation
FinRL-Meta copied to clipboard

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

Open mhdmyz opened this issue 2 years ago • 9 comments

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

mhdmyz avatar Aug 16 '22 12:08 mhdmyz

Has anyone solved?

KevinMyDing avatar Aug 22 '22 15:08 KevinMyDing

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 avatar Aug 24 '22 16:08 mhdmyz

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

mhdmyz avatar Aug 24 '22 17:08 mhdmyz

Anyone solved this yet? Is there a PR already?

Burntt avatar Aug 26 '22 09:08 Burntt

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

They are/were equivalent.

Burntt avatar Aug 26 '22 12:08 Burntt

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

Burntt avatar Aug 26 '22 12:08 Burntt

I created the required PRs to solve the issue.

mhdmyz avatar Aug 26 '22 12:08 mhdmyz

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

mhdmyz avatar Aug 26 '22 12:08 mhdmyz

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

BBiering avatar Feb 11 '23 22:02 BBiering