Extracting local sensitivities when using save_idxs

When specifying the saveat keyword, the extraction of local sensitivites seems to fail.
The example is from the official documentation:

using DifferentialEquations
using DiffEqSensitivity
function f(du,u,p,t)
  du[1] = dx = p[1]*u[1] - p[2]*u[1]*u[2]
  du[2] = dy = -p[3]*u[2] + u[1]*u[2]
end

p = [1.5,1.0,3.0]
prob = ODELocalSensitivityProblem(f,[1.0;1.0],(0.0,10.0),p)
sol = solve(prob, saveat = [1.,2.], save_idxs = [2])
x,dp = extract_local_sensitivities(sol) # throws error

The error that is thrown says attempt to access 1x2 OrdinaryDiffEq.ODECompositeSolution{[...] at index [1:2, Base.Slice(Base.OneTo(2))]

If you only save_idxs = [2] then the sensitivities are never saved, since the sensitivities are equations 3-8 here. This isn’t an issue with saveat, rather the choice of what to save (save_idxs).

1 Like

Got it. Thanks!

If I used save_idxs = 2:8 the extraction would also fail, although I have saved all sensitivities as extract_local_sensitivities function is based on sol.prob.f.numindvar. Maybe a good idea to adjust that fur future versions.

Can you open an issue on DiffEqSensitivity? We just need to keep track of save_idxs so know which values you’ve dropped.

Sure. For the issue, see here.