SciML / ModelingToolkit.jl

An acausal modeling framework for automatically parallelized scientific machine learning (SciML) in Julia. A computer algebra system for integrated symbolics for physics-informed machine learning and automated transformations of differential equations
https://mtk.sciml.ai/dev/
Other
1.41k stars 203 forks source link

`@mtkmodel`: Positional arguments passed as keyword arguments #3018

Open baggepinnen opened 1 week ago

baggepinnen commented 1 week ago

The following instantiation of a component

        @components begin
            filter = DiscreteTransferFunction(G; z)
        end

calls DiscreteTransferFunction(; G, z), i.e., G is passed as a keyword argument despite the fact that it was indicated to be a positional argument. Not being able to use positional arguments is very limiting, it means that there can only be a single method for any component constructor, and component constructors that use positional arguments cannot be called in a model defined by @mtkmodel.

@macroexpand indicates that the keyword-arg separator ; is put in the right place, but the name of the positional arg is mistakenly included:

DiscreteTransferFunction(G = _filter__G; name = :filter,
baggepinnen commented 1 week ago

The offending code is

        MLStyle.@match arg begin
            x::Symbol || Expr(:kw, x) => begin

which matches and does the same thing for arg being either Symbol or a :kw expression. These have to be two separate cases