|
| 1 | +using DiffEqGPU, Test, ModelingToolkit, OrdinaryDiffEqTsit5, CUDA |
| 2 | + |
| 3 | +@testset "ModelingToolkit GPU Compatibility" begin |
| 4 | + # Test case from issue #375 |
| 5 | + # ModelingToolkit-generated problems should work with EnsembleGPUKernel |
| 6 | + |
| 7 | + @parameters σ ρ β |
| 8 | + @variables t x(t) y(t) z(t) |
| 9 | + D = Differential(t) |
| 10 | + |
| 11 | + eqs = [D(x) ~ σ * (y - x), |
| 12 | + D(y) ~ x * (ρ - z) - y, |
| 13 | + D(z) ~ x * y - β * z] |
| 14 | + |
| 15 | + @named sys = ODESystem(eqs, t) |
| 16 | + sys = structural_simplify(sys) |
| 17 | + |
| 18 | + u0 = [x => 1.0, y => 0.0, z => 0.0] |
| 19 | + tspan = (0.0f0, 1.0f0) |
| 20 | + p = [σ => 10.0, ρ => 28.0, β => 8 / 3] |
| 21 | + |
| 22 | + prob = ODEProblem(sys, u0, tspan, p) |
| 23 | + |
| 24 | + # Test that we can create an ensemble problem |
| 25 | + function prob_func(prob, i, repeat) |
| 26 | + remake(prob, p = [σ => 10.0 + i * 0.1, ρ => 28.0, β => 8 / 3]) |
| 27 | + end |
| 28 | + |
| 29 | + ensemble_prob = EnsembleProblem(prob, prob_func = prob_func) |
| 30 | + |
| 31 | + # This should not error with "CuArray only supports element types that are allocated inline" |
| 32 | + @test_nowarn begin |
| 33 | + sol = solve(ensemble_prob, GPUTsit5(), EnsembleGPUKernel(CUDA.CUDABackend()); |
| 34 | + trajectories = 10, dt = 0.1f0, adaptive = false) |
| 35 | + end |
| 36 | + |
| 37 | + # Actually test that it works |
| 38 | + sol = solve(ensemble_prob, GPUTsit5(), EnsembleGPUKernel(CUDA.CUDABackend()); |
| 39 | + trajectories = 10, dt = 0.1f0, adaptive = false) |
| 40 | + |
| 41 | + @test length(sol) == 10 |
| 42 | + @test all(s.retcode == :Success || s.retcode == :Terminated for s in sol) |
| 43 | +end |
0 commit comments