Skip to content

Commit 637988c

Browse files
authored
Fix Atari wrapper bug: tried to step environment that needs reset (#1297)
* fix 1060 * update changelog
1 parent b702884 commit 637988c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

docs/misc/changelog.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ New Features:
2323

2424
Bug Fixes:
2525
^^^^^^^^^^
26+
- Fixed Atari wrapper that missed the reset condition (@luizapozzobon)
2627

2728
Deprecations:
2829
^^^^^^^^^^^^^
@@ -1218,4 +1219,4 @@ And all the contributors:
12181219
@Gregwar @ycheng517 @quantitative-technologies @bcollazo @git-thor @TibiGG @cool-RR @MWeltevrede
12191220
@Melanol @qgallouedec @francescoluciano @jlp-ue @burakdmb @timothe-chaumont @honglu2875 @yuanmingqi
12201221
@anand-bala @hughperkins @sidney-tio @AlexPasqua @dominicgkerr @Akhilez @Rocamonde @tobirohrer @ZikangXiong
1221-
@DavyMorgan
1222+
@DavyMorgan @luizapozzobon

stable_baselines3/common/atari_wrappers.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ def reset(self, **kwargs) -> np.ndarray:
106106
obs = self.env.reset(**kwargs)
107107
else:
108108
# no-op step to advance from terminal/lost life state
109-
obs, _, _, _ = self.env.step(0)
109+
obs, _, done, _ = self.env.step(0)
110+
111+
# The no-op step can lead to a game over, so we need to check it again
112+
# to see if we should reset the environment and avoid the
113+
# monitor.py `RuntimeError: Tried to step environment that needs reset`
114+
if done:
115+
obs = self.env.reset(**kwargs)
110116
self.lives = self.env.unwrapped.ale.lives()
111117
return obs
112118

@@ -150,9 +156,6 @@ def step(self, action: int) -> GymStepReturn:
150156

151157
return max_frame, total_reward, done, info
152158

153-
def reset(self, **kwargs) -> GymObs:
154-
return self.env.reset(**kwargs)
155-
156159

157160
class ClipRewardEnv(gym.RewardWrapper):
158161
"""

0 commit comments

Comments
 (0)