Fix TaskLocalRNG producing identical noise across processes#257
Fix TaskLocalRNG producing identical noise across processes#257isaacsas wants to merge 3 commits intoSciML:masterfrom
Conversation
When multiple noise processes were created sequentially with the default TaskLocalRNG and no intervening rand calls, `copy(rng)` gave each process an identical RNG state, resulting in statistically identical samples. Replace `copy(rng)` with `Random.Xoshiro(rand(rng, UInt64))` so that each construction draws a seed from the task-local RNG (advancing it), giving every process an independent random stream. Co-Authored-By: Claude Opus 4.5 <[email protected]>
CI Failure Analysis: SciMLSensitivity SDE1The only new CI failure is in the What's failing11 tests fail in The relative difference here is ~0.05%, just over the 0.01% threshold. Why this happensThis PR changes how RNGs are created for noise processes — instead of Suggested fix in SciMLSensitivityThe tolerances in |
|
@ChrisRackauckas I think this is good on my end. The SciMLSensitivty test seems like it needs updating to use more samples or a weaker tolerance as it is apparently borderline on having enough statistical samples. |
Remove the TaskLocalRNG -> Xoshiro conversion at construction time, reverting to the original behavior where all noise processes share the task-local RNG when no explicit rng is provided. Co-Authored-By: Claude Opus 4.5 <[email protected]>
The shared TaskLocalRNG singleton naturally produces independent noise across processes since each solve advances the shared state. Co-Authored-By: Claude Opus 4.5 <[email protected]>
|
OK, I reverted that copy but kept the test for distinct streams, which seems useful anyways. Let's see if tests pass now. |
|
Looks like it fails as there are one or more places that try to explicitly copy the rng and that causes the type to change with TaskLocalRNG (as it concretizes a Xoshiro). I don't know the motivation for such copies well enough to be comfortable messing with that code. I'll just close this and open a bug report. Hopefully someone who knows the code base better can fix this bug. |
When multiple noise processes were created sequentially with the default TaskLocalRNG and no intervening rand calls,
copy(rng)gave each process an identical RNG state, resulting in statistically identical samples.Replace
copy(rng)withRandom.Xoshiro(rand(rng, UInt64))so that each construction draws a seed from the task-local RNG (advancing it), giving every process an independent random stream.Old vs. new behavior:
Before (v5.27.0):
Identical? true— both processes produce the exact same noise samples.After this PR:
Identical? false— each process gets an independent random stream.