-
Notifications
You must be signed in to change notification settings - Fork 45
Make the walkthrough seed opt-in: unseeded FrotzEnv is stochastic (v4.0) #88
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
Merged
Marc-Alexandre Côté (MarcCote)
merged 3 commits into
microsoft:master
from
abahgat:implicit-seed-optin
Aug 14, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| __version__ = '3.3.1' | ||
| __version__ = '4.0.0' |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Open question: the
-1sentinel makes the emulator seed itself fromtime(0) & 0x7fff(seeos_random_seedindumb_init.c), i.e. one-second resolution and a 15-bit space. Unseeded envs created in the same second play identical episodes, which particularly affects parallel and vectorized runs, arguably the main audience for stochastic-by-default. I've documented the caveat in the README for now, but a stronger fix would be resolvingseed=Noneon the Python side (e.g. fromos.urandom) into a concrete random seed and passing that down, which also makes the episode's seed inspectable after the fact. That changes the meaning of the-1sentinel though, so I left it out of this PR. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. I like your proposed idea, dealing with it on the Python does make things more reproducible, we should also probably display which seed was obtained from Python's RNG and used to seed the z-machine. If you can implement this, that would be awesome.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, can you PTAL?
Unseeded envs now draw a new 31-bit seed per episode on the Python side, so
-1never reaches the emulator and same-second envs no longer collide. The selected seed is surfaced in three places:FrotzEnv.episode_seedproperty,seedkey inreset()'s info dict,ImplicitRandomSeedWarningmessageThe goal is to make any episode reproducible after the fact with
FrotzEnv(rom, seed=env.episode_seed).There's one deviation from the "Python's RNG" suggestion in the comment above: seeds are drawn from
random.SystemRandom(backed by OS entropy) rather than the globalrandommodule.Two reasons:
get_valid_actions(use_parallel=True)forks workers viamp.Pool, and forked processes inherit the global Mersenne state: every worker would draw the same "random" seed, reintroducing the exact collision this change fixes.random.seed(0)from silently turning "stochastic" envs deterministic, which felt like the same "unexpected determinism" pitfall as Silent fixed-seed default prevents independent runs for most games. Consider adding a warning? #84.The cost is that unseeded episodes aren't reproducible via global seeding. I think that's acceptable, given what we gain, and ultimately, that's what
episode_seedis for. However, let me know if you disagree or you'd like to take this in a different direction.I kept
-1as the documented "explicitly stochastic" sentinel (it now means "draw a random seed per episode" rather than "let the emulator use the clock"), since the warning message and docs already point users at it. I tried to update all comments accordingly, but please let me know if I missed any.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's reasonable. Thank you again for the PR.