Skip to content

Refactor random number generation to use self.np_random for seeding environments correctly - #43

Open
StefanHamm wants to merge 2 commits into
TUDelft-CNS-ATM:mainfrom
StefanHamm:fix/seeding
Open

Refactor random number generation to use self.np_random for seeding environments correctly#43
StefanHamm wants to merge 2 commits into
TUDelft-CNS-ATM:mainfrom
StefanHamm:fix/seeding

Conversation

@StefanHamm

Copy link
Copy Markdown

Implement Deterministic Seeding via self.np_random

Description

This PR standardizes the random number generation across all environments to ensure full reproducibility. All instances of randomness (including internal function calls) have been updated to use the Gymnasium standard self.np_random generator.

This allows users to seed the environment initialization and the resulting episode sequence using env.reset(seed=...).

Key Changes

  • Replaced Global Randomness: Refactored all environments to use self.np_random instead of numpy.random or standard random library calls.
  • Propagated RNG: Updated helper functions to accept the environment's random number generator instance to ensure consistent seeding throughout the complete stack.
  • Deterministic Behavior:
    • Calling env.reset(seed=X) once after env creation, guarantees that the specific episode and the subsequent sequence of episodes are deterministic initizialized.
    • Calling env.reset() (without a seed) maintains standard stochastic behavior for diverse training data.

@StefanHamm

Copy link
Copy Markdown
Author

seeding.py

Short script to test the seeding

@StefanHamm

Copy link
Copy Markdown
Author

fixes #42

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