-
Notifications
You must be signed in to change notification settings - Fork 57
Fix random seed handling in simulation #668
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes incorrect random seed handling in the simulate_scenarios
function. The bug caused the provided random_seed
parameter to be ignored, potentially leading to unpredictable behavior in benchmarking operations.
Key Changes:
- Fixed the seed calculation logic to use the provided
random_seed
instead of always defaulting to_DEFAULT_SEED
- Updated test to use a non-standard seed value to better detect such issues
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
File | Description |
---|---|
baybe/simulation/scenarios.py | Corrected the seed assignment logic to properly use the random_seed parameter when provided |
tests/test_simulation.py | Changed test seed value to a non-common number to avoid masking similar bugs |
CHANGELOG.md | Documented the bug fix |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
): | ||
"""Callable for xyzpy simulation.""" | ||
data = None if initial_data is None else initial_data[Initial_Data] | ||
seed = None if random_seed is None else Monte_Carlo_Run + _DEFAULT_SEED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@AdrianSosic but wasnt random seed always specified as part of benchmarks? So it should not happen that it is None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is: according to the old logic, it becomes None when you explicitly specify it 😄 (i.e. the None
right after the equation symbol is taken as the value)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok maybe I am not getting something:
DS=1
for random_seed in [None,0]:
print(f'Out for random_seed {random_seed}:',None if random_seed is None else DS)
Out for random_seed None: None
Out for random_seed 0: 1
And dont we always specify random_seed
in benchmarks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, read my own code wrong 😅 the point is that the passed seed actually never entered the simulation. if you specify one, you get the default 1337 with increasing number, no matter what you specified. So the previous version is definitely wrong, and the new version makes my minimal example work – but I also haven't yet fully understood how it interacts with the active_dims
. Regardless of that, the fix should be merged. Will try to drill further into "why" it fixes the active dims part
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it becomes None when you explicitly specify it
is that correct? According to the deleted line it becomes none when you pass none -> correct (or at least not catastrophic). But if its NOT none, the random_seed
would be ignored and always use the default seed (+ monte carlo run) -> that was the issue
(comment started before Adrians last comment was there)
Fixes a wrong assignment for controlling the random seeds in
simulate_scenarios
. Potentially, this was the cause for many weird effects noticed in the benchmarking module in the past.