# PSA: detected non-constant types in an out-of-place ODE solve

**URL:** <https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077>\
**Category:** Community\
**Tags:** announcement, diffeq\
**Created:** [June 20, 2022, 3:31pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077 "2022-06-20T15:31:45Z")\
**Posts on this page:** 7\
**Page:** 1

<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:** [June 20, 2022, 3:31pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/1 "2022-06-20T15:31:45Z")

</div>

If you suddenly started seeing an error message from an OrdinaryDiffEq.jl (DifferentialEquations.jl) solver like:

```julia
Detected non-constant types in an out-of-place ODE solve, i.e. for
`du = f(u,p,t)` we see `typeof(du) !== typeof(u)`. This is not
supported by OrdinaryDiffEq.jl's solvers. Please either make `f`
type-constant (i.e. typeof(du) === typeof(u)) or use the mutating
in-place form `f(du,u,p,t)` (which is type-constant by construction).
Note that one common case for this is when computing with GPUs, using
`Float32` for `u0` and `Float64` for `tspan`. To correct this, ensure
that the element type of `tspan` matches the preferred compute type,
for example `ODEProblem(f,0f0,(0f0,1f0))` for `Float32`-based time.

  typeof(u/t) = Vector{ComplexF64}
  typeof(du) = Vector{Float64}

```

The reason is [Informative error if the type from the first call is non-constant by ChrisRackauckas · Pull Request #1685 · SciML/OrdinaryDiffEq.jl · GitHub](https://github.com/SciML/OrdinaryDiffEq.jl/pull/1685) and OrdinaryDiffEq.jl v6.16. For the most part, this new error check finds cases that would otherwise error deeper in the code (and thus this should be a much more clear error message).

However, there were a few cases which previously worked and now throw this error. All of those cases were found to be subtle performance bugs. For example, there were cases where `u0` was `CuArray{Float32}` but `tspan` was `Float64`. This would technically work because internally it would upconvert to Float64, and then downconvert to `u0`’s type when trying to write the output after the Runge-Kutta steps. But, clearly, you don’t want to run Float64 on GPUs and so this found a real performance bug. Another case was found with an ODE function that would always return real even though its initial condition was Complex: something the user probably wants to fix to be a real valued ODE solve.

So because of this behavior, we know that there are some codes now throwing this error but we are considering it a non-breaking change as the codes which break seem to only be bugs and not really supported behavior. If you have any behavior that seems to require this, please share a simplified description of how this arises. We can create a Preferences option to opt-out of this error message, but for now it seems like every case shouldn’t opt-out and instead improve their code.

---

<div class="post-metadata">

**Author:** ![Cory\_Simon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cory_simon/32/3950_2.png) [@Cory\_Simon](https://discourse.julialang.org/u/Cory_Simon)\
**Post date:** [June 15, 2024, 5:28pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/2 "2024-06-15T17:28:16Z")

</div>

I’m getting this error when using `DifferentialEquations.jl` v7.13.0 with `Turing.jl`.  
very oddly, the error isn’t consistent. it shows up only sometimes, during the MCMC sampling of parameters for the ODE.

---

<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:** [June 15, 2024, 5:37pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/3 "2024-06-15T17:37:11Z")

</div>

In order to know why you’d have to share you code so it’s clear what the input/output types are.

---

<div class="post-metadata">

**Author:** ![cbilllingham1983](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@cbilllingham1983](https://discourse.julialang.org/u/cbilllingham1983)\
**Post date:** [March 2, 2025, 10:58pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/4 "2025-03-02T22:58:16Z")

</div>

> [@ChrisRackauckas](#):
>
> So because of this behavior, we know that there are some codes now throwing this error but we are considering it a non-breaking change as the codes which break seem to only be bugs and not really supported behavior. If you have any behavior that seems to require this, please share a simplified description of how this arises.

Hi I’m getting the same error when I try to run this code for multiple shooting in the DiffEqFlux examples section:

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

I’m running Julia 1.10.8 on a 2024 MacBook with Apple Silicon hardware. Any advice?

---

<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:** [March 2, 2025, 11:09pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/5 "2025-03-02T23:09:00Z")

</div>

That’s not possible. You aren’t showing an out of place ODE solve. Please share a code that is copy-pastable that reproduces the behavior. Also, please make it in a separate thread.

---

<div class="post-metadata">

**Author:** ![cbilllingham1983](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@cbilllingham1983](https://discourse.julialang.org/u/cbilllingham1983)\
**Post date:** [March 2, 2025, 11:37pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/6 "2025-03-02T23:37:11Z")

</div>

Sorry I’ll post this in a separate thread. I’m new and it told me I’m not allowed to post links (e.g to github) - I’m trying to reproduce the script on this example page:

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

---

<div class="post-metadata">

**Author:** ![cbilllingham1983](https://avatars.discourse-cdn.com/v4/letter/c/a88e57/32.png) [@cbilllingham1983](https://discourse.julialang.org/u/cbilllingham1983)\
**Post date:** [March 2, 2025, 11:42pm UTC](https://discourse.julialang.org/t/psa-detected-non-constant-types-in-an-out-of-place-ode-solve/83077/7 "2025-03-02T23:42:00Z")

</div>

Posted a new thread titled: [Non-constant types in out-of-place ODE solve with multshooting?]
