Skip to content

Commit 794bf13

Browse files
Properly throw an error for non-diagonal noise in EnsembleGPUArray
Doesn't quite fix #331 but makes the users of the package safe by putting in an appropriate error.
1 parent 3d94277 commit 794bf13

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/ensemblegpuarray/problem_generation.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ function generate_problem(prob::SciMLBase.AbstractODEProblem,
7070
end
7171

7272
function generate_problem(prob::SDEProblem, u0, p, jac_prototype, colorvec)
73+
if prob.noise_rate_prototype !== nothing
74+
error("Incompatible problem detected. EnsembleGPUArray currently requires `prob.noise_rate_prototype === nothing`, i.e. only diagonal noise is currently supported. Track https://github.com/SciML/DiffEqGPU.jl/issues/331 for more information.")
75+
end
76+
7377
_f = let f = prob.f.f, kernel = DiffEqBase.isinplace(prob) ? gpu_kernel : gpu_kernel_oop
7478
function (du, u, p, t)
7579
version = get_backend(u)

test/ensemblegpuarray_sde.jl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,31 @@ monteprob = EnsembleProblem(prob, prob_func = prob_func)
2828
# CUDAnative.CUDAdrv.@profile
2929
@time sol = solve(monteprob, SOSRI(), EnsembleGPUArray(backend), trajectories = 10,
3030
saveat = 1.0f0)
31+
32+
function lorenz(du, u, p, t)
33+
du[1] = p[1] * (u[2] - u[1])
34+
du[2] = u[1] * (p[2] - u[3]) - u[2]
35+
du[3] = u[1] * u[2] - p[3] * u[3]
36+
du[4] = 0
37+
end
38+
39+
function multiplicative_noise(du, u, p, t)
40+
du[1, 1] = 0.1
41+
du[2, 2] = 0.4
42+
du[4, 1] = 1.0
43+
end
44+
45+
NRate = spzeros(4, 2)
46+
NRate[1, 1] = 1
47+
NRate[4, 1] = 1
48+
NRate[2, 2] = 1
49+
50+
u0 = ComplexF32[1.0; 0.0; 0.0; 0.0]
51+
tspan = (0.0f0, 10.0f0)
52+
p = (10.0f0, 28.0f0, 8 / 3.0f0)
53+
prob = SDEProblem(lorenz, multiplicative_noise, u0, tspan, p, noise_rate_prototype=NRate)
54+
55+
prob_func = (prob, i, repeat) -> remake(prob, p=p)
56+
monteprob = EnsembleProblem(prob, prob_func=prob_func)
57+
58+
@test_throws "Incompatible problem detected. EnsembleGPUArray currently requires `prob.noise_rate_prototype === nothing`, i.e. only diagonal noise is currently supported. Track https://github.com/SciML/DiffEqGPU.jl/issues/331 for more information." sol = solve(monteprob, SRA1(), EnsembleCPUArray(), trajectories=10_000, saveat=1.0f0)

0 commit comments

Comments
 (0)