SciML / StochasticDiffEq.jl

Solvers for stochastic differential equations which connect with the scientific machine learning (SciML) ecosystem
Other
237 stars 65 forks source link

Allow seeding `SDEProblems` with e.g. StableRNGs #569

Open TorkelE opened 3 months ago

TorkelE commented 3 months ago

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.

isaacsas commented 2 months ago

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.