hill-a / stable-baselines

A fork of OpenAI Baselines, implementations of reinforcement learning algorithms
http://stable-baselines.readthedocs.io/
MIT License
4.16k stars 725 forks source link

BrokenPipeError using the GAIL example of stable-baselines #567

Closed ThibaultFy closed 4 years ago

ThibaultFy commented 4 years ago

Hello,

I can't launch the GAIL example on my Anaconda on Windows 10. I installed the Windows MPI, try setting n_workers to 0 but I can't get rid of this error... Has anyone succeed in using an stable-baselines algorithm using the MPI library?

Thank you in advance for your help.

Traceback (most recent call last):

  File "...\Anaconda3\envs\baselines\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile
    execfile(filename, namespace)

  File "...\Anaconda3\envs\baselines\lib\site-packages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File ".../gail_test.py", line 40, in <module>
    main()

  File ".../gail_test.py", line 23, in main
    model.learn(total_timesteps=1000)

  File "...\stable-baselines\stable_baselines\gail\model.py", line 54, in learn
    return super().learn(total_timesteps, callback, log_interval, tb_log_name, reset_num_timesteps)

  File "...\stable-baselines\stable_baselines\trpo_mpi\trpo_mpi.py", line 447, in learn
    ob_expert, ac_expert = self.expert_dataset.get_next_batch()

  File "...\stable-baselines\stable_baselines\gail\dataset\dataset.py", line 152, in get_next_batch
    dataloader.start_process()

  File "...\stable-baselines\stable_baselines\gail\dataset\dataset.py", line 231, in start_process
    self.process.start()

  File "...\Anaconda3\envs\baselines\lib\multiprocessing\process.py", line 112, in start
    self._popen = self._Popen(self)

  File "...\Anaconda3\envs\baselines\lib\multiprocessing\context.py", line 223, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)

  File "...\Anaconda3\envs\baselines\lib\multiprocessing\context.py", line 322, in _Popen
    return Popen(process_obj)

  File "...\Anaconda3\envs\baselines\lib\multiprocessing\popen_spawn_win32.py", line 89, in __init__
    reduction.dump(process_obj, to_child)

  File "...\Anaconda3\envs\baselines\lib\multiprocessing\reduction.py", line 60, in dump
    ForkingPickler(file, protocol).dump(obj)

BrokenPipeError: [Errno 32] Broken pipe

Code

import gym
from stable_baselines import GAIL, SAC
from stable_baselines.gail import ExpertDataset, generate_expert_traj

def main():
    # Generate expert trajectories (train expert)
    model = SAC('MlpPolicy', 'Pendulum-v0', verbose=1)
    generate_expert_traj(model, 'expert_pendulum', n_timesteps=100, n_episodes=10)

    # Load the expert dataset
    dataset = ExpertDataset(expert_path='expert_pendulum.npz', traj_limitation=10, verbose=1)

    model = GAIL("MlpPolicy", 'Pendulum-v0', dataset, verbose=1)
    # Note: in practice, you need to train for 1M steps to have a working policy
    model.learn(total_timesteps=1000)
    model.save("gail_pendulum")

    del model # remove to demonstrate saving and loading

    model = GAIL.load("gail_pendulum")

    env = gym.make('Pendulum-v0')
    obs = env.reset()
    while True:
        action, _states = model.predict(obs)
        obs, rewards, dones, info = env.step(action)
        env.render()

    return

if __name__ == '__main__':
    main()

System Info

ThibaultFy commented 4 years ago

Am I the only one having this issue?..

ThibaultFy commented 4 years ago

I fix my error lauching the code directly from the console. The bug seem to come from IPython in the Spyder interface.

Source: https://stackoverflow.com/questions/57626939/how-to-fix-the-broken-pipe-error-in-the-following-code

nisaaf03 commented 1 year ago

I'm having the same problem as you. Thanks for opened this issue.