-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Reproducibilty Trap in model.py #3190
Copy link
Copy link
Closed
Description
This code block is really confusing me
Lines 122 to 127 in b6e96d1
| try: | |
| self.random = random.Random(rng) | |
| except TypeError: | |
| seed = int(self.rng.integers(np.iinfo(np.int32).max)) | |
| self.random = random.Random(seed) | |
| self._seed = seed # this allows for reproducing stdlib.random |
It uses a try-except block to handle compatibility issues but the logic fails to capture the seed value in the successful cases.
- If
rngisNone:random.Random(None)succeeds, skipping theexceptblock.seedremainsNone. - If
rngis anint:random.Random(int)succeeds, skipping theexceptblock.seedremainsNone.
As a result, self._seed is set to None at the end of the block (self._seed = seed). This breaks reproducibility and causes model.scenario.rng to be None
Please correct me if I am wrong!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels