StochasticDiffEq.jl icon indicating copy to clipboard operation
StochasticDiffEq.jl copied to clipboard

Allow seeding `SDEProblems` with e.g. StableRNGs

Open TorkelE opened this issue 10 months ago • 1 comments

For JumpProcesses's JumpProblems you can do

using JumpProcesses,  StableRNGs
rng = StableRNG(12345)
jprob = JumpProblem(no_param_network, dprob, Direct(); rng = rng)
sol1 = solve(jprob, SSAStepper())
sol2 = solve(jprob, SSAStepper())
sol3 = solve(jprob, SSAStepper())

and now, while sol1, sol2, and sol3 are different, they will yield reproducibly the same result each time I rerun the above snippet (useful to e.g. remove any randomness from tests). Note, this si different from setting a seed, where if I do:

using JumpProcesses,  StableRNGs
jprob = JumpProblem(no_param_network, dprob, Direct(); seed = 1234)
sol1 = solve(jprob, SSAStepper())
sol2 = solve(jprob, SSAStepper())
sol3 = solve(jprob, SSAStepper())

sol1, sol2, and sol3 will be identical.

StochasticDiffEq does not have a feature like this (and is only able to set seeds, however, it would be useful.

It is possible to partially circumvent this by setting different seeds for each sol (potentially depending on the StableRNG). However, long-term, being able to provide a stable rng to a SDEProblem directly would be ideal.

TorkelE avatar Mar 30 '24 00:03 TorkelE

I think the bigger issue here is providing a simple way for users to set the rng used internally, i.e. via the problem or solve call, which would also fix this issue.

isaacsas avatar May 14 '24 19:05 isaacsas