From b734f19f1812c83917de2e18356f1397c1a50738 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Thu, 8 Aug 2024 12:53:57 -0400 Subject: [PATCH 1/3] add strip_solution --- src/solutions/ode_solutions.jl | 14 ++++++++++++++ src/utils.jl | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/solutions/ode_solutions.jl b/src/solutions/ode_solutions.jl index 2fb0cf3b6..163d93017 100644 --- a/src/solutions/ode_solutions.jl +++ b/src/solutions/ode_solutions.jl @@ -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) + + 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 diff --git a/src/utils.jl b/src/utils.jl index aca5d24da..d14d5c2d8 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -538,3 +538,11 @@ See also: `prepare_initial_state`. """ prepare_function(f) = f +""" + strip_solution(sol) + +Strips a SciMLSolution object and its interpolation of their functions to better accommadate serialization. +""" +function strip_solution(sol::AbstractSciMLSolution) + sol +end \ No newline at end of file From baed4879bf4dbbb5896b6899dae79727a9554e60 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 12 Aug 2024 12:00:04 -0400 Subject: [PATCH 2/3] add test for ode_stripping --- test/downstream/ode_stripping.jl | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 test/downstream/ode_stripping.jl diff --git a/test/downstream/ode_stripping.jl b/test/downstream/ode_stripping.jl new file mode 100644 index 000000000..b11336974 --- /dev/null +++ b/test/downstream/ode_stripping.jl @@ -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) \ No newline at end of file From 00b913d31f63d2c450096f51fa47780992b8dfd5 Mon Sep 17 00:00:00 2001 From: jClugstor Date: Mon, 12 Aug 2024 14:08:32 -0400 Subject: [PATCH 3/3] fix typo --- src/utils.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.jl b/src/utils.jl index d14d5c2d8..24bee26d3 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -541,7 +541,7 @@ prepare_function(f) = f """ strip_solution(sol) -Strips a SciMLSolution object and its interpolation of their functions to better accommadate serialization. +Strips a SciMLSolution object and its interpolation of their functions to better accommodate serialization. """ function strip_solution(sol::AbstractSciMLSolution) sol