feat: pass randomness keys to environment steps - #311
quinnarnold wants to merge 2 commits into
Conversation
sash-a
left a comment
There was a problem hiding this comment.
This is such a huge break in the API that I feel we'd need more careful planning and an agreed upon approach to merge this.
key's aren't truly optional here, e.g in 2048 if the key is none you raise an error. For this to be merged we'd really want a way to keep the existing functionality (using the state's key) as the default and allow passing the key as an option.
This is quite tricky in JAX. If we do a cond it's more computational work and if we have an if this will silently fail if you use the same jitted function when passing a key vs using the state's key.
|
Thanks, I agree the compatibility contract needs clarification before I revise this further. The current implementation breaks existing callers despite the optional signature, including in I’d propose keeping On the JIT concern, I checked a minimal function using Would this backward-compatible scope be acceptable? The remaining design question is how an explicit key determines the returned state key and any automatic reset, so switching between the two calling forms has defined behavior. I’ll hold further edits pending your feedback on that direction. |
|
Ok I just tested that if and it does seem to work, I thought it wouldn't. Then I am happy to go through with this using state.key if key isn't passed and using the key argument if it is |
Summary
Allow callers to resample a stochastic successor with
env.step(state, action, key), while preserving the existing behavior ofenv.step(state, action).For stochastic environments, an explicit key replaces
state.keyusing the environment’s existing splitting and returned-state key behavior. Deterministic environments accept and may ignore the optional key. Wrappers forward it;AutoResetWrappercontinues to derive reset randomness from the returned state key.State.keyremains in place. Existing training callers, examples, and Gym/DMEnv adapters retain their calling conventions. Merged currentmainand resolved the shared helper/fake conflicts while preserving upstream changes.Closes #211.
Validation
mainpassed for all seven stochastic environments: default calls match upstream, supplied keys act independently of the old stored key, and switching explicit/default calls through JIT works. Wrapper, batched, and terminal automatic-reset checks passed.AI-assisted implementation and validation.