SciML / StochasticDiffEq.jl

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

seed given by solver keyword argument does not work for sparse noise_rate_prototype #435

Closed sho7014 closed 2 years ago

sho7014 commented 2 years ago

Hello,

seed argument in solve() does not seem to work when noise_rate_prototype is specified using sparse arrays. Instead. seed can be appropriately set using Random.seed!().

You can see this behavior using the following code.

using StochasticDiffEq, PyPlot, SparseArrays, Random

function f!(du,u,p,t)
    du[1] = 0.0
end

function g!(du,u,p,t)
    du[1,1] = 1.0
    du[1,3] = 1.0
end

dt = 1e-2
u0 = [0.0]
tspan = (0.0,0.1)

#seed does not work
sde_prob = SDEProblem(f!, g!, u0, tspan, noise_rate_prototype=sparse([1.0 0.0 1.0]))
sol = solve(sde_prob, EulerHeun(), dt=dt, seed=1)

#seed works
sde_prob = SDEProblem(f!, g!, u0, tspan, noise_rate_prototype=[1.0 0.0 1.0])
sol = solve(sde_prob, EulerHeun(), dt=dt, seed=1)

#seed works
sde_prob = SDEProblem(f!, g!, u0, tspan, noise_rate_prototype=sparse([1.0 0.0 1.0]))
Random.seed!(1)
sol = solve(sde_prob, EulerHeun(), dt=dt)