microsoft / jericho

A learning environment for man-made Interactive Fiction games.
GNU General Public License v2.0
257 stars 42 forks source link

Support multiple instances of Jericho #23

Closed MarcCote closed 4 years ago

MarcCote commented 4 years ago

This PR adds support for playing multiple games in parallel. To achieve this, each instance of FrotzEnv has its own local version of libfrotz.so.

MarcCote commented 4 years ago

Rebased.

xingdi-eric-yuan commented 4 years ago

I saw this error and I think it might be caused by this PR:

    File "train_rl.py", line 360, in <module>
      train()
    File "train_rl.py", line 106, in train
      obs, infos = env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/gym/envs/batch_env.py", line 229, in reset
      results = [env.reset() for env in self.envs]
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/gym/envs/batch_env.py", line 229, in <listcomp>
      results = [env.reset() for env in self.envs]
    File "/tmp/twkg/lib/python3.6/site-packages/gym/wrappers/time_limit.py", line 25, in reset
      return self.env.reset(**kwargs)
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/gym/envs/textworld_games_env.py", line 112, in reset
      self.ob, infos = self.textworld_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/envs/wrappers/filter.py", line 52, in reset
      game_state = super().reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/core.py", line 306, in reset
      return self._wrapped_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/core.py", line 306, in reset
      return self._wrapped_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/envs/wrappers/tw_inform7.py", line 238, in reset
      self.state = self._wrapped_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/envs/wrappers/tw_inform7.py", line 140, in reset
      self.state = self._wrapped_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/envs/wrappers/tw_inform7.py", line 304, in reset
      self.state = self._wrapped_env.reset()
    File "/tmp/twkg/lib/python3.6/site-packages/textworld/envs/zmachine/jericho.py", line 75, in reset
      self._jericho = jericho.FrotzEnv(self.gamefile, self._seed)
    File "/tmp/twkg/lib/python3.6/site-packages/jericho/jericho.py", line 314, in __init__
      self.frotz_lib = load_frotz_lib()
    File "/tmp/twkg/lib/python3.6/site-packages/jericho/jericho.py", line 196, in load_frotz_lib
      frotz_lib = cdll.LoadLibrary(frotz_lib_path)
    File "/tmp/twkg/lib/python3.6/ctypes/__init__.py", line 426, in LoadLibrary
      return self._dlltype(name)
    File "/tmp/twkg/lib/python3.6/ctypes/__init__.py", line 348, in __init__
      self._handle = _dlopen(self._name, mode)
    OSError: /tmp/tmpy439op20/libfrotz.so: cannot map zero-fill pages
mhauskn commented 4 years ago

Thanks Eric! Some searching indicates this error may occur when out of memory. Does this sounds like it could be the case?

@MarcCote Textworld seems to be creating a new Jericho environment on each reset, rather than using Jericho's reset() call. Presumably since Jericho is now threadsafe this snippet could be updated.

MarcCote commented 4 years ago

Good point. But that wouldn't help in the case were we change game at every reset. There's probably some memory cleaning regarding the .so resource that need to be done when deleting a FrotzEnv. I'll look into it later today if I have time.

xingdi-eric-yuan commented 4 years ago

Yeah this always happens after running ~12000 games. For now I'll just use commit 545aabf93cc38d56e4e9565c2bceb227e6a95020, which didn't have such issue.

MarcCote commented 4 years ago

@xingdi-eric-yuan do you mind giving #24 a try?

xingdi-eric-yuan commented 4 years ago

I'll try it and let you know