Skip to content

Reject degenerate stochastic frameskip (n, n) at construction instead of crashing in step()#710

Open
teddytennant wants to merge 1 commit into
Farama-Foundation:mainfrom
teddytennant:fix-degenerate-stochastic-frameskip
Open

Reject degenerate stochastic frameskip (n, n) at construction instead of crashing in step()#710
teddytennant wants to merge 1 commit into
Farama-Foundation:mainfrom
teddytennant:fix-degenerate-stochastic-frameskip

Conversation

@teddytennant

Copy link
Copy Markdown

What

Tighten the stochastic-frameskip validation in AtariEnv.__init__ so a degenerate equal-bounds tuple such as (4, 4) is rejected at construction, and fix a copy-paste error in one of the validation messages.

Why

The validation only rejected reversed bounds (frameskip[0] > frameskip[1]), so an equal-bounds tuple like (4, 4) passed. At step time, step() calls self.np_random.integers(*self._frameskip), and numpy's integers() samples from the half-open interval [low, high). With low == high that range is empty and raises ValueError: low >= high.

The upshot is that AtariEnv("Pong", frameskip=(4, 4)) and reset() succeed, then the very first step() dies with a cryptic numpy error that doesn't obviously point back to the frameskip argument the user passed.

Changing the comparison to >= makes the invalid (empty) range fail fast at construction, consistent with the half-open sampling used in step(). I also fixed the message on the frameskip[0] <= 0 branch, which duplicated the bound-ordering text instead of describing the positive-lower-bound requirement.

Testing

Added the degenerate (4, 4) case to the existing test_frameskip_warnings parametrization, which asserts that construction raises gymnasium.error.Error. The new case fails before this change (construction proceeds past validation) and passes after it.

python -m pytest tests/python/test_atari_env.py::test_frameskip_warnings -q
8 passed

Copilot AI review requested due to automatic review settings July 8, 2026 21:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@jkterry1

Copy link
Copy Markdown
Member

@teddytennant could you please rebase off main?

The stochastic-frameskip validation in AtariEnv.__init__ only rejected
reversed bounds (frameskip[0] > frameskip[1]), so an equal-bounds tuple
such as (4, 4) passed validation. step() then calls
self.np_random.integers(*self._frameskip), and numpy's integers() samples
from the half-open interval [low, high); with low == high that range is
empty and raises "ValueError: low >= high". The result was that
construction and reset succeeded but the first step() died with a cryptic
numpy error unrelated on its face to the frameskip argument.

Tighten the check to frameskip[0] >= frameskip[1] so an empty range fails
fast at construction, and fix the copy-paste error in the lower-bound
message (it previously duplicated the bound-ordering text).
@teddytennant teddytennant force-pushed the fix-degenerate-stochastic-frameskip branch from cc8d7b1 to 104f7a1 Compare July 13, 2026 12:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants