Make Othello starting-player tests RNG-version-agnostic#1325
Open
gweber wants to merge 1 commit into
Open
Conversation
The bernoulli coin flip that picks the starting player in Othello._init is not stable across jax.random versions, so tests that hard-coded the outcome of a specific PRNGKey (via a double split chosen to land on current_player==0) broke on newer JAX. Replace that with a small _init_with_current_player(player) helper that searches keys for the desired starting player, keeping every downstream board/reward/observation assertion deterministic on any JAX version. Verified on jax 0.4.30 and jax 0.10.1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Make Othello's starting-player-dependent tests RNG-version-agnostic
Four tests in
tests/test_othello.py(test_init,test_terminated,test_legal_action,test_observe) hard-coded the outcome of the starting-playercoin flip in
Othello._init(current_player = bernoulli(key)). They picked aspecific
PRNGKey— via a doublejax.random.splitchosen to land oncurrent_player == 0— and then made absolute board/reward/observation assertionskeyed to that player.
The exact
bernoulliresult for a given key is not stable acrossjax.randomversions, so on newer JAX (e.g. 0.10.x) the flip returns
1and all four testsfail, even though the environment logic is unchanged and correct.
This replaces the brittle key-hunting with a small helper that searches keys for
the desired starting player:
Every downstream assertion is unchanged and fully deterministic once the starting
player is fixed (board indices and outcomes don't depend on the RNG). No
environment/runtime code is touched — tests only.
Validation
Ran
tests/test_othello.pyon jax 0.4.30 and jax 0.10.1: the four testspass on both. (On 0.10.x a separate, unrelated
test_apifailure remains, causedby an
IndexErrorinsidepgx.api_test/baseline infra — out of scope here.)