ModellingToolkit issue with creating ODEProblem

Hi all,

I have encountered the same error multiple times when building a model, and I am not sure whether it is a bug or whether I am building the model wrong. Below is an example of the type of model that I am trying to build:

using ModelingToolkit
using ModelingToolkit: t_nounits as t, D_nounits as D
using DifferentialEquations

@parameters begin
    labourProductivity
    capitalProductivity
    wageRate
    depreciationRate
end

@variables begin
    totalDemand(t)
    output(t)
    investment(t)
    capital(t)
    wageBill(t)
end

eqs = [ totalDemand ~ wageBill + investment,
        output ~ min(totalDemand, capitalProductivity * capital),
        wageBill ~ wageRate * output / labourProductivity,
        investment ~ output - wageBill,
        D(capital) ~ investment - depreciationRate * capital,
        ]

@named sys = ODESystem(eqs, t)

simple = structural_simplify(sys)

inits = [output => 100]
params = [labourProductivity => 4, capitalProductivity => 1, wageRate => 2, 
    depreciationRate => .05]

problem = ODEProblem(simple, inits, (0,100), params)

sol = solve(problem, Euler(), dt=1)

Below is the error message that I get is when trying to create the ODEProblem. This message has come up multiple times with variations of this model.

ERROR: MethodError: no method matching AbstractFloat(::Type{SymbolicUtils.BasicSymbolic{Real}})

Closest candidates are:
  AbstractFloat(::Int16)
   @ Base float.jl:266
  AbstractFloat(::Bool)
   @ Base float.jl:264
  AbstractFloat(::UInt32)
   @ Base float.jl:272
  ...

Stacktrace:
  [1] float(x::Type)
    @ Base .\float.jl:294
  [2] promote_to_concrete(vs::Vector{SymbolicUtils.BasicSymbolic{Real}}; tofloat::Bool, use_union::Bool)
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\utils.jl:634
  [3] varmap_to_vars(varmap::Dict{…}, varlist::Vector{…}; defaults::Dict{…}, check::Bool, toterm::Function, promotetoconcrete::Nothing, tofloat::Bool, use_union::Bool)
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\variables.jl:163
  [4] get_u0(sys::NonlinearSystem, u0map::Dict{…}, parammap::Dict{…}; symbolic_u0::Bool, toterm::Function)
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:829
  [5] get_u0
    @ C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:816 [inlined]
  [6] process_NonlinearProblem(constructor::Type, sys::NonlinearSystem, u0map::Dict{…}, parammap::Dict{…}; version::Nothing, jac::Bool, checkbounds::Bool, sparse::Bool, simplify::Bool, linenumbers::Bool, parallel::Symbolics.SerialForm, eval_expression::Bool, use_union::Bool, tofloat::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:398
  [7] process_NonlinearProblem
    @ C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:384 [inlined]
  [8] (NonlinearProblem{…})(sys::NonlinearSystem, u0map::Dict{…}, parammap::Dict{…}; check_length::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:435
  [9] (NonlinearProblem{…})(sys::NonlinearSystem, u0map::Dict{…}, parammap::Dict{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:429
 [10] NonlinearProblem(::NonlinearSystem, ::Dict{Any, Any}, ::Vararg{Any}; kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:426
 [11] NonlinearProblem(::NonlinearSystem, ::Dict{Any, Any}, ::Vararg{Any})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\nonlinear\nonlinearsystem.jl:425
 [12] ModelingToolkit.InitializationProblem{…}(sys::ODESystem, t::Int64, u0map::Vector{…}, parammap::Dict{…}; guesses::Dict{…}, check_length::Bool, warn_initialize_determined::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1636
 [13] (ModelingToolkit.InitializationProblem{…})(::ODESystem, ::Int64, ::Vararg{…}; kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1572
 [14] ModelingToolkit.InitializationProblem(::ODESystem, ::Int64, ::Vararg{…}; kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1560
 [15] process_DEProblem(constructor::Type, sys::ODESystem, u0map::Vector{…}, parammap::Vector{…}; implicit_dae::Bool, du0map::Nothing, version::Nothing, tgrad::Bool, jac::Bool, checkbounds::Bool, sparse::Bool, simplify::Bool, linenumbers::Bool, parallel::Symbolics.SerialForm, eval_expression::Bool, use_union::Bool, tofloat::Bool, symbolic_u0::Bool, u0_constructor::typeof(identity), guesses::Dict{…}, t::Int64, warn_initialize_determined::Bool, build_initializeprob::Bool, kwargs::@Kwargs{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:921
 [16] process_DEProblem
    @ C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:834 [inlined]
 [17] (ODEProblem{…})(sys::ODESystem, u0map::Vector{…}, tspan::Tuple{…}, parammap::Vector{…}; callback::Nothing, check_length::Bool, warn_initialize_determined::Bool, kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1085
 [18] (ODEProblem{…})(sys::ODESystem, u0map::Vector{…}, tspan::Tuple{…}, parammap::Vector{…})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1075
 [19] (ODEProblem{true})(::ODESystem, ::Vector{Pair{Num, Int64}}, ::Vararg{Any}; kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1062
 [20] (ODEProblem{true})(::ODESystem, ::Vector{Pair{Num, Int64}}, ::Vararg{Any})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1061
 [21] ODEProblem(::ODESystem, ::Vector{Pair{Num, Int64}}, ::Vararg{Any}; kwargs::@Kwargs{})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1051
 [22] ODEProblem(::ODESystem, ::Vector{Pair{Num, Int64}}, ::Vararg{Any})
    @ ModelingToolkit C:\Users\robva\.julia\packages\ModelingToolkit\PtnSY\src\systems\diffeqs\abstractodesystem.jl:1050
 [23] top-level scope
    @ c:\Users\robva\ToBe\ToBe-Model\sandbox\test_symbolic_problems.jl:35

Any help is appreciated!

capital is missing an initial condition. I need to fix that error message.

1 Like

Thanks Chris, that solved it indeed!