Hi All,
I want to be able to pass optimization parameters to the model.
I took the RC circuit from the docs and created 2 parameters (param_r1 param_c1)
https://mtk.sciml.ai/stable/tutorials/acausal_components/#Connecting-and-Simulating-Our-Electrical-Circuit
My code:
using ModelingToolkit, DifferentialEquations
using ModelingToolkitStandardLibrary.Electrical
@variables t
@parameters param_r1 param_c1
@named resistor = Resistor(R=param_r1)
@named capacitor = Capacitor(C=param_c1)
@named source = ConstantVoltage(V=1.)
@named ground = Ground()
rc_eqs = [
connect(source.p, resistor.p)
connect(resistor.n, capacitor.p)
connect(capacitor.n, source.n)
connect(capacitor.n, ground.g)
]
@named _rc_model = ODESystem(rc_eqs, t)
@named rc_model = compose(_rc_model,
[resistor, capacitor, source, ground])
sys = structural_simplify(rc_model)
u0 = [
capacitor.v => 0.0
]
params = [param_r1 => 1.0, param_c1 => 1.0]
tspan = (0., 10.)
prob = ODAEProblem(sys, u0, tspan, params)
The last line gives me the next error:
ERROR: MethodError: no method matching float(::Type{Any})
Closest candidates are:
float(::Type{Union{Missing, T}}) where T at C:\Users\mzhen\AppData\Local\Programs\Julia-1.7.2\share\julia\base\missing.jl:112
float(::Any) at C:\Users\mzhen\AppData\Local\Programs\Julia-1.7.2\share\julia\base\float.jl:269
float(::Union{StatsBase.PValue, StatsBase.TestStat}) at C:\Users\mzhen\.julia\packages\StatsBase\pJqvO\src\statmodels.jl:86
...
Stacktrace:
[1] float(#unused#::Type{Any})
@ Base .\missing.jl:113
[2] promote_to_concrete(vs::Vector{Any}; tofloat::Bool, use_union::Bool)
@ ModelingToolkit C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\utils.jl:558
[3] varmap_to_vars(varmap::Vector{Pair{Num, Float64}}, varlist::Vector{Sym{Real, Base.ImmutableDict{DataType, Any}}}; defaults::Dict{Any, Any}, check::Bool, toterm::Function, promotetoconcrete::Nothing, tofloat::Bool, use_union::Bool)
@ ModelingToolkit C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\variables.jl:68
[4] ODAEProblem{true}(sys::ODESystem, u0map::Vector{Pair{Num, Float64}}, tspan::Tuple{Float64, Float64}, parammap::Vector{Pair{Num, Float64}}; callback::Nothing, use_union::Bool, check::Bool, kwargs::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit.StructuralTransformations C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\structural_transformation\codegen.jl:523
[5] ODAEProblem{true}(sys::ODESystem, u0map::Vector{Pair{Num, Float64}}, tspan::Tuple{Float64, Float64}, parammap::Vector{Pair{Num, Float64}})
@ ModelingToolkit.StructuralTransformations C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\structural_transformation\codegen.jl:514
[6] ODAEProblem(::ODESystem, ::Vararg{Any}; kw::Base.Pairs{Symbol, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
@ ModelingToolkit.StructuralTransformations C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\structural_transformation\codegen.jl:492
[7] ODAEProblem(::ODESystem, ::Vararg{Any})
@ ModelingToolkit.StructuralTransformations C:\Users\mzhen\.julia\packages\ModelingToolkit\LXLjs\src\structural_transformation\codegen.jl:492
[8] top-level scope
@ d:\Projects\playground\julia\grid\src\grid _stl.jl:31
How to fix it?
Thanks!