Skip to content

Commit

Permalink
Merge pull request #790 from jClugstor/strip_sol_fix
Browse files Browse the repository at this point in the history
Fix interpolation for stripped solutions
  • Loading branch information
ChrisRackauckas authored Sep 23, 2024
2 parents 4a0c5e8 + d777184 commit 1e6720c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 9 additions & 3 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -619,14 +619,20 @@ function Base.showerror(io::IO, e::LazyInterpolationException)
" uses lazy interpolation, which is incompatible with `strip_solution`.")
end

function strip_solution(sol::ODESolution)
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 = (; p = nothing)

if strip_alg
@reset sol.alg = nothing
end

return sol
end
10 changes: 5 additions & 5 deletions test/downstream/ode_stripping.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ 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 isnothing(SciMLBase.strip_solution(sol, strip_alg = true).alg)

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

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

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

0 comments on commit 1e6720c

Please sign in to comment.