Open
Description
For example, the following code fails using Julia v1.6.0-rc3 and ModelingToolkit v5.13.6.
julia> using ModelingToolkit, OrdinaryDiffEq
julia> struct MyParameter
a::Float64
end
julia> f(du, u, p, t) = du .= p.a .* u
f (generic function with 1 method)
julia> ode = ODEProblem(f, ones(2), (0.0, 1.0), MyParameter(2.0))
ODEProblem with uType Vector{Float64} and tType Float64. In-place: true
timespan: (0.0, 1.0)
u0: [1.0, 1.0]
julia> sol = solve(ode, Tsit5())# the problem is set up correctly
julia> ode_mtk = modelingtoolkitize(ode)
ERROR: MethodError: no method matching keys(::MyParameter)
Closest candidates are:
keys(::Union{Tables.AbstractColumns, Tables.AbstractRow}) at ~/.julia/packages/Tables/UxLRG/src/Tables.jl:179
keys(::IndexStyle, ::AbstractArray, ::AbstractArray...) at abstractarray.jl:327
keys(::IterativeSolvers.ConvergenceHistory) at ~/.julia/packages/IterativeSolvers/TpeDx/src/history.jl:223
...
Stacktrace:
[1] eachindex(itrs::MyParameter)
@ Base ./abstractarray.jl:253
[2] modelingtoolkitize(prob::ODEProblem{Vector{Float64}, Tuple{Float64, Float64}, true, MyParameter, ODEFunction{true, typeof(f), LinearAlgebra.UniformScaling{Bool}, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, typeof(SciMLBase.DEFAULT_OBSERVED), Nothing}, Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}, SciMLBase.StandardODEProblem})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/7KM6m/src/systems/diffeqs/modelingtoolkitize.jl:21
[3] top-level scope
@ REPL[9]:1
Is it possible to use ModelingToolkit.jl to deal with general struct
s as parameter (p
in the ODEProblem
)?