Kautenja / gym-super-mario-bros

An OpenAI Gym interface to Super Mario Bros. & Super Mario Bros. 2 (Lost Levels) on The NES

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

smb_env.py:148: RuntimeWarning: overflow encountered in ubyte_scalars

dkuku opened this issue · comments

Describe the bug

I created a new venv and my training crashes straight away on the default script:

 mario-gym  gym_super_mario_bros -e SuperMarioBros-v0 -m random
 59%|█████████████▌         | 296/500 [00:01<00:01, 171.89it/s, info={'coins': 0, 'flag_get': False, 'life': 2, 'score': 0, 'stage': 1, 'status': 'small', 'time': 392, 'world': 1, 'x_pos': 254, 'x_pos_screen': 112, 'y_pos': 88}, reward=2]
/home/kuku/MachineLearning/mario-gym/.direnv/python-3.7.4/lib/python3.7/site-packages/gym_super_mario_bros/smb_env.py:148: RuntimeWarning: overflow encountered in ubyte_scalars
  return (self.ram[0x86] - self.ram[0x071c]) % 256
100%|█████████████████████| 500/500 [00:02<00:00, 169.35it/s, info={'coins': 0, 'flag_get': False, 'life': 2, 'score': 100, 'stage': 1, 'status': 'small', 'time': 387, 'world': 1, 'x_pos': 423, 'x_pos_screen': 112, 'y_pos': 93}, reward=2]
 mario-gym  gym_super_mario_bros -e SuperMarioBros-v0 -m random
 82%|██████████████████▊    | 409/500 [00:02<00:00, 173.24it/s, info={'coins': 0, 'flag_get': False, 'life': 2, 'score': 0, 'stage': 1, 'status': 'small', 'time': 389, 'world': 1, 'x_pos': 255, 'x_pos_screen': 112, 'y_pos': 93}, reward=2]
/home/kuku/MachineLearning/mario-gym/.direnv/python-3.7.4/lib/python3.7/site-packages/gym_super_mario_bros/smb_env.py:148: RuntimeWarning: overflow encountered in ubyte_scalars
  return (self.ram[0x86] - self.ram[0x071c]) % 256
100%|█████████████████████| 500/500 [00:02<00:00, 170.77it/s, info={'coins': 0, 'flag_get': False, 'life': 2, 'score': 100, 'stage': 1, 'status': 'small', 'time': 387, 'world': 1, 'x_pos': 314, 'x_pos_screen': 112, 'y_pos': 97}, reward=2]
 mario-gym  

A clear and concise description of what the bug is.

Reproduction Script

gym_super_mario_bros -e SuperMarioBros-v0 -m random

I can't reproduce the issue, but this would seem to occur when subtracting a uint8 value from another uint8 value that is smaller, i.e., a - b where b > a. A simple workaround is to wrap the uint8 operands with python int types, but i'm not sure how this would affect the output of the environment. Can you inject the suspected fix into your codefile and see if it resolves?

(self.ram[0x86] - self.ram[0x071c]) % 256

would become

np.uint8(int(self.ram[0x86]) - int(self.ram[0x071c])) % 256

the _left_x_position parameter is never called in the logic of the current version of nes-py, so i'm not sure how you're coming about this error. I've added the suggested fix for if anyone uses the value in subclasses or through indirect access to the environment.