Skip to content

Commit 8807f1c

Browse files
Merge pull request #350 from SciML/error_nondiagonal
Properly throw an error for non-diagonal noise in EnsembleGPUArray
2 parents 3d94277 + a388ccf commit 8807f1c

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
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/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
1515
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
1616
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
1717
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
18+
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1819
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
1920
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2021
Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f"

test/ensemblegpuarray_sde.jl

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using DiffEqGPU, StochasticDiffEq, Test
1+
using DiffEqGPU, StochasticDiffEq, SparseArrays, Test
22

33
include("utils.jl")
44

@@ -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)