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

Fix Pistonball to only render if render_mode is not None #1014

Merged

Conversation

elliottower
Copy link
Contributor

Description

This fixes a minor bug with Pistonball where the underlying environment code still uses PyGame surfaces and does the mechanism of rendering, even if render_mode is set to none. This causes a problem when trying to train with SB3, as pygame surfaces don't work well with multithreading (pygame.error: Surfaces must not be locked during blit). Also should speed up training in any setting.

Fixes # (issue), Depends on # (pull request)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots

Please attach before and after screenshots of the change if applicable.
To upload images to a PR -- simply drag and drop or copy paste.

Checklist:

  • I have run the pre-commit checks with pre-commit run --all-files (see CONTRIBUTING.md instructions to set it up)
  • I have run pytest -v and no errors are present.
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I solved any possible warnings that pytest -v has generated that are related to my code to the best of my knowledge.
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@elliottower
Copy link
Contributor Author

elliottower commented Jul 6, 2023

One problem I found, when calling env.close() on a ProcConcatVec env, I get this error:

Traceback (most recent call last):
  File "/mnt/d/GitHub/SuperSuit/supersuit/vector/multiproc_vec.py", line 65, in async_loop
    instr = pipe.recv()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 379, in _recv
    chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/d/GitHub/SuperSuit/supersuit/vector/multiproc_vec.py", line 114, in async_loop
    pipe.send((e, tb))
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 411, in _send_bytes
    self._send(header + buf)
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe

I tried messing around with pipe.close() and some other multiprocessing things I found on google but it didn't seem to work. If I don't try to call one of these, the program never ends because of the async_loop in multiproc_vec.py. Even if I call sys.exit(0), it still doesn't exit, because of the other threads. This seems like the subject of another PR though.

@elliottower
Copy link
Contributor Author

One problem I found, when calling env.close() on a ProcConcatVec env, I get this error:

Traceback (most recent call last):
  File "/mnt/d/GitHub/SuperSuit/supersuit/vector/multiproc_vec.py", line 65, in async_loop
    instr = pipe.recv()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 250, in recv
    buf = self._recv_bytes()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 414, in _recv_bytes
    buf = self._recv(4)
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 379, in _recv
    chunk = read(handle, remaining)
ConnectionResetError: [Errno 104] Connection reset by peer

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    self.run()
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/process.py", line 108, in run
    self._target(*self._args, **self._kwargs)
  File "/mnt/d/GitHub/SuperSuit/supersuit/vector/multiproc_vec.py", line 114, in async_loop
    pipe.send((e, tb))
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 206, in send
    self._send_bytes(_ForkingPickler.dumps(obj))
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 411, in _send_bytes
    self._send(header + buf)
  File "/home/elliot/anaconda3/envs/pettingzoo/lib/python3.9/multiprocessing/connection.py", line 368, in _send
    n = write(self._handle, buf)
BrokenPipeError: [Errno 32] Broken pipe

I tried messing around with pipe.close() and some other multiprocessing things I found on google but it didn't seem to work. If I don't try to call one of these, the program never ends because of the async_loop in multiproc_vec.py. Even if I call sys.exit(0), it still doesn't exit, because of the other threads. This seems like the subject of another PR though.

This will have to be a separate PR I think, and is more related to SuperSuit and the close() method, so will likely be there instead of here

@elliottower elliottower merged commit 2926e8a into Farama-Foundation:master Jul 7, 2023
@elliottower elliottower deleted the pistonball-render-bug branch July 7, 2023 04:34
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

Successfully merging this pull request may close these issues.

1 participant