# DifferentialEquations: ┌ Warning: IDAGetDky failed with error code

I tried a test case from Octave ode15i tests and get the error:

[IDAS ERROR] IDAGetDky
Illegal value for k.

┌ Warning: IDAGetDky failed with error code =
│ flag = -25
└ @ Sundials ~/.julia/dev/Sundials/src/simple.jl:20

The error happens with “save_everystep=true” option. With “save_everystep=false” the error does not happen.
The test should have two events, the second event terminates the problem.
When the error happens the second event is not detected. Without the error both events are detected. Could the problem be with IDA or DiffEq?
I recall having tested this some time ago (>year) and I think at that time it worked with save_everystep=true option, but I don’t have the version of DiffEq used at that time.

This is with Julia 1.5.3 and “[0c46a032] DifferentialEquations v6.15.0”
Below the code to test this:

``````import DifferentialEquations
const DiffEq = DifferentialEquations

function rob(t, u, du)
res =[-(du[1] + 0.04*u[1] - 1e4*u[2]*u[3]),
-(du[2] - 0.04*u[1] + 1e4*u[2]*u[3] + 3e7*u[2]^2),
u[1] + u[2] + u[3] - 1]

return res
end

function event1(t, u, du)
if (t < 1e1)
val = -1
else
val = 1
end
return val
end

function event2(t, u, du)
if (t < 1e1)
val = -2
else
val = 3
end
return val
end

ode_rob = (out, du, u, p, t) -> (out[:] .= rob(t, u, du); out)

dae_f = DiffEq.DAEFunction(ode_rob)

tspan = (0.0, 100.0)
u0 = [1.0, 0.0, 0.0]
du0 = [-1e-4, 1e-4, 0.0]
differential_vars = [true, true,true]

dae_prob = DiffEq.DAEProblem(dae_f, du0, u0, tspan; differential_vars)

cond1 = (u, t, integrator) -> event1(t, u, DiffEq.get_du(integrator))
cond2 = (u, t, integrator) -> event2(t, u, DiffEq.get_du(integrator))

affect1 = (integrator)-> (println("Event 1 at time: \$(integrator.t)"); integrator)
affect2 = (integrator)-> (println("Event 2 at time: \$(integrator.t)"); DiffEq.terminate!(integrator))

cb1 = DiffEq.ContinuousCallback(cond1, affect1, nothing)
cb2 = DiffEq.ContinuousCallback(cond2, affect2)

cb_set = DiffEq.CallbackSet(cb1, cb2)

println("Sol 1")
sol1 = DiffEq.solve(dae_prob, DiffEq.IDA(); save_everystep=false,callback=cb_set)

println("Sol 2")
sol2 = DiffEq.solve(dae_prob, DiffEq.IDA(); save_everystep=true,callback=cb_set)
``````

This differential equation doesn’t have the right function signature. This is the same problem that is solved in the documentation though:

``````function f(out,du,u,p,t)
out[1] = - 0.04u[1]              + 1e4*u[2]*u[3] - du[1]
out[2] = + 0.04u[1] - 3e7*u[2]^2 - 1e4*u[2]*u[3] - du[2]
out[3] = u[1] + u[2] + u[3] - 1.0
end
``````

Judging by your code, it wouldn’t’ve worked since Julia v0.5 or approximately 2017.

This isn’t the right signature for defining events. See the event handling documentation:

Thanks for the reply. I have glue-functions to translate the Octave ode15i-interface functions to DiffEq signature. The glue functions should have the right signatures, as far as I can tell. I was testing, if I could directly use the Octave type ode-functions with the glue to translate to DiffEq interface. (whether this makes sense, is another question. )

ode_rob = (out, du, u, p, t) -> (out[:] .= rob(t, u, du); out)
cond1 = (u, t, integrator) -> event1(t, u, DiffEq.get_du(integrator))
cond2 = (u, t, integrator) -> event2(t, u, DiffEq.get_du(integrator))

I did notice that I had all variables as differential, but changing the last variable to not be differential still produces the IDA error and the second event is not detected.

Well look at the answer in the documentation. Since that runs it’ll tell you what you need to do.

that’s not correct because that’s not at the right time. `integrator(t,Val{1})` would be required.

`integrator(t,Val{1})` would be required.

Thanks, corrected that.

The code/solution works without the event callbacks. The example in the documentation doesn’t have the event callbacks.
With the event callbacks given as option, the events are detected when “save_everystep=false” option is given. With “save_everystep=true” the IDA warning/error is triggered and the second event is not detected.

That is worth an issue.

That is worth an issue.

Ok, should I do it somewhere?
If it might help I can try go back to find the version of DifferentialEquations this worked with.

I think it’s because of how `integrator(t)` is interpolating, but it should be using IDAGetDky correctly. This is a Sundials.jl-specific issue.

Ok, I reported the issue in the Sundials GitHub.

I also checked that the problem has shown up in Sundials 3.9.
The code worked with Sundials 3.8.3 without the IDA error.