# Type instability when solving ODEProblem

**URL:** <https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687>\
**Category:** Performance\
**Tags:** type-stability, differentialequation\
**Created:** [November 2, 2023, 10:47am UTC](https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687 "2023-11-02T10:47:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Post date:** [November 2, 2023, 10:47am UTC](https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687/1 "2023-11-02T10:47:07Z")

</div>

Hello, in the following I show a minimal working example of the problem. I want to implement a type stable function that solves an ODE. But I figured out that the `solve` function returns `Any` type. This is the minimal code:

```julia
function prova(A, b, tspan; alg=Tsit5())
    prob = ODEProblem{true}(prova_func, b, tspan, (L=A,))
    sol = solve(prob, alg)
    return prova(sol)
end

function prova(sol)
    return sol.u
end

prova_func(du, u, p, t) = mul!(du, p.L, u)

A = rand(5,5)
b = rand(5)
tspan = (0, 1)
res = prova(A, b, tspan)

```

but when I use Cthulhu to discover type instabilities, I see that the function `solve` returns `Any`. After that, it is impossible for julia to identify the type of the outcome of the solution.

How to solve it?

---

<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 2, 2023, 1:57pm UTC](https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687/2 "2023-11-02T13:57:18Z")

</div>

simplify the problem a bit by making `tspan` floats. If not remake is required then is it fine? Our inference tests do pass so it should be the case.

---

<div class="post-metadata">

**Author:** ![albertomercurio](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/albertomercurio/32/27051_2.png) [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Post date:** [November 2, 2023, 10:41pm UTC](https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687/3 "2023-11-02T22:41:34Z")

</div>

Thanks, making tspan float solved the problem.

---

<div class="post-metadata">

**Author:** ![Maysam\_Gholampour](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maysam_gholampour/32/218184_2.png) [@Maysam\_Gholampour](https://discourse.julialang.org/u/Maysam_Gholampour)\
**Post date:** [June 7, 2024, 3:57pm UTC](https://discourse.julialang.org/t/type-instability-when-solving-odeproblem/105687/4 "2024-06-07T15:57:26Z")

</div>

Is it a good idea to use `prova(sol)` as a function barrier? Is there any other way? Sorry, I am a newbie.

update: I have found ODEProblem{true, SciMLBase.AutoSpecialize}, I am working on it to know what’s going on. Thanks
