record_video.py not working on PyBullet envs [bug]
See original GitHub issueDescribe the bug
After training a PyBullet environment, I try to record a video of it:
python -m utils.record_video --algo tqc --env ReacherBulletEnv-v0 -n 1000
And I get the following output:
pybullet build time: Mar 8 2021 17:24:12
Loading latest experiment, id=1
pybullet build time: Mar 8 2021 17:24:12
Loading latest experiment, id=1
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/forkserver.py", line 196, in main
_serve_one(s, listener, alive_r, old_handlers)
File "/usr/lib/python3.6/multiprocessing/forkserver.py", line 231, in _serve_one
code = spawn._main(child_r)
File "/usr/lib/python3.6/multiprocessing/spawn.py", line 114, in _main
prepare(preparation_data)
File "/usr/lib/python3.6/multiprocessing/spawn.py", line 223, in prepare
_fixup_main_from_name(data['init_main_from_name'])
File "/usr/lib/python3.6/multiprocessing/spawn.py", line 249, in _fixup_main_from_name
alter_sys=True)
File "/usr/lib/python3.6/runpy.py", line 205, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib/python3.6/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mcres/git/rl-baselines3-zoo/utils/record_video.py", line 74, in <module>
hyperparams=hyperparams,
File "/home/mcres/git/rl-baselines3-zoo/utils/utils.py", line 219, in create_test_env
vec_env_kwargs=vec_env_kwargs,
File "/home/mcres/git/stable-baselines3/stable_baselines3/common/env_util.py", line 102, in make_vec_env
return vec_env_cls([make_env(i + start_index) for i in range(n_envs)], **vec_env_kwargs)
File "/home/mcres/git/stable-baselines3/stable_baselines3/common/vec_env/subproc_vec_env.py", line 106, in __init__
process.start()
File "/usr/lib/python3.6/multiprocessing/process.py", line 105, in start
self._popen = self._Popen(self)
File "/usr/lib/python3.6/multiprocessing/context.py", line 291, in _Popen
return Popen(process_obj)
File "/usr/lib/python3.6/multiprocessing/popen_forkserver.py", line 35, in __init__
super().__init__(process_obj)
File "/usr/lib/python3.6/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/usr/lib/python3.6/multiprocessing/popen_forkserver.py", line 42, in _launch
prep_data = spawn.get_preparation_data(process_obj._name)
File "/usr/lib/python3.6/multiprocessing/spawn.py", line 143, in get_preparation_data
_check_not_importing_main()
File "/usr/lib/python3.6/multiprocessing/spawn.py", line 136, in _check_not_importing_main
is not going to be frozen to produce an executable.''')
RuntimeError:
An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.
This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:
if __name__ == '__main__':
freeze_support()
...
The "freeze_support()" line can be omitted if the program
is not going to be frozen to produce an executable.
Traceback (most recent call last):
File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mcres/git/rl-baselines3-zoo/utils/record_video.py", line 74, in <module>
hyperparams=hyperparams,
File "/home/mcres/git/rl-baselines3-zoo/utils/utils.py", line 219, in create_test_env
vec_env_kwargs=vec_env_kwargs,
File "/home/mcres/git/stable-baselines3/stable_baselines3/common/env_util.py", line 102, in make_vec_env
return vec_env_cls([make_env(i + start_index) for i in range(n_envs)], **vec_env_kwargs)
File "/home/mcres/git/stable-baselines3/stable_baselines3/common/vec_env/subproc_vec_env.py", line 111, in __init__
observation_space, action_space = self.remotes[0].recv()
File "/usr/lib/python3.6/multiprocessing/connection.py", line 250, in recv
buf = self._recv_bytes()
File "/usr/lib/python3.6/multiprocessing/connection.py", line 407, in _recv_bytes
buf = self._recv(4)
File "/usr/lib/python3.6/multiprocessing/connection.py", line 379, in _recv
chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer
The same thing happens if I change algorithm and environment, e.g. td3
and HalfCheetahBulletEnv-v0
, respectively.
System Info Describe the characteristic of your environment:
- Describe how Stable Baselines3 was installed:
pip install -e
- Python version:
3.6.9
- PyTorch version:
1.8.0
- Versions of any other relevant libraries:
gym==0.18.0
pybullet==3.1.0
Additional context
Recording video on normal gym
environments is working.
Executing the PyBullet envs with enjoy.py
is also working.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Real-Time Physics Simulation Forum - PyBullet
Initially this behavior appeared to be random. It happened frequently, but I had no idea why, and I could not reproduce the issue...
Read more >How to run OpenAI Gym .render() over a server - Stack Overflow
Got a simple solution working: CartPole. If on a linux server, open jupyter with $ xvfb-run -s "-screen 0 1400x900x24" jupyter notebook
Read more >Added OG gym repo (c8f3d5fc) · Commits - GitLab
open_ai_gym_master/gym/envs/algorithmic/__init__.py ... Only issues or pull requests with all of these labels are check if stale.
Read more >OpenAI Gym Environments with PyBullet (Part 2)
During the training process the robot is just “shaking” a bit and opening/closing the fingers, but it is not moving towards the object...
Read more >Creating OpenAI Gym Environments with PyBullet (Part 2)
Completed code is provided, so you do not need to write any of the following ... Finally, in simple_driving/envs/simple_driving_env.py, add:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
you have two solutions : try with
MKL_THREADING_LAYER=GNU
(see https://github.com/DLR-RM/stable-baselines3/blob/master/.gitlab-ci.yml) or change the default start method to fork (cf doc).So, the fix is here: https://github.com/DLR-RM/rl-baselines3-zoo/pull/77
Different things:
__main__
(I wrote the code when we were still usingfork
as default)--no-render
if you just need the video without direct visual feedback (faster).