-
Notifications
You must be signed in to change notification settings - Fork 186
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
Game freezing / general robustness to wrapped game engine #161
Comments
Thank you for reporting this issue. I'm not surprised Jericho would have the same issue since TextWorld uses Jericho under the hood. If I remember correctly, I think @mhauskn is aware of that issue but I don't know if we had a solution for it? |
Here's an attempt to recreate the issue in Jericho alone: from jericho import *
import itertools
import tqdm
import numpy as np
np.random.seed(0)
episodes = 50
episode_len = 500
ROM='/home/mahauskn/workspace/text-agents/roms/balances.z5'
scores = []
for episode in range(episodes):
print('episode {}'.format(episode))
env = FrotzEnv(ROM, 0)
env.reset()
verbs = [w.word for w in env.get_dictionary() if w.is_verb]
nouns = [w.word for w in env.get_dictionary() if w.is_noun]
actions = [' '.join(tup) for tup in list(itertools.product(verbs, nouns))]
for step in tqdm.trange(episode_len):
act = np.random.choice(actions)
print(step, act)
game_state, score, done, _ = env.step(act)
if done:
break
scores.append(score)
print(scores) Running this script I observe a Fatal error:
Is this consistent with what you're seeing @vzhong? |
I've verified that the same behavior is present in the Frotz (the base emulator used by Jericho) and have filed an issue there (https://gitlab.com/DavidGriffith/frotz/issues/111). It's a valid point that RL environments shouldn't hang or produce fatal errors for what should be valid actions. |
Hey @mhauskn , there are a variety of ways in which these failures can manifest. I haven't seen I'm not even certain that the problem lies in Frotz. We are wrapping environments (textworld) around environments (Jericho) around environments (Frotz) around environments (ZMachine). There are probably fatal bugs in ZMachine (which is not written to support randomly behaving RL agents), and it's probably overly optimistic to hope to get those fixed. The problem for TextWorld users is that this kills the entire Python stack, which is not ideal for RL. It's probably useful to do something on the TextWorld end to handle these failure cases. One simulator-agnostic way is to wrap the simulator (e.g. Jericho or Frotz) in a separate process, such that one can issue time-out-attached commands to the simulator. The simulator can fail/time out, but this does not affect TextWorld. When these events happen, TextWorld can just tell the user that the simulator died and the user can decide what they want to do (e.g. discard the trajectory, assign a negative reward for killing the simulator). |
I've updated Jericho (now version 1.2.0) to avoid the Python stack crashing when a game encounters a fatal error. Instead the episode will be reported as over and the emulator status will be marked as halted. This change should address the issue with Balances, but will not fix games that hang or segfault. Running your script across all supported Jericho games revealed 2 hangs and 3 fatal errors. The 3 fatal errors should be addressed by this update, but for now I'd advise avoiding the showverb command that causes hangs in the other 2 games. Please open issues with Jericho if you encounter other hangs or segfaults. |
Thank you @mhauskn !! I'll take a look soon |
Thanks @mhauskn, now I'll need to think what's the best way to expose that information in TextWorld. Regarding the hangs, what @vzhong proposes (wrapping a subprocess) is probably the safest way to do it but the drawback is the overhead over inter-multiprocess communications. If I remember correctly Jericho's main focus is speed. That said, in TextWorld we are already using subprocesses that to handle communications with the git-glulx interpreter, so we could also do it for Jericho. |
I'm avoiding implementing subprocess wrapping in Jericho for now. My hope is that segfaults + hangs can be fixed. If fixing segfaults/hangs turns out not to be feasible, then I may reconsider in the future. That said, I totally understand if TW wants to subprocess-wrap Jericho for added safety. |
I've noticed that when randomly sampling actions in real text games (e.g. ZMachine games not generated by TextWorld), the game inevitably freezes/segfaults at some point (It seems like Jericho has the same issue). Since TextWorld is a RL environment for text games, can we make it more robust to these problems? For example, having a timeout failure or game crashed failure?
Here's a code snippet that consistently freezes on my machine:
The text was updated successfully, but these errors were encountered: