# Issue with Local Sensitivites and dt \<= dtmin

**URL:** <https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426>\
**Category:** Numerics\
**Tags:** diffeq, forwarddiff\
**Created:** [May 21, 2022, 5:28pm UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426 "2022-05-21T17:28:12Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![xztt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xztt/32/33843_2.png) [@xztt](https://discourse.julialang.org/u/xztt)\
**Post date:** [May 21, 2022, 5:28pm UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426/1 "2022-05-21T17:28:12Z")

</div>

Hi,

I am trying to calculate the local sensitivities for a large circulation model [(Shi 2006)](https://models.physiomeproject.org/exposure/c49d416ae3a5132882e6ea7479ba50f5/ModelMain.cellml/view)

I am Importing the model using CellML.jl when I define an ODEproblem and simulate the solution appears fine and also when performing GSA the results are also sound.

Using the code

```julia
using ForwardDiff

savetime = LinRange(18, 19, 100)

p = prob.p 
u0 =prob.u0

function circ_local(x)
    newprob = remake(prob; p=x[1:end])
    sol = solve(newprob, Tsit5(); reltol=1e-6, abstol=1e-12,saveat = savetime)
    [mean(sol[@nonamespace sys.LV₊V]), mean(sol[@nonamespace sys.Pat₊Pi])]
end
S = ForwardDiff.jacobian(circ_local,p)

```

Note: all the solver opts I use are the same for both simulation and performing GSA.

The above returns the following warnings with the NAN’s

```julia
Warning: First function call produced NaNs. Exiting.
└ @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/ZBye7/src/initdt.jl:121
┌ Warning: dt <= dtmin. Aborting. There is either an error in your model specification or the true solution is unstable.
└ @ SciMLBase ~/.julia/packages/SciMLBase/Vg9hW/src/integrator_interface.jl:345
2×154 Matrix{Float64}:
 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN … NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
 NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

```

Any help would be very much appreciated 🙂

Cheers,  
Harry

---

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [May 21, 2022, 5:54pm UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426/2 "2022-05-21T17:54:32Z")

</div>

have you tried using a stiff solver?

---

<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 21, 2022, 6:48pm UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426/3 "2022-05-21T18:48:54Z")

</div>

Indeed, trying a method for stiff equations is the first thing to do in this case. Did you try it?

Follow the guide:

> [@PSA: How to help yourself debug differential equation solving issues](https://discourse.julialang.org/t/psa-how-to-help-yourself-debug-differential-equation-solving-issues/62489):
>
> Debugging differential equation solver issues almost always boils down to doing the same thing, so this is a summary to help you out. For more information on specific issues, check out the FAQ section of the DifferentialEquations.jl documentation which highlights common issues and questions: [https://diffeq.sciml.ai/dev/basics/faq/](https://diffeq.sciml.ai/dev/basics/faq/)How do I debug why the differential equation solver is diverging? dt \<= dtmin. Aborting. There is either an error in your model specification or the true solution i…

---

<div class="post-metadata">

**Author:** ![xztt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xztt/32/33843_2.png) [@xztt](https://discourse.julialang.org/u/xztt)\
**Post date:** [May 22, 2022, 10:57am UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426/4 "2022-05-22T10:57:05Z")

</div>

Hi @ChrisRackauckas & @Oscar_Smith

Tried a stiff solver and all the other solvers that I could find with increasingly high tolerances too.

![image](https://global.discourse-cdn.com/julialang/original/3X/3/4/34b88ee9f5b8b177ef44964218913e96395ede0b.png)

The Image above is the graph of the solution at the savetime.

I hate to sound exactly like the meme in the guide above just I am cautious to claim model error seen as the simulation and function for GSA works well plus I am loading the model in from CellML.

Also intersting when I try and run the model for Waveform data

```julia
function circ_local(params)
    newprob = remake(prob; p=params[1:end])
    newsol = solve(newprob, KenCarp4(); reltol=1e-12, abstol=1e-12, saveat=savetime)
    [newsol[@nonamespace sys.LV₊V]; newsol[@nonamespace sys.Sas₊Pi] ]
end
S = ForwardDiff.jacobian(circ_local,p)

```

The outcome is a 0x154 and errors in the same fashion as the above

```julia
┌ Warning: First function call produced NaNs. Exiting.
└ @ OrdinaryDiffEq ~/.julia/packages/OrdinaryDiffEq/ZBye7/src/initdt.jl:121
┌ Warning: dt <= dtmin. Aborting. There is either an error in your model specification or the true solution is unstable.
└ @ SciMLBase ~/.julia/packages/SciMLBase/Vg9hW/src/integrator_interface.jl:345
0×154 Matrix{Float64}

```

I also feel I probably should have added this extra point in yesterday however I did not give it much thought when solving the model using

```julia
ml = CellModel("/home/harry/Desktop/PhD/Year 1/Sem 2/CellML project/shi_hose_2009/shi_hose_2009-a679cdc2e974/ModelMain.cellml")
prob = ODEProblem(ml, (0.0,20.0))
sol = solve(prob, TRBDF2(), reltol=1e-6, abstol=1e-12)

```

I recieve the following warning

```julia
Warning: Unrecognized keyword arguments found. Future versions will error.
│ The only allowed keyword arguments to `solve` are: 
│ (:dense, :saveat, :save_idxs, :tstops, :d_discontinuities, :save_everystep, :save_on, :save_start, :save_end, :initialize_save, :adaptive, :abstol, :reltol, :dt, :dtmax, :dtmin, :force_dtmin, :internalnorm, :controller, :gamma, :beta1, :beta2, :qmax, :qmin, :qsteady_min, :qsteady_max, :qoldinit, :failfactor, :calck, :alias_u0, :maxiters, :callback, :isoutofdomain, :unstable_check, :verbose, :merge_callbacks, :progress, :progress_steps, :progress_name, :progress_message, :timeseries_errors, :dense_errors, :calculate_errors, :initializealg, :alg, :save_noise, :delta, :seed, :alg_hints, :kwargshandle, :trajectories, :batch_size, :sensealg, :advance_to_tstop, :stop_at_next_tstop, :default_set, :second_time)
│ See https://diffeq.sciml.ai/stable/basics/common_solver_opts/ for more details.
│ 
│ Set kwargshandle=KeywordArgError for an error message and more details.
│ Set kwargshandle=KeywordArgSilent to ignore this message.
└ @ DiffEqBase ~/.julia/packages/DiffEqBase/dVZCn/src/solve.jl:346

```

I checked this morning and this warning is not present when I formulate an ODE problem not using CellML, could this be related?

Cheers

---

<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 22, 2022, 12:14pm UTC](https://discourse.julialang.org/t/issue-with-local-sensitivites-and-dt-dtmin/81426/5 "2022-05-22T12:14:33Z")

</div>

That sounds like a problem with the CellML reader then. Open an issue there with the file you’re trying to read. Do you also have the SBML from the SBMLBiomodels repository? That could be a possible way to read it in: the CellML reader has had less work than SBMLToolbox.jl

> [@xztt](#):
>
> I checked this morning and this warning is not present when I formulate an ODE problem not using CellML, could this be related?

There was a version of MTK which was passing an argument that it shouldn’t’ve. That got cleaned up and the latest versions should be fine if you upgrade.

> <https://github.com/SciML/ModelingToolkit.jl/pull/1584>
>
> Fixes https://github.com/SciML/ModelingToolkit.jl/issues/1583
> 
> If this is ok, …would be good to get a bug fix release once merged.
