Skip to content

@mtkmodel macro requires imports from MTK #3640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hexaeder opened this issue May 19, 2025 · 1 comment · May be fixed by #3643
Open

@mtkmodel macro requires imports from MTK #3640

hexaeder opened this issue May 19, 2025 · 1 comment · May be fixed by #3643
Labels
bug Something isn't working

Comments

@hexaeder
Copy link
Contributor

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)
@hexaeder hexaeder added the bug Something isn't working label May 19, 2025
@ChrisRackauckas
Copy link
Member

Yeah in the macro it should just ModelingToolkit. ...

But in general you cannot even assume that ModelingToolkit is defined in the calling module...

It can just be a requirement of the macro. Getting to using Modelingtoolkit: Modelingtoolkit, @mtkmodel is step 1 and let's get there first.

cstjean added a commit to cstjean/ModelingToolkit.jl that referenced this issue May 20, 2025
See SciML#3640

Feels like `const MTK = ModelingToolkit` should be at the top-level for
convenience.
cstjean added a commit to cstjean/ModelingToolkit.jl that referenced this issue May 20, 2025
@cstjean cstjean linked a pull request May 20, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants