Description
When running on an ODE solve the solver kicks a non-concrete error message, I've included a MWE of a Lotka-Volterra system demonstrating the behavior. I get the same error for an in-place solve
function lv_ode(u, p, t)
x, y = u
α, β, δ, γ = p
return [α*x - β*x*y;
δ*x*y - γ*y]
end
u0_lv = [10.0; 100.0]
p_lv = [.3; .015; .015; .7]
tspan_lv = (0.0, 100.0)
lv_prob = ODEProblem(lv_ode, u0_lv, tspan_lv, p_lv)
function taylordiff_lv(x, prob)
_prob = remake(prob, u0=x)
return Array(solve(_prob, Vern9(), abstol=1E-13, reltol=1E-13, save_start=false, save_everystep=false))[:, end]
end
# Checking other Derivative Methods
ad_jac = ForwardDiff.jacobian((x) -> taylordiff_lv(x, lv_prob), u0_lv)
fd_jac = FiniteDifferences.jacobian(central_fdm(5, 1), (x) -> taylordiff_lv(x, lv_prob), u0_lv)[1]
td_jac = derivative((x)->taylordiff_lv(x, lv_prob), u0_lv, [1.0; 0.0], 1)
ERROR: Non-concrete element type inside of an
Array
detected.
Arrays with non-concrete element types, such as
Array{Union{Float32,Float64}}
, are not supported by the
differential equation solvers. Anyways, this is bad for
performance so you don't want to be doing this!If this was a mistake, promote the element types to be
all the same. If this was intentional, for example,
using Unitful.jl with different unit values, then use
an array type which has fast broadcast support for
heterogeneous values such as the ArrayPartition
from RecursiveArrayTools.jl.
I tried using the solution suggested in the error with the line
_prob = remake(prob, u0=ArrayPartition(x))
and converting to an in-place solve
function lv_ode!(du, u, p, t)
x, y = u
α, β, δ, γ = p
du[1:2] =[α*x - β*x*y;
δ*x*y - γ*y]
nothing
end
but get the the following error instead
ERROR: MethodError: no method matching zero(::Type{Any})