# DifferentialEquations: ┌ Warning: IDAGetDky failed with error code

**URL:** <https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195>\
**Category:** Numerics\
**Created:** [December 21, 2020, 7:09pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195 "2020-12-21T19:09:51Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 21, 2020, 7:09pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/1 "2020-12-21T19:09:51Z")

</div>

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:

```julia
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)

```

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 21, 2020, 11:20pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/2 "2020-12-21T23:20:52Z")

</div>

> [@JuhaHeiskala](#):
>
> `function rob(t, u, du)`

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

[https://diffeq.sciml.ai/stable/tutorials/dae\_example/](https://diffeq.sciml.ai/stable/tutorials/dae_example/)

```julia
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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 21, 2020, 11:22pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/3 "2020-12-21T23:22:01Z")

</div>

> [@JuhaHeiskala](#):
>
> ```julia
> 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
> 
> ```

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

[https://diffeq.sciml.ai/stable/features/callback\_functions/](https://diffeq.sciml.ai/stable/features/callback_functions/)

---

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 22, 2020, 6:18am UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/4 "2020-12-22T06:18:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 22, 2020, 11:59am UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/5 "2020-12-22T11:59:29Z")

</div>

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

> [@JuhaHeiskala](#):
>
> DiffEq.get\_du(integrator)

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

---

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 22, 2020, 3:10pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/6 "2020-12-22T15:10:53Z")

</div>

`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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 22, 2020, 3:30pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/7 "2020-12-22T15:30:00Z")

</div>

> [@JuhaHeiskala](#):
>
> With “save\_everystep=true” the IDA warning/error is triggered and the second event is not detected.

That is worth an issue.

---

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 22, 2020, 3:59pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/8 "2020-12-22T15:59:40Z")

</div>

> 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.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [December 22, 2020, 4:05pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/9 "2020-12-22T16:05:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 22, 2020, 8:42pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/10 "2020-12-22T20:42:24Z")

</div>

Ok, I reported the issue in the Sundials GitHub.

---

<div class="post-metadata">

**Author:** ![JuhaHeiskala](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@JuhaHeiskala](https://discourse.julialang.org/u/JuhaHeiskala)\
**Post date:** [December 22, 2020, 11:30pm UTC](https://discourse.julialang.org/t/differentialequations-warning-idagetdky-failed-with-error-code/52195/11 "2020-12-22T23:30:40Z")

</div>

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.
