BUG: seed Monte Carlo per simulation index, not per worker (#1053)#1071
Open
wuisabel-gif wants to merge 2 commits into
Open
BUG: seed Monte Carlo per simulation index, not per worker (#1053)#1071wuisabel-gif wants to merge 2 commits into
wuisabel-gif wants to merge 2 commits into
Conversation
Member
|
duplicated with #1053 |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #1071 +/- ##
===========================================
+ Coverage 80.85% 82.22% +1.37%
===========================================
Files 122 122
Lines 16355 16361 +6
===========================================
+ Hits 13224 13453 +229
+ Misses 3131 2908 -223 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull request type
Checklist
ruff checkandruff format --check; pylint 10/10 on the touched files)test_monte_carlo.py,tests/unit/stochastic); relying on CI for the full slow suiteCHANGELOG.mdupdatedCurrent behavior
MonteCarlo.simulate()seeds the stochastic models per worker in parallel mode and effectively once at construction in serial mode, so the inputs a given simulation index receives depend on how the run was executed rather than on the index. Parallel spawns one seed per worker from a fresh unseededSeedSequence, and each worker draws for whatever sims it pulls off the shared counter; serial draws one long sequential stream. Result: serial,n_workers=2, andn_workers=4all sample different inputs, and parallel runs aren't reproducible run to run. This is #1053.New behavior
Each simulation's seed is derived from
(master seed, simulation index)viaSeedSequence, reseeding the models before every simulation in both paths. Adds an optionalseedtoMonteCarlo; the master entropy is captured once, soseed=Nonestays random but consistent across execution modes within a run. A given index now samples identical inputs regardless of serial/parallel orn_workers, and a fixed seed reproduces a whole run. Integer child seeds (notSeedSequenceobjects) keep custom samplers'reset_seedworking.Breaking change
With
seed=Nonethe sampling is unchanged in spirit (still random), but numeric samples for existing unseeded runs will differ, since seeding is now per-index rather than one sequential stream. Theseedargument is opt-in.Additional information
Adds
test_seed_makes_inputs_reproducible_by_indexandtest_unseeded_monte_carlo_is_index_consistentintests/unit/simulation/test_monte_carlo.py.Closes #1053