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
284 stars 29 forks source link

Continuous Callbacks for GPUTsit5 #184

Closed utkarsh530 closed 1 year ago

utkarsh530 commented 1 year ago

Hi, I have completed Continuous callbacks for GPUTsit5. I tested the bouncing ball problem and works well:

using DiffEqGPU, SimpleDiffEq, StaticArrays, CUDA, BenchmarkTools, NonlinearSolve
#using OrdinaryDiffEq

CUDA.allowscalar(false)

function f(u, p, t)
    du1 = u[2]
    du2 = -p[1]
    return SVector{2}(du1, du2)
end

u0 = @SVector[45.0f0, 0.0f0]
tspan = (0.0f0, 15.0f0)
p = @SVector [10.0f0]
prob = ODEProblem{false}(f, u0, tspan, p)
prob_func = (prob, i, repeat) -> remake(prob, p = prob.p)
monteprob = EnsembleProblem(prob, safetycopy = false)

function affect!(integrator)
    integrator.u += @SVector[0.0f0, -2.0f0] .* integrator.u
end

function condition(u, t, integrator)
    u[1]
end

cb = ContinuousCallback(condition, affect!; save_positions = (false, false))
sol = solve(monteprob, GPUTsit5(), EnsembleGPUKernel(),
            trajectories = 2,
            adaptive = false, dt = 0.1f0, callback = cb, merge_callbacks = true)

test_2

I need to write tests, which will not pass until we merge https://github.com/SciML/NonlinearSolve.jl/pull/92 . @ChrisRackauckas, please review.

ChrisRackauckas commented 1 year ago

Other than the extra dispatch, this looks good to go.

utkarsh530 commented 1 year ago

Can you tag NonlinearSolve.jl?

codecov[bot] commented 1 year ago

Codecov Report

Merging #184 (2db273f) into master (32417d4) will not change coverage. The diff coverage is 0.00%.

@@          Coverage Diff           @@
##           master    #184   +/-   ##
======================================
  Coverage    0.00%   0.00%           
======================================
  Files           9       9           
  Lines        1894    1993   +99     
======================================
- Misses       1894    1993   +99     
Impacted Files Coverage Δ
src/DiffEqGPU.jl 0.00% <0.00%> (ø)
src/integrators/integrator_utils.jl 0.00% <0.00%> (ø)
src/integrators/types.jl 0.00% <0.00%> (ø)
src/perform_step/gpu_tsit5_perform_step.jl 0.00% <0.00%> (ø)
src/perform_step/gpu_vern7_perform_step.jl 0.00% <0.00%> (ø)
src/perform_step/gpu_vern9_perform_step.jl 0.00% <0.00%> (ø)
src/solve.jl 0.00% <ø> (ø)

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

ChrisRackauckas commented 1 year ago

The retcode stuff should be good with the new DiffEqBase version that uses SimpleNonlinearSolve. Setup the test and let's get this one merged.

ChrisRackauckas commented 1 year ago

This is still missing tests

utkarsh530 commented 1 year ago

Added continuous callbacks tests to Tsit5.

ChrisRackauckas commented 1 year ago

Looks fine. I would reorganize this in a bit. There's no reason to copy paste the same discrete and continuous callback scripts into a file for each solver: just run the same setup with different solvers (and check that they give close to equivalent results). But let's merge and reorganize in a follow up.

utkarsh530 commented 1 year ago

Yes, reorganization is my next task. Let's merge this, and I'll follow up with a reorganization.

Also, I'll need to address the growing If-Else blocks for adaptive and other things that increases compile time.

ChrisRackauckas commented 1 year ago

Real failures.

utkarsh530 commented 1 year ago

Strange.. everything is passing locally

utkarsh530 commented 1 year ago

LGTM