Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions docs/src/tutorials/modelingtoolkit.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ by hand. Those exact features are also potentially useful for GPU computing, and
tutorial showcases how to effectively use MTK with DiffEqGPU.jl.

!!! warn

This tutorial currently only works for ODEs defined by ModelingToolkit. More work
will be required to support DAEs in full. This is work that is ongoing and expected
to be completed by the summer of 2025.
Expand All @@ -29,16 +30,16 @@ eqs = [D(D(x)) ~ σ * (y - x),
D(z) ~ x * y - β * z]

@mtkbuild sys = ODESystem(eqs, t)
u0 = SA[D(x) => 2f0,
x => 1f0,
y => 0f0,
z => 0f0]
u0 = SA[D(x) => 2.0f0,
x => 1.0f0,
y => 0.0f0,
z => 0.0f0]

p = SA[σ => 28f0,
ρ => 10f0,
β => 8f0 / 3f0]
p = SA[σ => 28.0f0,
ρ => 10.0f0,
β => 8.0f0 / 3.0f0]

tspan = (0f0, 100f0)
tspan = (0.0f0, 100.0f0)
prob = ODEProblem{false}(sys, u0, tspan, p)
sol = solve(prob, Tsit5())
```
Expand All @@ -64,7 +65,7 @@ sym_setter = setsym_oop(sys, [σ, ρ, β])
The return `sym_setter` is our optimized function, let's see it in action:

```@example mtk
u0, p = sym_setter(prob,@SVector(rand(Float32,3)))
u0, p = sym_setter(prob, @SVector(rand(Float32, 3)))
```

Notice it takes in the vector of values for `[σ, ρ, β]` and spits out the new `u0, p`. So
Expand All @@ -73,7 +74,7 @@ we can build and solve an MTK generated ODE on the GPU using the following:
```@example mtk
using DiffEqGPU, CUDA
function prob_func2(prob, i, repeat)
u0, p = sym_setter(prob,@SVector(rand(Float32,3)))
u0, p = sym_setter(prob, @SVector(rand(Float32, 3)))
remake(prob, u0 = u0, p = p)
end

Expand Down
2 changes: 0 additions & 2 deletions src/DiffEqGPU.jl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ include("ensemblegpukernel/tableaus/verner_tableaus.jl")
include("ensemblegpukernel/tableaus/rodas_tableaus.jl")
include("ensemblegpukernel/tableaus/kvaerno_tableaus.jl")



include("utils.jl")
include("algorithms.jl")
include("solve.jl")
Expand Down
1 change: 0 additions & 1 deletion src/ensemblegpuarray/problem_generation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ function generate_problem(prob::SciMLBase.AbstractODEProblem,
_tgrad = nothing
end


f_func = ODEFunction(_f, Wfact = _Wfact!,
Wfact_t = _Wfact!_t,
#colorvec=colorvec,
Expand Down
2 changes: 1 addition & 1 deletion src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ function batch_solve_up_kernel(ensembleprob, probs, alg, ensemblealg, I, adaptiv
_callback.continuous_callbacks)...)

dev = ensemblealg.dev
probs = adapt(dev,adapt.((dev,), probs))
probs = adapt(dev, adapt.((dev,), probs))

#Adaptive version only works with saveat
if adaptive
Expand Down
9 changes: 5 additions & 4 deletions test/ensemblegpuarray_sde.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@ NRate[2, 2] = 1
u0 = ComplexF32[1.0; 0.0; 0.0; 0.0]
tspan = (0.0f0, 10.0f0)
p = (10.0f0, 28.0f0, 8 / 3.0f0)
prob = SDEProblem(lorenz, multiplicative_noise, u0, tspan, p, noise_rate_prototype=NRate)
prob = SDEProblem(lorenz, multiplicative_noise, u0, tspan, p, noise_rate_prototype = NRate)

prob_func = (prob, i, repeat) -> remake(prob, p=p)
monteprob = EnsembleProblem(prob, prob_func=prob_func)
prob_func = (prob, i, repeat) -> remake(prob, p = p)
monteprob = EnsembleProblem(prob, prob_func = prob_func)

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