Skip to content

fix(player): forward env_config seed to vecenv and regular envs - #426

Merged
Denys88 merged 1 commit into
Denys88:masterfrom
NY-WaKeUp:fix/player-env-seed
Nov 20, 2026
Merged

Denys88 merged 1 commit into
Denys88:masterfrom
NY-WaKeUp:fix/player-env-seed

Conversation

@NY-WaKeUp

@NY-WaKeUp NY-WaKeUp commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

BasePlayer.__init__ previously popped seed from env_config (mutating the caller's dict in place) and never forwarded self.seed to vecenv.create_vec_env, create_env(), or env_reset(). Complements #408 by ensuring BasePlayer forwards env_config['seed'] during play/evaluation.

Changes

  • Copy env_config in BasePlayer.__init__ (handling None and falling back to config['env_config']['seed'] when player.env_config overrides env_config without a seed key).
  • Extract _init_env() to keep BasePlayer.__init__ cyclomatic complexity below the flake8 threshold and forward seed to vecenv.create_vec_env when use_vecenv=True (matching a2c_common.py).
  • For regular envs (use_vecenv=False), call self.env.seed(self.seed) if available and pass seed on the first env_reset() via try: obs = env.reset(seed=seed) except TypeError: obs = env.reset().
  • Add unit and end-to-end CartPole-v1 determinism tests in tests/test_player_env_seed.py.

Testing

  • pytest tests/test_player_env_seed.py tests/test_gymnasium_seeding.py tests/test_player_gymnasium_step.py -v (23 passed)
  • flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics (0 errors)

@Denys88

Denys88 commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Thanks for the PR, and welcome. Two things. First, the use case: which setup are you evaluating where the player's seed not reaching the environment actually mattered for you (gymnasium vector env, custom env_creator, something else), and what did you observe? That tells me which part needs to land. Second, #408 just merged and already handles the GymnasiumVecEnv side (pending seed consumed on the next reset, per-env offsets on the manual path), so the constructor seeding in gymnasium_vecenv.py now double-seeds and its tests fail when combined. Could you rebase and trim this to the player part: forward seed into create_vec_env / env.seed(), and drop the manual-env constructor change and the inspect.signature reset wrapper? A plain env.reset(seed=...) guarded by a try/except TypeError would be enough for the regular-env path.

@NY-WaKeUp

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review @Denys88!

  1. Use case: We ran into this when running deterministic checkpoint evaluations (--play with seed set and player.deterministic: True) across both GymnasiumVecEnv and custom env_creator-registered Gymnasium robotics/control tasks to compare checkpoints on identical initial rollout states. Although Runner.load_config populates params['config']['env_config']['seed'], BasePlayer.__init__ popped seed from self.env_config without forwarding it to vecenv.create_vec_env (on the vecenv path) or env.seed() / the initial env.reset(seed=...) (on the create_env() path), so initial observations still varied across runs.
  2. Changes updated: Rebased onto latest master (with Apply pending seeds when Gymnasium vector environments reset #408 merged) and trimmed the PR as requested:
    • Dropped the gymnasium_vecenv.py change completely (#408 now handles both native and manual reset seeding once BasePlayer forwards seed into create_vec_env).
    • Replaced the inspect.signature helper in BasePlayer.env_reset with a plain try: obs = env.reset(seed=seed) except TypeError: obs = env.reset().
    • Verified that both tests/test_gymnasium_seeding.py and tests/test_player_env_seed.py pass together (23 passed).

@Denys88 Denys88 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for the quick rebase and trim. The vecenv path now matches what training does (the full env_config including seed goes into create_vec_env), the regular-env path seeds once on the first reset with a plain try/except, and the player/seeding tests pass together on master (148 passed locally, CI green on 3.11-3.14).

@Denys88
Denys88 merged commit dc95c95 into Denys88:master Nov 20, 2026
6 checks passed
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (master@294f020). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff            @@
##             master     #426   +/-   ##
=========================================
  Coverage          ?   63.94%           
=========================================
  Files             ?       70           
  Lines             ?     8923           
  Branches          ?        0           
=========================================
  Hits              ?     5706           
  Misses            ?     3217           
  Partials          ?        0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

ViktorM added a commit that referenced this pull request Nov 25, 2026
A clean merge: no file needed a change by hand. Master brings the FlashSAC
options (#395), multi-GPU SAC with update_cuda_graph (#396) and the fix
series of #391 to #426. PBT still supports the PPO agents only and refuses
SAC. Both sides had changed README.md, central_value.py, a2c_common.py,
torch_runner.py and tests/test_release_blockers.py, in separate places.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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