I am having some issues with ModelingTookit.
I tried to run the example copy-paste code from the documentation. Component-Based Modeling a Spring-Mass System · ModelingToolkit.jl
using ModelingToolkit, Plots, DifferentialEquations, LinearAlgebra
using Symbolics: scalarize
@variables t
D = Differential(t)
function Mass(; name, m = 1.0, xy = [0., 0.], u = [0., 0.])
ps = @parameters m=m
sts = @variables pos[1:2](t)=xy v[1:2](t)=u
eqs = scalarize(D.(pos) .~ v)
ODESystem(eqs, t, [pos..., v...], ps; name)
end
function Spring(; name, k = 1e4, l = 1.)
ps = @parameters k=k l=l
@variables x(t), dir[1:2](t)
ODESystem(Equation[], t, [x, dir...], ps; name)
end
function connect_spring(spring, a, b)
[
spring.x ~ norm(scalarize(a .- b))
scalarize(spring.dir .~ scalarize(a .- b))
]
end
spring_force(spring) = -spring.k .* scalarize(spring.dir) .* (spring.x - spring.l) ./ spring.x
m = 1.0
xy = [1., -1.]
k = 1e4
l = 1.
center = [0., 0.]
g = [0., -9.81]
@named mass = Mass(m=m, xy=xy)
@named spring = Spring(k=k, l=l)
eqs = [
connect_spring(spring, mass.pos, center)
scalarize(D.(mass.v) .~ spring_force(spring) / mass.m .+ g)
]
@named _model = ODESystem(eqs, t)
@named model = compose(_model, mass, spring)
sys = structural_simplify(model)
prob = ODEProblem(sys, [], (0., 3.))
sol = solve(prob, Rosenbrock23())
plot(sol)
I get the following error
ERROR: MethodError: no method matching AbstractFloat(::Type{Term{Float64, Nothing}})
Closest candidates are:
(::Type{T})(::SymbolicUtils.Symbolic) where T<:Union{AbstractFloat, Integer, Complex{var"#s144"} where var"#s144"<:AbstractFloat, Complex{var"#s143"} where var"#s143"<:Integer} at /Users/adrianaperezrotondo/.julia/packages/Symbolics/hgePJ/src/Symbolics.jl:137
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number} at char.jl:50
(::Type{T})(::Base.TwicePrecision) where T<:Number at twiceprecision.jl:243
...
Stacktrace:
[1] float(x::Type)
@ Base ./float.jl:206
[2] promote_to_concrete(vs::Vector{Term{Float64, Nothing}}; tofloat::Bool, use_union::Bool)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/utils.jl:480
[3] varmap_to_vars(varmap::Vector{Any}, varlist::Vector{Term{Real, Base.ImmutableDict{DataType, Any}}}; defaults::Dict{Any, Any}, check::Bool, toterm::Function, promotetoconcrete::Nothing, tofloat::Bool, use_union::Bool)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/variables.jl:64
[4] process_DEProblem(constructor::Type, sys::ODESystem, u0map::Vector{Any}, parammap::SciMLBase.NullParameters; 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, kwargs::Base.Iterators.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:has_difference,), Tuple{Bool}}})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/systems/diffeqs/abstractodesystem.jl:613
[5] (ODEProblem{true, tType, isinplace, P, F, K, PT} where {tType, isinplace, P, F, K, PT})(sys::ODESystem, u0map::Vector{Any}, tspan::Tuple{Float64, Float64}, parammap::SciMLBase.NullParameters; callback::Nothing, kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/systems/diffeqs/abstractodesystem.jl:704
[6] (ODEProblem{true, tType, isinplace, P, F, K, PT} where {tType, isinplace, P, F, K, PT})(sys::ODESystem, u0map::Vector{Any}, tspan::Tuple{Float64, Float64}, parammap::SciMLBase.NullParameters) (repeats 2 times)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/systems/diffeqs/abstractodesystem.jl:703
[7] ODEProblem(::ODESystem, ::Vector{Any}, ::Vararg{Any, N} where N; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/systems/diffeqs/abstractodesystem.jl:682
[8] ODEProblem(::ODESystem, ::Vector{Any}, ::Vararg{Any, N} where N)
@ ModelingToolkit ~/.julia/packages/ModelingToolkit/gG7nj/src/systems/diffeqs/abstractodesystem.jl:682
[9] top-level scope
@ ~Code/Julia/CerebellarMotorLearning/scripts/ex.jl:48
I am using Julia-1.6 and Modelingtoolkit is up to date ModelingToolkit v8.11.0.
Please I would appreciate any help!