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 interpolation for stripped solutions #790

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SciMLBase"
uuid = "0bca4576-84f4-4d90-8ffe-ffa030f20462"
authors = ["Chris Rackauckas <[email protected]> and contributors"]
version = "2.53.1"
version = "2.53.2"

[deps]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Expand Down
15 changes: 12 additions & 3 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,23 @@ function Base.showerror(io::IO, e::LazyInterpolationException)
" uses lazy interpolation, which is incompatible with `strip_solution`.")
end

function strip_solution(sol::ODESolution)
struct ODENullFunction <: SciMLBase.AbstractODEFunction{false} end

function strip_solution(sol::ODESolution; strip_alg = false)
if has_lazy_interpolation(sol.alg)
throw(LazyInterpolationException(nameof(typeof(sol.alg))))
end

interp = strip_interpolation(sol.interp)

@reset sol.interp = interp
@reset sol.prob = nothing
return @set sol.alg = nothing

@reset sol.prob = ODEProblem(ODENullFunction(), sol.prob.u0, sol.prob.tspan, p = sol.prob.p,
problem_type = sol.prob.problem_type, sol.prob.kwargs...)

if strip_alg
@reset sol.alg = nothing
end

return sol
end
13 changes: 8 additions & 5 deletions test/downstream/ode_stripping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ prob = ODEProblem(lorenz!, u0, tspan)
# implicit solver so we can test cache stripping worked
sol = solve(prob, Rosenbrock23())

@test isnothing(SciMLBase.strip_solution(sol).prob)
stripped_sol = SciMLBase.strip_solution(sol)

@test isnothing(SciMLBase.strip_solution(sol).alg)
@test stripped_sol.prob.f isa SciMLBase.ODENullFunction

@test isnothing(SciMLBase.strip_solution(sol).interp.f)
@test isnothing(SciMLBase.strip_solution(sol, strip_alg = true).alg)

@test isnothing(SciMLBase.strip_solution(sol).interp.cache.jac_config)
@test isnothing(stripped_sol.interp.f)

@test isnothing(stripped_sol.interp.cache.jac_config)

@test isnothing(stripped_sol.interp.cache.grad_config)

@test isnothing(SciMLBase.strip_solution(sol).interp.cache.grad_config)
Loading