toybox-rs / Toybox

The Machine Learning Toybox for testing the behavior of autonomous agents.
http://toybox.rs
27 stars 12 forks source link

Is Pong available? #183

Open yxie20 opened 3 years ago

yxie20 commented 3 years ago

Hello! I would love to use Pong with Toybox.

I noticed that there is an implementation in toybox-rs, but it is not registered correctly with gym (unlike Amidar, Breakout, etc.). Is there something I can do to get it to run with gym api?

Thanks!

jjfiv commented 3 years ago

The two steps for this are:

  1. to subclass ToyboxBaseEnv:

https://github.com/toybox-rs/Toybox/blob/2b270d61188659bb8a1c9f436cfc03cddcc7a52c/toybox/envs/atari/breakout.py#L6-L11

  1. to register with gym

https://github.com/toybox-rs/Toybox/blob/2b270d61188659bb8a1c9f436cfc03cddcc7a52c/toybox/__init__.py#L5-L12

We tried to follow the naming conventions of Atari in gym, but it wouldn't be necessary to get it running, unless, like openai-baselines, your libraries apply wrappers based on the environment name.

This will be added, maybe by the end of the week? It's a simple patch, but we're currently debugging our actions integration after ridding ourselves of the openai-baselines/tensorflow 1.x dependency (#181,#182).

yxie20 commented 3 years ago

Thanks! I followed the steps above and got this error:

>>> env_id = "PongToyboxNoFrameskip-v4"
>>> env = gym.make(env_id)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/gym/envs/registration.py", line 145, in make
    return registry.make(id, **kwargs)
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/gym/envs/registration.py", line 90, in make
    env = spec.make(**kwargs)
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/gym/envs/registration.py", line 60, in make
    env = cls(**_kwargs)
  File "/gpfs/data/mlittman/ubuntu/Toybox/toybox/envs/atari/pong.py", line 8, in __init__
    super().__init__(Toybox('pong', grayscale),
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/ctoybox/ffi.py", line 360, in __init__
    self.rsimulator = Simulator(game_name)
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/ctoybox/ffi.py", line 90, in __init__
    sim = _handle_ffi_result(lib.simulator_alloc(game_name.encode("utf-8")))
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/ctoybox/ffi.py", line 52, in _handle_ffi_result
    _raise_error_str(error)
  File "/users/ubuntu/anaconda/torchbeast/lib/python3.7/site-packages/ctoybox/ffi.py", line 27, in _raise_error_str
    raise ValueError("{0}: {1}".format(response["error"], response["context"]))
ValueError: error: "Cannot construct game: `pong`. Try any of [\"amidar\", \"breakout\", \"space_invaders\", \"gridworld\"]."
jjfiv commented 3 years ago

Your ctoybox is probably from before we had Pong...

I suspect this wouldn't work, either? (human_play goes through those same functions to get the game).

pip install pygame && python -m ctoybox.human_play pong

If so, you can just:

pip install --upgrade ctoybox