AgileRL / AgileRL

Streamlining reinforcement learning with RLOps. State-of-the-art RL algorithms and tools.
https://agilerl.com
Apache License 2.0
589 stars 45 forks source link

Broken Pipeline Error when creating an environement #235

Closed sryu1 closed 4 months ago

sryu1 commented 4 months ago

What version of AgileRL are you using?

1.0.0

What operating system and processor architecture are you using?

Windows 11 x64

What did you do? Steps to reproduce the behaviour:

  1. Use the example provided in docs for gymnasium single agent tutorial
  2. In cell 1, add jsbgym
  3. Click on change discrete to False in the second cell
  4. Change env name to "J3-HeadingControlTask-Shaping.STANDARD-NoFG-v0"
  5. See error

What did you expect to see? No output

What did you see instead? Describe the bug.

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\multiprocessing\connection.py:328 in _recv_bytes       │
│                                                                                                  │
│   325 │   │   │   │   │   │   ov.cancel()                                                        │
│   326 │   │   │   │   │   │   raise                                                              │
│   327 │   │   │   │   │   finally:                                                               │
│ ❱ 328 │   │   │   │   │   │   nread, err = ov.GetOverlappedResult(True)                          │
│   329 │   │   │   │   │   │   if err == 0:                                                       │
│   330 │   │   │   │   │   │   │   f = io.BytesIO()                                               │
│   331 │   │   │   │   │   │   │   f.write(ov.getbuffer())                                        │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
BrokenPipeError: [WinError 109] The pipe has been ended

During handling of the above exception, another exception occurred:

╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:2                                                                                    │
│                                                                                                  │
│    1 num_envs=10                                                                                 │
│ ❱  2 env = make_vect_envs("J3-HeadingControlTask-Shaping.STANDARD-NoFG-v0", num_envs=num_envs    │
│    3 try:                                                                                        │
│    4 │   state_dim = env.single_observation_space.n  # Discrete observation space                │
│    5 │   one_hot = True  # Requires one-hot encoding                                             │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\site-packages\agilerl\utils\utils.py:26 in             │
│ make_vect_envs                                                                                   │
│                                                                                                  │
│    23 │   :param num_envs: Number of vectorized environments, defaults to 1                      │
│    24 │   :type num_envs: int, optional                                                          │
│    25 │   """                                                                                    │
│ ❱  26 │   return gym.vector.AsyncVectorEnv(                                                      │
│    27 │   │   [lambda: gym.make(env_name) for i in range(num_envs)]                              │
│    28 │   )                                                                                      │
│    29                                                                                            │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\site-packages\gymnasium\vector\async_vector_env.py:169 │
│ in __init__                                                                                      │
│                                                                                                  │
│   166 │   │   │   │   child_pipe.close()                                                         │
│   167 │   │                                                                                      │
│   168 │   │   self._state = AsyncState.DEFAULT                                                   │
│ ❱ 169 │   │   self._check_spaces()                                                               │
│   170 │                                                                                          │
│   171 │   def reset_async(                                                                       │
│   172 │   │   self,                                                                              │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\site-packages\gymnasium\vector\async_vector_env.py:504 │
│ in _check_spaces                                                                                 │
│                                                                                                  │
│   501 │   │   spaces = (self.single_observation_space, self.single_action_space)                 │
│   502 │   │   for pipe in self.parent_pipes:                                                     │
│   503 │   │   │   pipe.send(("_check_spaces", spaces))                                           │
│ ❱ 504 │   │   results, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])             │
│   505 │   │   self._raise_if_errors(successes)                                                   │
│   506 │   │   same_observation_spaces, same_action_spaces = zip(*results)                        │
│   507 │   │   if not all(same_observation_spaces):                                               │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\site-packages\gymnasium\vector\async_vector_env.py:504 │
│ in <listcomp>                                                                                    │
│                                                                                                  │
│   501 │   │   spaces = (self.single_observation_space, self.single_action_space)                 │
│   502 │   │   for pipe in self.parent_pipes:                                                     │
│   503 │   │   │   pipe.send(("_check_spaces", spaces))                                           │
│ ❱ 504 │   │   results, successes = zip(*[pipe.recv() for pipe in self.parent_pipes])             │
│   505 │   │   self._raise_if_errors(successes)                                                   │
│   506 │   │   same_observation_spaces, same_action_spaces = zip(*results)                        │
│   507 │   │   if not all(same_observation_spaces):                                               │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\multiprocessing\connection.py:250 in recv              │
│                                                                                                  │
│   247 │   │   """Receive a (picklable) object"""                                                 │
│   248 │   │   self._check_closed()                                                               │
│   249 │   │   self._check_readable()                                                             │
│ ❱ 250 │   │   buf = self._recv_bytes()                                                           │
│   251 │   │   return _ForkingPickler.loads(buf.getbuffer())                                      │
│   252 │                                                                                          │
│   253 │   def poll(self, timeout=0.0):                                                           │
│                                                                                                  │
│ C:\Users\noahs\miniconda3\envs\jgtest\Lib\multiprocessing\connection.py:337 in _recv_bytes       │
│                                                                                                  │
│   334 │   │   │   │   │   │   │   return self._get_more_data(ov, maxsize)                        │
│   335 │   │   │   │   except OSError as e:                                                       │
│   336 │   │   │   │   │   if e.winerror == _winapi.ERROR_BROKEN_PIPE:                            │
│ ❱ 337 │   │   │   │   │   │   raise EOFError                                                     │
│   338 │   │   │   │   │   else:                                                                  │
│   339 │   │   │   │   │   │   raise                                                              │
│   340 │   │   │   raise RuntimeError("shouldn't get here; expected KeyboardInterrupt")           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
EOFError

Additional context Exact same code works in Linux. Is this a problem of the custom env library? Other envs such as CartPole-v1 and MountainCar-v0 works in Windows...

nicku-a commented 4 months ago

I'm not able to replicate your error, but I'm running on Linux. You could try running gym.make("J3-HeadingControlTask-Shaping.STANDARD-NoFG-v0") to see if you can get more information on what causes the error.

In any case, if you have a Windows PC, it is better to install and use WSL (Windows Subsystem for Linux) instead. It essentially lets you run a Linux OS on your Windows computer. It's highly recommended for any development work, which naturally lends itself to Linux over Windows: https://learn.microsoft.com/en-us/windows/wsl/install

It's very straightforward; just run wsl --install, and then within the Ubuntu terminal install Python, agilerl, etc.