Skip to content

Non-numeric parameters are broken inside @mtkmodel #3231

@cstjean

Description

@cstjean

Describe the bug 🐞

@parameters p3::MyCustomStructType works OK standalone, but fails with iteration error inside of @mtkmodel

Expected behavior

@parameters should work inside of @mtkmodel.

Minimal Reproducible Example 👇

The docs claim that the line @parameters p3::MyCustomStructType # non-numeric should work. It seems to work stand-alone.

julia> struct MyCustomStructType end

julia> @parameters p3::MyCustomStructType
1-element Vector{SymbolicUtils.BasicSymbolic{MyCustomStructType}}:
 p3

but fails inside of @mtkmodel

julia> @mtkmodel MyModel begin
           @parameters begin
               p3::MyCustomStructType
           end
       end
ModelingToolkit.Model{typeof(__MyModel__), Dict{Symbol, Any}}(__MyModel__, Dict{Symbol, Any}(:kwargs => Dict{Symbol, Dict}(:p3 => Dict{Symbol, Union{Nothing, DataType}}(:value => nothing, :type => MyCustomStructType)), :independent_variable => t, :parameters => Dict{Symbol, Dict{Symbol, Any}}(:p3 => Dict(:type => MyCustomStructType))), false)

julia> @named sys = MyModel(p3=MyCustomStructType())
ERROR: MethodError: no method matching iterate(::SymbolicUtils.BasicSymbolic{MyCustomStructType})

Closest candidates are:
  iterate(::LaTeXStrings.LaTeXString, ::Int64)
   @ LaTeXStrings C:\Users\\.julia\packages\LaTeXStrings\6NrIG\src\LaTeXStrings.jl:108
  iterate(::LaTeXStrings.LaTeXString)
   @ LaTeXStrings C:\Users\\.julia\packages\LaTeXStrings\6NrIG\src\LaTeXStrings.jl:109
  iterate(::DataStructures.TrieIterator)
   @ DataStructures C:\Users\\.julia\packages\DataStructures\95DJa\src\trie.jl:112
  ...

Stacktrace:
 [1] __MyModel__(; name::Symbol, p3::MyCustomStructType)
   @ Main C:\Users\\.julia\packages\ModelingToolkit\2hOLJ\src\systems\model_parsing.jl:914
 [2] (::ModelingToolkit.Model{typeof(__MyModel__), Dict{Symbol, Any}})(; kw::@Kwargs{name::Symbol, p3::MyCustomStructType})
   @ ModelingToolkit C:\Users\\.julia\packages\ModelingToolkit\2hOLJ\src\systems\model_parsing.jl:25
 [3] top-level scope
   @ REPL[29]:1

Environment (please complete the following information):

Julia 1.10.5
MTK 9.52.0

Might be related to the work necessary for #3182

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions