Skip to content

add PreallocationTools.DiffCache as cache for SplitODEProblem #1097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
28a8bcf
add PreallocationTools.LazyBufferCache as cache for SplitODEProblem
thomvet Aug 8, 2025
69003bb
test: fix jump affects in MTK remake test
AayushSabharwal Aug 12, 2025
724cc66
Merge branch 'SciML:master' into fix-orddiffeq-2719
thomvet Aug 12, 2025
382ceef
make DiffCache instead of LBC
thomvet Aug 12, 2025
e73e4bb
Merge pull request #1099 from AayushSabharwal/as/fix-test
ChrisRackauckas Aug 12, 2025
2e306e3
Force more function specialization
ChrisRackauckas Aug 13, 2025
5ea73ad
Merge pull request #1101 from SciML/functionspecialization
ChrisRackauckas Aug 13, 2025
571f92a
Update Project.toml
ChrisRackauckas Aug 13, 2025
b006610
add test
thomvet Aug 13, 2025
1a60ad6
slimmer using
thomvet Aug 13, 2025
b0eb83c
Update test/downstream/splitodeproblem_cache.jl
ChrisRackauckas Aug 13, 2025
3ba02de
Apply suggestions from code review
ChrisRackauckas Aug 13, 2025
ee65e46
make hasx foldable
oscardssmith Aug 13, 2025
a955c01
Merge pull request #1104 from oscardssmith/os/improve-hasx-defs
ChrisRackauckas Aug 14, 2025
b209f72
Update Project.toml
ChrisRackauckas Aug 14, 2025
9db8a8c
Apply suggestions from code review
ChrisRackauckas Aug 14, 2025
7ade05e
add PreallocationTools.LazyBufferCache as cache for SplitODEProblem
thomvet Aug 8, 2025
fc5bf4b
make DiffCache instead of LBC
thomvet Aug 12, 2025
adec855
add test
thomvet Aug 13, 2025
71e8c49
slimmer using
thomvet Aug 13, 2025
13026f8
Update test/downstream/splitodeproblem_cache.jl
ChrisRackauckas Aug 13, 2025
2a71c1a
Apply suggestions from code review
ChrisRackauckas Aug 13, 2025
42e382d
Apply suggestions from code review
ChrisRackauckas Aug 14, 2025
4b12de8
Merge branch 'fix-orddiffeq-2719' of https://github.com/thomvet/SciML…
thomvet Aug 14, 2025
e45a494
add PreallocationTools.DiffCache as cache for SplitODEProblem
thomvet Aug 8, 2025
37f9b1e
Merge branch 'fix-orddiffeq-2719' of https://github.com/thomvet/SciML…
thomvet Aug 14, 2025
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
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
Moshi = "2e0e35c7-a2e4-4343-998d-7ef72827ed2d"
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Expand Down Expand Up @@ -75,6 +76,7 @@ Makie = "0.20, 0.21, 0.22, 0.23, 0.24"
Markdown = "1.10"
Moshi = "0.3"
PartialFunctions = "1.1"
PreallocationTools = "0.4.29"
PrecompileTools = "1.2"
Preferences = "1.3"
Printf = "1.10"
Expand Down
1 change: 1 addition & 0 deletions src/SciMLBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using Distributed
using Markdown
using Printf
import Preferences
using PreallocationTools: get_tmp, DiffCache

import Logging, ArrayInterface
import IteratorInterfaceExtensions
Expand Down
2 changes: 1 addition & 1 deletion src/problems/ode_problems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ end
function SplitODEProblem{iip}(f::SplitFunction, u0, tspan, p = NullParameters();
kwargs...) where {iip}
if f._func_cache === nothing && iip
_func_cache = similar(u0)
_func_cache = PreallocationTools.DiffCache(u0)
f = remake(f; _func_cache)
end
ODEProblem(f, u0, tspan, p, SplitODEProblem{iip}(); kwargs...)
Expand Down
11 changes: 6 additions & 5 deletions src/scimlfunctions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2618,9 +2618,10 @@ end

(f::SplitFunction)(u, p, t) = f.f1(u, p, t) + f.f2(u, p, t)
function (f::SplitFunction)(du, u, p, t)
f.f1(f._func_cache, u, p, t)
tmp = PreallocationTools.get_tmp(f._func_cache, u)
f.f1(tmp, u, p, t)
f.f2(du, u, p, t)
du .+= f._func_cache
du .+= tmp
end

(f::DiscreteFunction)(args...) = f.f(args...)
Expand Down Expand Up @@ -2666,11 +2667,11 @@ end

(f::SDDEFunction)(args...) = f.f(args...)
(f::SplitSDEFunction)(u, p, t) = f.f1(u, p, t) + f.f2(u, p, t)

function (f::SplitSDEFunction)(du, u, p, t)
f.f1(f._func_cache, u, p, t)
tmp = PreallocationTools.get_tmp(f._func_cache)
f.f1(tmp, u, p, t)
f.f2(du, u, p, t)
du .+= f._func_cache
du .+= tmp
end

(f::RODEFunction)(args...) = f.f(args...)
Expand Down
33 changes: 33 additions & 0 deletions test/downstream/splitodeproblem_cache.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using OrdinaryDiffEq, Test

# https://github.com/SciML/OrdinaryDiffEq.jl/issues/2719

# set up functions
function f1!(du, u , p, t)
du .= -u.^2
return nothing
end

function f2!(du, u , p, t)
du .= 2u
return nothing
end

function f!(du, u, p, t)
du .= -u.^2 .+ 2u
return nothing
end

#create problems
u0 = ones(2)
tspan = (0.0, 1.0)
prob = ODEProblem(f!, u0, tspan)
f_split! = SplitFunction(f1!, f2!)
prob_split = SplitODEProblem(f_split!, u0, tspan)

#solve
sol = solve(prob, Rodas5())
sol_split = solve(prob_split, Rodas5())

#tests
@test sol_split == sol
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ end
@time @safetestset "Table Traits" begin
include("downstream/traits.jl")
end
@time @safetestset "SplitODEProblem cache" begin
include("downstream/splitodeproblem_cache.jl")
end
end

if !is_APPVEYOR && GROUP == "SymbolicIndexingInterface"
Expand Down
Loading