Skip to content

@mtkmodel macro requires imports from MTK #3640

Open
@hexaeder

Description

@hexaeder

Describe the bug 🐞
The @mtkmodel macro expands to code which relies on certain names beeing presend in the calling context, for example Num and Equation. As of #3526 also System (see this line)

This is breaking in contexts which use only implicit imports, for example I hadn't imported System before. I guess everything should be called via ModelingToolkit.$sym? But in general you cannot even assume that ModelingToolkit is defined in the calling module...

Expected behavior

Only depend on using Modelingtoolkit: @mtkmodel to use @mtkmodel macro.

Minimal Reproducible Example 👇

using ModelingToolkit: ModelingToolkit, @mtkmodel, @variables, @parameters, t_nounits as t # those kinda make sense
using ModelingToolkit: Equation, Num, System # <- this is needed
@mtkmodel MyModel begin
    @variables begin
        x(t)
        y(t)
    end
    @parameters begin
        a
    end
    @equations begin
        y ~ a * x
    end
end
MyModel(; name=:foo)

Metadata

Metadata

Assignees

No one assigned

    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