Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: __init__() missing 1 required positional argument: 'action_dim' #237

Closed
haisheng666 opened this issue Nov 22, 2022 · 4 comments · Fixed by #239
Closed

TypeError: __init__() missing 1 required positional argument: 'action_dim' #237

haisheng666 opened this issue Nov 22, 2022 · 4 comments · Fixed by #239
Labels
bug Something isn't working

Comments

@haisheng666
Copy link

If you run your own example, errors will be reported. Please help us to find out what the problem is?

/opt/anaconda3/envs/elegant_RL/bin/python /home/lhs/PycharmProjects/elegant_RL/tutorial_BipedalWalker-v3.py
WARNING: env.action_space.high [1. 1. 1. 1.]
env_args = {
'env_num': 1,
'env_name': 'BipedalWalker-v3',
'max_step': 1600,
'state_dim': 24,
'action_dim': 4,
'if_discrete': False,
'target_return': 300,
}
| Arguments Remove cwd: ./BipedalWalker-v3_PPO_0
Traceback (most recent call last):
File "/home/lhs/PycharmProjects/elegant_RL/tutorial_BipedalWalker-v3.py", line 32, in
train_and_evaluate(args)
File "/opt/anaconda3/envs/elegant_RL/lib/python3.8/site-packages/elegantrl/train/run.py", line 87, in train_and_evaluate
agent = init_agent(args, gpu_id, env)
File "/opt/anaconda3/envs/elegant_RL/lib/python3.8/site-packages/elegantrl/train/run.py", line 16, in init_agent
agent = args.agent_class(args.net_dim, args.state_dim, args.action_dim, gpu_id=gpu_id, args=args)
File "/opt/anaconda3/envs/elegant_RL/lib/python3.8/site-packages/elegantrl/agents/AgentPPO.py", line 38, in init
AgentBase.init(self, net_dim, state_dim, action_dim, gpu_id, args)
File "/opt/anaconda3/envs/elegant_RL/lib/python3.8/site-packages/elegantrl/agents/AgentBase.py", line 53, in init
self.act = act_class(net_dim, state_dim, action_dim).to(self.device)
TypeError: init() missing 1 required positional argument: 'action_dim'

@YangletLiu YangletLiu added the bug Something isn't working label Nov 22, 2022
@Yonv1943
Copy link
Collaborator

Yonv1943 commented Nov 29, 2022

The code in net.py is

def __init__(self, mid_dim: int, num_layer: int, state_dim: int, action_dim: int):

The code in AgentBase.py is

self.act = act_class(net_dim, state_dim, action_dim).to(self.device)

The code in AgentBase.py should be:

        self.act = act_class(net_dim, num_layers, state_dim, action_dim).to(self.device)
        self.cri = cri_class(net_dim, num_layers, state_dim, action_dim).to(self.device) \

I will upload a Pullrequest 237 to fix this bug. Thank you.

@Praying
Copy link

Praying commented Dec 4, 2022

same question, please fix it and merge to master as soon as possible

@JonathanLehner
Copy link

self.act = act_class(net_dim, state_dim, action_dim).to(self.device)
self.cri = cri_class(net_dim, state_dim, action_dim).to(self.device)
if cri_class else self.act

this is still in the latest code. It still crashes for me

@JonathanLehner
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants