How does one pass structural parameters from a @mtkmodel to a @component function? Is it possible to sort of convert between the positional syntax of @component function to the keyword syntax of @mtkmodel (for structural parameters)? As an example, how would one do the following?
@component function Subsystem(B; d, name)
vars = @variables begin
(y(t))[1:B]
end
eqs = [
D(y) ~ d*y
]
ODESystem(eqs, t, vars, eqs; name)
end
@mtkmodel Example2 begin
@structural_parameters begin
A = 1
B = 2
end
@parameters begin
c
d
end
@components begin
subsystem = Subsystem(B; d=d)
end
end
A = 10
B = 20
c = 4.67
d = 2.34
@mtkbuild correct_method = Example2(A=A, B=B, c=c, d=d)
MethodError: no method matching Subsystem(; B::Int64, name::Symbol, d::Num)
The function Subsystem
exists, but no method is defined for this combination of argument types.
Closest candidates are:
Subsystem(::Any; d, name) got unsupported keyword argument “B”
@ Main C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2461
Stacktrace:
[1] macro expansion
@ C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2295 [inlined]
[2] Example2(; name::Symbol, A::Int64, B::Int64, c::Float64, d::Float64, subsystem__d::Nothing, subsystem__B::Nothing)
@ Main C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\model_parsing.jl:1203
[3] (::ModelingToolkit.Model{typeof(Example2), Dict{Symbol, Any}})(; kw::@Kwargs{name::Symbol, A::Int64, B::Int64, c::Float64, d::Float64})
@ ModelingToolkit C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\model_parsing.jl:25
[4] top-level scope
@ C:\Users\matth.julia\packages\ModelingToolkit\Ljerk\src\systems\abstractsystem.jl:2295