Hi. I’m a ModellingToolkit newbie (and DE in general).
I wrote some code last December which now throws the error Differentiation of expressions involving arrays and array variables is not yet supported.
I saw that raising the error has been introduced in this pull request 530, and I have a couple of simple ways to avoid it… but I don’t have much understanding of what’s going on, so I would like some feedback.
Here is what I want to do.
I have some arrays of various lengths v_1, ..., v_n, and I want to define an ODE system whose equations are of the form \frac d{dt} f_i(t)= g_i(f_i(t)) such that g_i(x) = f(x, v_i) for some f.
Back in December it seemed that I could indeed register only f and achieve my goal as in this MWE, but now it raises the error mentioned above.
using ModelingToolkit, DifferentialEquations
function f(x, y)
sum(y)*x
return x
end
@register f(x, y::AbstractVector)
@variables t h(t) w(t) k(t)
a = rand(10)
b = rand(5)
D = Differential(t)
eqs = [
D(h) ~ f(w, a)
D(w) ~ f(k, b)
D(k) ~ 1
]
@named sys = ODESystem(eqs)
sys = structural_simplify(sys)
u0 = [h => 1, w => 1, k => 1]
tspan = (0.0, 1.0)
prob = ODEProblem(sys, u0, tspan, jac=true)
sol = solve(prob)
No error is issued if either

AbstractVector
is replaced withNTuple
or  We remove the arg
jac=true
fromODEProblem
.
Are both solutions fine?
As a side question (probably worth a separate thread?), I also had an hard time finding information about what jac=true
means in the documentation. The most relevant page seems to be this one, and it seems to be that jac=false
is equivalent to jac=nothing
but I don’t get what jac=true
means.