# Parameters of IDA DAE solver

**URL:** https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366
**Category:** Modelling & Simulations
**Tags:** question
**Created:** [May 18, 2021, 2:45pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366 "2021-05-18T14:45:32Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 18, 2021, 2:45pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/1 "2021-05-18T14:45:32Z")

</div>

I have the following code:

```julia
using DifferentialEquations, Sundials, StaticArrays
using Revise

if ! @isdefined KPS3
    includet("../src/KPS3.jl")
    using .KPS3
end

my_state = KPS3.get_state()
clear(my_state)
y0, yd0 = KPS3.init(my_state)

tspan = (0.0, 0.05) # time span; fails when changed to (0.0, 0.06)

differential_vars = ones(Bool, 36)
prob = DAEProblem(residual!, yd0, y0, tspan, differential_vars=differential_vars)

sol = solve(prob, IDA(), saveat=0.001, abstol=0.01, reltol=0.001)

time = sol.t
println(sol.retcode)

pos_x = sol[3*5+1, :]
pos_z = sol[3*5+3, :]

```

It works fine. You can check it out here: [https://github.com/ufechner7/KiteViewer/tree/sim](https://github.com/ufechner7/KiteViewer/tree/sim)  
(careful, use branch sim)

But if I increase the simulation time to 0.06 seconds it fails with the following error  
message:

```julia
julia> include("src/RTSim.jl")

[IDAS ERROR] IDASolve
  At t = 0.0599924 and h = 2.40789e-162, the corrector convergence failed repeatedly or with |h| = hmin.

  3.462572 seconds (10.40 M allocations: 599.441 MiB, 15.08% gc time)
ConvergenceFailure

```

I would like to set the following parameters of the solver to make it work:

```julia
        inith = 0.002
        maxord = 3

        pos_tol = 2.0/ 100.0
        vel_tol = pos_tol / 60.0
        atol = vel_tol * ones(36)
        for i in 1:18
            atol[i] = pos_tol
        end
        rtol = 1e-3

```

The names I am using here are coming from the Python/ Assimulo code that I am converting to Julia,  
so I might have to use slightly different names. (See: [IDA — Assimulo 3.0 documentation](https://jmodelica.org/assimulo/DAE_IDA.html))

Special question: Can I use arrays for the absolute end the relative tolerance?

Any ideas how to set inith, maxord, rtol and atol when using IDA from DifferentialEquations?

Uwe

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 18, 2021, 4:33pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/2 "2021-05-18T16:33:47Z")

</div>

I created an issue: [Document IDA options · Issue #306 · SciML/Sundials.jl · GitHub](https://github.com/SciML/Sundials.jl/issues/306)

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 18, 2021, 4:54pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/3 "2021-05-18T16:54:47Z")

</div>

OK, I found the functions:  
function IDASVtolerances(ida\_mem, reltol::realtype, abstol::N\_Vector)  
function IDASetMaxOrd(ida\_mem, maxord::Cint)  
function IDASetInitStep(ida\_mem, hin::realtype)

In the file:  
[https://github.com/SciML/Sundials.jl/blob/master/src/API/idas.jl](https://github.com/SciML/Sundials.jl/blob/master/src/API/idas.jl)

But how can I use them?

Where do I get ida\_mem from?

---

<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: [May 18, 2021, 5:39pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/4 "2021-05-18T17:39:41Z")

</div>

> [@ufechner7](#):
>
> Any ideas how to set inith, maxord, rtol and atol when using IDA from DifferentialEquations?

Most of those are common arguments documented in the same place they always are:

[https://diffeq.sciml.ai/stable/basics/common\_solver\_opts/](https://diffeq.sciml.ai/stable/basics/common_solver_opts/)

The order though is specific to IDA, so it’s documented in the same place all of the algorithm-specific arguments are, i.e. in the algorithm’s documentation.

[https://diffeq.sciml.ai/stable/solvers/dae\_solve/#Sundials.jl](https://diffeq.sciml.ai/stable/solvers/dae_solve/#Sundials.jl)

It all follows a pattern.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 18, 2021, 6:42pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/5 "2021-05-18T18:42:42Z")

</div>

Ok, but how can I specify a vector for abstol?

---

<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: [May 18, 2021, 6:43pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/6 "2021-05-18T18:43:13Z")

</div>

Just make it a vector. `solve(prob,alg,abstol=[1e-3,1e-4])`

> The scaled error is guaranteed to be `<1` for a given local error estimate (note: error estimates are local unless the method specifies otherwise). `abstol` controls the non-scaling error and thus can be though of as the error around zero. `reltol` scales with the size of the dependent variables and so one can interpret `reltol=1e-3` as roughly being (locally) correct to 3 digits. Note tolerances can be specified element-wise by passing a vector whose size matches `u0` .

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 18, 2021, 6:43pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/7 "2021-05-18T18:43:53Z")

</div>

OK, lets see if that works.

---

<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: [May 18, 2021, 6:45pm UTC](https://discourse.julialang.org/t/parameters-of-ida-dae-solver/61366/8 "2021-05-18T18:45:05Z")

</div>

It should, for reference the source code shows how the common interface lowers to using the functions you’re talking about:

> <https://github.com/SciML/Sundials.jl/blob/v4.4.3/src/common_interface/solve.jl#L1159-L1163>
