Skip to content
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

Fix cache_strip for default algs #2489

Merged
merged 5 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "OrdinaryDiffEq"
uuid = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
authors = ["Chris Rackauckas <[email protected]>", "Yingbo Ma <[email protected]>"]
version = "6.89.0"
version = "6.89.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want to bump OrdinaryDiffEqCore? I think that if we want a bump in OrdinaryDiffEq, that would also need to bump the minimum compat on OrdinaryDiffEqCore in OrdinaryDiffEq besides bumping the version number.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah, you're right.


[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
26 changes: 8 additions & 18 deletions lib/OrdinaryDiffEqCore/src/interp_func.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,14 @@ function SciMLBase.strip_interpolation(id::InterpolationData)
end

function strip_cache(cache)
if hasfield(typeof(cache), :jac_config)
SciMLBase.@reset cache.jac_config = nothing
if !(cache isa OrdinaryDiffEqCore.DefaultCache)
cache = SciMLBase.constructorof(typeof(cache))([nothing
for name in fieldnames(typeof(cache))]...)
else
# need to do something special for default cache
cache = OrdinaryDiffEqCore.DefaultCache{Nothing, Nothing, Nothing, Nothing,
Nothing, Nothing, Nothing, Nothing}(nothing, nothing, 0, nothing)
end
if hasfield(typeof(cache), :grad_config)
SciMLBase.@reset cache.grad_config = nothing
end
if hasfield(typeof(cache), :nlsolver)
SciMLBase.@reset cache.nlsolver = nothing
end
if hasfield(typeof(cache), :tf)
SciMLBase.@reset cache.tf = nothing
end
if hasfield(typeof(cache), :uf)
SciMLBase.@reset cache.uf = nothing
end
if hasfield(typeof(cache),:args)
SciMLBase.@reset cache.args = nothing
end


cache
end
28 changes: 18 additions & 10 deletions test/interface/ode_strip_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,36 @@ prob = ODEProblem(lorenz!, u0, tspan)
rosenbrock_sol = solve(prob, Rosenbrock23())
TRBDF_sol = solve(prob, TRBDF2())
vern_sol = solve(prob, Vern7())

default_sol = solve(prob)
@testset "Interpolation Stripping" begin
@test isnothing(SciMLBase.strip_interpolation(rosenbrock_sol.interp).f)
@test isnothing(SciMLBase.strip_interpolation(rosenbrock_sol.interp).cache.jac_config)
@test isnothing(SciMLBase.strip_interpolation(rosenbrock_sol.interp).cache.grad_config)
end

@testset "Rosenbrock Solution Stripping" begin
@test SciMLBase.strip_solution(rosenbrock_sol).prob isa NamedTuple
stripped_sol = SciMLBase.strip_solution(rosenbrock_sol)
@test stripped_sol.prob isa NamedTuple
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol, strip_alg = true).alg)
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol).interp.f)
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol).interp.cache.jac_config)
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol).interp.cache.grad_config)
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol).interp.cache.uf)
@test isnothing(SciMLBase.strip_solution(rosenbrock_sol).interp.cache.tf)
@test isnothing(stripped_sol.interp.f)
@test isnothing(stripped_sol.interp.cache.jac_config)
@test isnothing(stripped_sol.interp.cache.grad_config)
@test isnothing(stripped_sol.interp.cache.uf)
@test isnothing(stripped_sol.interp.cache.tf)
end

@testset "TRBDF Solution Stripping" begin
@test SciMLBase.strip_solution(TRBDF_sol).prob isa NamedTuple
stripped_sol = SciMLBase.strip_solution(TRBDF_sol)
@test stripped_sol.prob isa NamedTuple
@test isnothing(SciMLBase.strip_solution(TRBDF_sol, strip_alg = true).alg)
@test isnothing(SciMLBase.strip_solution(TRBDF_sol).interp.f)
@test isnothing(SciMLBase.strip_solution(TRBDF_sol).interp.cache.nlsolver)
@test isnothing(stripped_sol.interp.f)
@test isnothing(stripped_sol.interp.cache.nlsolver)
end

@testset "Default Solution Stripping" begin
stripped_sol = SciMLBase.strip_solution(default_sol)
@test isnothing(stripped_sol.interp.cache.args)

end

@test_throws SciMLBase.LazyInterpolationException SciMLBase.strip_solution(vern_sol)
Loading