Farama-Foundation / SuperSuit

A collection of wrappers for Gymnasium and PettingZoo environments (being merged into gymnasium.wrappers and pettingzoo.wrappers
Other
446 stars 56 forks source link

Problem with ss.concat_vec_envs_v1() #171

Closed Stelath closed 2 years ago

Stelath commented 2 years ago

supersuit.concat_vec_envs_v1(env, 8, num_cpus=4, base_class="stable_baselines3") Seems to be throwing an error on my M1 Pro Mac, I've looked at past issues that encountered this error on Windows which I know isn't officially supported. Is apple's arm hardware supported or only x86 chipsets? If Arm is supported as well, any ideas what could be causing this problem?

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.
Exception ignored in: <function ProcConcatVec.__del__ at 0x15948c940>
Traceback (most recent call last):
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/site-packages/supersuit/vector/multiproc_vec.py", line 217, in __del__
    for pipe in self.pipes:
AttributeError: 'ProcConcatVec' object has no attribute 'pipes'
^CTraceback (most recent call last):
  File "/Users/alexanderkorte/Documents/GitHub/stable-baselines-learning/piston_ball/piston_ball_train.py", line 22, in <module>
    env = ss.concat_vec_envs_v1(env, 8, num_cpus=4, base_class="stable_baselines3")
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/site-packages/supersuit/vector/vector_constructors.py", line 60, in concat_vec_envs_v1
    vec_env = MakeCPUAsyncConstructor(num_cpus)(*vec_env_args(vec_env, num_vec_envs))
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/site-packages/supersuit/vector/constructors.py", line 36, in constructor
    return ProcConcatVec(
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/site-packages/supersuit/vector/multiproc_vec.py", line 151, in __init__
    proc.start()
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 62, in _launch
    f.write(fp.getbuffer())
KeyboardInterrupt
Exception ignored in: <function ProcConcatVec.__del__ at 0x157311b80>
Traceback (most recent call last):
  File "/Users/alexanderkorte/miniforge3/envs/ml/lib/python3.9/site-packages/supersuit/vector/multiproc_vec.py", line 217, in __del__
    for pipe in self.pipes:
AttributeError: 'ProcConcatVec' object has no attribute 'pipes'
jjshoots commented 2 years ago

There is no official support for M1 yet unfortunately, so its behaviour is a bit undefined. Support for Mac only goes as far as x86 for OSX.

benblack769 commented 2 years ago

@jjshoots I believe MacOS is trying to move away from supporting fork in general, due to various bugs on the platform and windows has never supported it. Might be good to change the tutorial to one with proper support for process spawning, such as the one I commented here https://github.com/Farama-Foundation/PettingZoo/issues/710, so this issue doesn't come up again.

jjshoots commented 2 years ago

Tutorial updated. If I understand things correctly, you just need to do the thing that the error message has shown

if __name__ == "__main__":
   ...