Skip to content

Forward the reset seed and implement VecEnv.seed - #265

Open
eliasnaha wants to merge 3 commits into
edbeeching:mainfrom
eliasnaha:forward-reset-seed
Open

eliasnaha wants to merge 3 commits into
edbeeching:mainfrom
eliasnaha:forward-reset-seed

Conversation

@eliasnaha

Copy link
Copy Markdown

Two related gaps in seeding.

GodotEnv.reset accepts a seed and drops it. The reset message is built without it, so gymnasium style reseeding on reset is silently a no op:

def reset(self, seed=None):
    message = {
        "type": "reset",
    }

StableBaselinesGodotEnv.seed raises NotImplementedError. sb3 calls env.seed() when an algorithm is built with a seed, so PPO(..., seed=0) on a godot env crashes rather than training.

reset now sends the seed with the reset message, and the wrapper latches one seed per parallel game using the same seed + p offsets the constructor already uses, applied on the next reset and cleared afterwards, which is how sb3's own vec envs behave.

The wire change is additive. The current plugin reads only message["type"] in its reset handler and ignores extra keys, so this is safe against existing games. For the seed to actually take effect in game, that handler in sync.gd needs to read it, which is a three line change in godot_rl_agents_plugin. I am happy to open that PR as well if you want to take this.

Related to #124, which covered the same area on the Godot side.

GodotEnv.reset accepted a seed and dropped it, so gymnasium style reseeding was
a silent no-op, and StableBaselinesGodotEnv.seed raised NotImplementedError,
which crashes any sb3 algorithm constructed with a seed (PPO(seed=0) calls
env.seed()).

reset now puts the seed in the reset message, and the wrapper latches one seed
per parallel game using the same seed + p offsets as the constructor, applied on
the next reset like sb3's own vec envs do.

The wire change is additive, older plugin versions ignore the extra key, so
nothing breaks. Reading it on the Godot side is a small companion change in
godot_rl_agents_plugin (the reset handler in sync.gd), happy to open that too.
The rllib CI jobs uninstall stable_baselines3 before running the suite, so a
module level import of the sb3 wrapper turns into a pytest collection error and
takes the whole run down. Import the wrapper inside the helper that needs it and
skip the vec env tests when ray is present, as the other sb3 tests already do.
The GodotEnv reset tests need no sb3 and keep running everywhere.
The seeds were initialised right after self.results, which the step_async PR
removes, so the two PRs touched adjacent lines and whichever landed second
would no longer merge cleanly. Initialise them where n_parallel is stored
instead. No behaviour change.
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.

1 participant