SciML / DiffEqGPU.jl

GPU-acceleration routines for DifferentialEquations.jl and the broader SciML scientific machine learning ecosystem
https://docs.sciml.ai/DiffEqGPU/stable/
MIT License
274 stars 28 forks source link

Add support for random time span within trajectories #216

Closed utkarsh530 closed 1 year ago

utkarsh530 commented 1 year ago

Fixes #141 MWE:

using DiffEqGPU, OrdinaryDiffEq, StaticArrays, LinearAlgebra, CUDA
function lorenz(u, p, t)
    σ = p[1]
    ρ = p[2]
    β = p[3]
    du1 = σ * (u[2] - u[1])
    du2 = u[1] * (ρ - u[3]) - u[2]
    du3 = u[1] * u[2] - β * u[3]
    return SVector{3}(du1, du2, du3)
end

u0 = @SVector [1.0f0; 0.0f0; 0.0f0]
tspan = (0.0f0, 10.0f0)
p = @SVector [10.0f0, 28.0f0, 8 / 3.0f0]
prob = ODEProblem{false}(lorenz, u0, tspan, p)

saveats = 1.f0:1.f0:10.f0

monteprob = EnsembleProblem(prob, prob_func =  (prob, i, repeat) -> remake(prob; tspan = (0.f0, saveats[i]), saveat = LinRange(0.f0,saveats[i],10), safetycopy = false))

alg = GPUTsit5()

sol = solve(monteprob, alg, EnsembleGPUKernel(0.0), trajectories = 10,
            adaptive = false, dt = 0.01f0, save_everystep = false)
utkarsh530 commented 1 year ago

@ChrisRackauckas does this seem okay? We'll need to document it a bit because I know people will break this easily haha

ChrisRackauckas commented 1 year ago

Documentation is only half the battle. Make it throw clear and descriptive errors before it hits the kernel for the cases that will not work. There's no error exceptions thrown with this at all right now.

utkarsh530 commented 1 year ago

Tried to throw exceptions for common cases.