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

get_env_attr not working in SubprocVectorEnv? #1153

Open
HYB777 opened this issue May 27, 2024 · 2 comments
Open

get_env_attr not working in SubprocVectorEnv? #1153

HYB777 opened this issue May 27, 2024 · 2 comments

Comments

@HYB777
Copy link

HYB777 commented May 27, 2024

I want to obtain some attributions from my custom environ, when I use DummyVectorEnv, get_env_attr is working.

But for SubprocVectorEnv, it seem not working? It report the following errors:

Process Process-1:
Traceback (most recent call last):
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
self.run()
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/process.py", line 108, in run
self._target(*self._args, **self._kwargs)
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/tianshou/env/worker/subproc.py", line 114, in _worker
p.send(getattr(env, data) if hasattr(env, data) else None)
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/connection.py", line 211, in send
self._send_bytes(_ForkingPickler.dumps(obj))
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/reduction.py", line 51, in dumps
cls(buf, protocol).dump(obj)
AttributeError: Can't pickle local object 'config_valve..'
Traceback (most recent call last):
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3398, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "", line 1, in <cell line: 1>
train_env.get_env_attr('simulator')
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/tianshou/env/venvs.py", line 221, in get_env_attr
return [self.workers[j].get_env_attr(key) for j in id]
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/tianshou/env/venvs.py", line 221, in
return [self.workers[j].get_env_attr(key) for j in id]
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/site-packages/tianshou/env/worker/subproc.py", line 152, in get_env_attr
return self.parent_remote.recv()
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/connection.py", line 255, in recv
buf = self._recv_bytes()
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/connection.py", line 419, in _recv_bytes
buf = self._recv(4)
File "/home/hyb/anaconda3/envs/hyb/lib/python3.9/multiprocessing/connection.py", line 388, in _recv
raise EOFError
EOFError

How could I solve it?

@Trinkle23897
Copy link
Collaborator

Trinkle23897 commented May 27, 2024

AttributeError: Can't pickle local object 'config_valve..' did you use lambda expression for config_value? Could you provide how you set config_value?

@HYB777
Copy link
Author

HYB777 commented May 28, 2024

AttributeError: Can't pickle local object 'config_valve..' did you use lambda expression for config_value? Could you provide how you set config_value?

What does the config_value refer to? If you mean the paramter env_fns in SubprocVectorEnv, I was actually using a lambda expression, as follows:
`

train_env_ = [lambda port=i: get_env(
    problem_config(
        problem=args.problem,
        prefix=args.prefix + '_train_port%d' % port,
        state_dir='state_dir',
        result_dir='result_dir',
        error_dir='error_dir',
        msh_dir='msh_dir',
        max_len=args.max_len,
        penalty=args.penalty,
        phase='train',
        local=args.prefix + '_train_port%d' % port,
        port=port,
    )
) for i in range(2036, 2036 + args.training_num)]

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants