# Problem understanding results of DiffEqUncertainty

**URL:** <https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193>\
**Category:** Modelling & Simulations\
**Tags:** question, diffeq\
**Created:** [November 9, 2021, 9:22am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193 "2021-11-09T09:22:40Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrBellamy](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@MrBellamy](https://discourse.julialang.org/u/MrBellamy)\
**Post date:** [November 9, 2021, 9:22am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/1 "2021-11-09T09:22:40Z")

</div>

I have issues using the librairie DiffEqUncertainty.jl or at least understanding the results. I have a DAE made of 4 differential equations and 1 algebric equations. I defined it using a mass matrix and I am solving it with an ODE solver like this

solve(prob\_MM, Rodas5(), reltol = 1e-8, abstol=1e-12, callback=cbs, maxiters = 1e7)

The solver manage to solve it without issue :  
9.159245 seconds (21.20 M allocations: 1.964 GiB, 9.29% gc time, 0.10% compilation time)

and I can plot the solution. It looks like that

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/0/80f86ab4dde8a7108afbb3d0f0e0507502afe421.png)

which is what I was expecting. So far so good. Now I tried to see how sensitive my solutions was, so I used the librairie DiffEqUncertainty.jl with the lines

cb\_uncert = AdaptiveProbIntsUncertainty(5)  
ensemble\_prob = EnsembleProblem(prob\_MM)  
sim = solve(ensemble\_prob, Rodas5(), reltol = 1e-10, abstol=1e-12, trajectories=5, callback=cbs)  
(cb\_uncert is added to cbs using cbs = CallbackSet(others\_cb, cb\_uncert ))

Then the simulation takes a really long time with A LOT of allocation

6588.658787 seconds (21.72 G allocations: 3.086 TiB, 52.83% gc time, 0.00% compilation time)

and the solution is really not smooth, like this :

 ![image](https://global.discourse-cdn.com/julialang/original/3X/1/c/1cfb2d7adca7b127650ee09068ad07d762f95f78.png)

I was expecting results similar in smoothness as those ones [https://diffeq.sciml.ai/stable/analysis/uncertainty\_quantification/](https://diffeq.sciml.ai/stable/analysis/uncertainty_quantification/)  
What could be the cause of this behaviour ? Is my system extremely unstable or is it something else ? Why does it take so many allocations ? I would say the specificity of my system is that I interpolate many thermodynamical properties, so the code is quite heavy and not very practical to post here.

---

<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:** [November 9, 2021, 11:46am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/2 "2021-11-09T11:46:03Z")

</div>

> [@MrBellamy](#):
>
> I defined it using a mass matrix and I am solving it with an ODE solver like this
> 
> solve(prob\_MM, Rodas5(), reltol = 1e-8, abstol=1e-12, callback=cbs, maxiters = 1e7)

Don’t use Rodas5 for this. The documentation says why. Try Rodas4 here.

---

<div class="post-metadata">

**Author:** ![MrBellamy](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@MrBellamy](https://discourse.julialang.org/u/MrBellamy)\
**Post date:** [November 10, 2021, 8:32am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/3 "2021-11-10T08:32:54Z")

</div>

What I found in the doc about Rodas5 is that : “Currently has a Hermite interpolant because its stiff-aware 3rd order interpolant is not yet implemented”. Is this the reason why I should not use it ? I don’t understand it. Anywway, I tried Rodas4 as suggested, it took much longer :

16113.129405 seconds (23.94 G allocations: 3.447 TiB, 74.66% gc time, 0.00% compilation time)

but the results seem a bit better though really not smooth

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/2/a280bfab8f4a31e0d572c309fc06e8f77ce86219.png)

How come it takes so long for the uncertainty calculations when individually the simulation is relatively fast (9.1 s) and why does it take so much allocations ? I guess it is linked with the non-smooth nature of the solution but I cannot understand why ?

---

<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:** [November 10, 2021, 11:12am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/4 "2021-11-10T11:12:58Z")

</div>

> [@MrBellamy](#):
>
> What I found in the doc about Rodas5 is that : “Currently has a Hermite interpolant because its stiff-aware 3rd order interpolant is not yet implemented”. Is this the reason why I should not use it ?

It’s much more explicit than that in the docs.

[https://diffeq.sciml.ai/stable/solvers/dae\_solve/#Rosenbrock-Methods](https://diffeq.sciml.ai/stable/solvers/dae_solve/#Rosenbrock-Methods)

> - `Rodas5` - A 5th order A-stable stiffly stable Rosenbrock method. Currently has a Hermite interpolant because its stiff-aware 3rd order interpolant is not yet implemented. This means the interpolation is inaccurate on algebraic variables, meaning this algorithm should not be used with `saveat` or post-solution interpolation on DAEs.

So if the non-smooth behavior was in the algebraic variables, then that would be the explanation. If it’s in the differential variables, and that explosion… I think you might be doing something wrong in your `f` function. See:

> [@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…

One guess, do you happen to modify `u`?

---

<div class="post-metadata">

**Author:** ![MrBellamy](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@MrBellamy](https://discourse.julialang.org/u/MrBellamy)\
**Post date:** [November 12, 2021, 8:41am UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/5 "2021-11-12T08:41:13Z")

</div>

Indeed it is more explicit than that, I only looked at this page :  
[https://diffeq.sciml.ai/stable/solvers/ode\_solve/](https://diffeq.sciml.ai/stable/solvers/ode_solve/)  
where the explanation was more succinct.

I had looked at your PSA post which is very useful, thanks for that, unfortunately I checked already those points. The problem is that my code works perfectly when I solve it “alone” and most of the tips on this page are for ODE system that cannot get solved.

I am not modifying u or f either in my code. I had a “max” function in my f function that I transformed into a smooth max using [0.5\* x \* (1 + erf(x/sqrt(2.0))) - Wolfram|Alpha](https://www.wolframalpha.com/input/?i=0.5*+x+*+%281+%2B+erf%28x%2Fsqrt%282.0%29%29%29)  
and I relaunched the uncertainty code but it took even longer and displayed similar behaviour :

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/0/90ee151af248abfb12785d4ca53d317da9cd7c5f.png)

Could it be a normal behaviour linked with the stiffness of my model ?

---

<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:** [November 12, 2021, 3:48pm UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/6 "2021-11-12T15:48:24Z")

</div>

Nah, that’s not a stiffness thing. That looks like a caching problem. If you can open an issue with your code it could be looked into more.

---

<div class="post-metadata">

**Author:** ![MrBellamy](https://avatars.discourse-cdn.com/v4/letter/m/ad7895/32.png) [@MrBellamy](https://discourse.julialang.org/u/MrBellamy)\
**Post date:** [November 15, 2021, 1:53pm UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/7 "2021-11-15T13:53:04Z")

</div>

Ok, I cleaned the code a bit and posted an issue on the github :  
[https://github.com/SciML/DiffEqUncertainty.jl/issues/57](https://github.com/SciML/DiffEqUncertainty.jl/issues/57)

I hope it is the proper place, I am quite new to this.

---

<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:** [November 15, 2021, 1:57pm UTC](https://discourse.julialang.org/t/problem-understanding-results-of-diffequncertainty/71193/8 "2021-11-15T13:57:55Z")

</div>

That’s the right place, thanks.
