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

Add strip_solution #762

Merged
merged 4 commits into from
Aug 17, 2024
Merged
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
14 changes: 14 additions & 0 deletions src/solutions/ode_solutions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -604,3 +604,17 @@ function sensitivity_solution(sol::ODESolution, u, t)
@reset sol.t = t isa Vector ? t : collect(t)
return @set sol.interp = interp
end

function strip_solution(sol::ODESolution)
if has_lazy_interpolation(sol.alg)
error("The algorithm $(sol.alg) uses lazy interpolation, which is incompatible with
solution stripping.")
end

interp = strip_interpolation(sol.interp)
Copy link
Contributor

@thomvet thomvet Aug 19, 2024

Choose a reason for hiding this comment

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

@jClugstor : Just randomly reviewing this. It seems strange to me that the interp variable isn't used afterwards? Should it go into line 618? Otherwise, what's the point of defining it at all? Also, maybe check that the interpolation is stripped as well in the tests if this is the intended behavior here :)

Copy link
Member

Choose a reason for hiding this comment

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

Yes that looks like a typo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it's a typo, thanks for pointing it out .


ODESolution(sol.u, sol.u_analytic, sol.errors,
sol.t, sol.k, sol.discretes, nothing, nothing,
sol.interp, sol.dense, sol.tslocation, sol.stats,
sol.alg_choice, sol.retcode, sol.resid, sol.original)
end
9 changes: 9 additions & 0 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,3 +537,12 @@ the arity of a function is computed with `numargs`
See also: `prepare_initial_state`.
"""
prepare_function(f) = f

"""
strip_solution(sol)

Strips a SciMLSolution object and its interpolation of their functions to better accommodate serialization.
"""
function strip_solution(sol::AbstractSciMLSolution)
sol
end
8 changes: 8 additions & 0 deletions test/downstream/ode_stripping.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using OrdinaryDiffEq
f(u, p, t) = 1.01 * u
u0 = 1 / 2
tspan = (0.0, 1.0)
prob = ODEProblem(f, u0, tspan)
sol = solve(prob, Tsit5(), reltol = 1e-8, abstol = 1e-8)

@test isnothing(strip_solution(sol).f)
Loading