Skip to content
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

@extend does not work with parameters #3061

Open
baggepinnen opened this issue Sep 19, 2024 · 4 comments
Open

@extend does not work with parameters #3061

baggepinnen opened this issue Sep 19, 2024 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@baggepinnen
Copy link
Contributor

When using @mtkmodel and @extend, the constructor does not know about the parameters of the extended system. MWE:

@mtkmodel Inner begin
    @parameters begin
        color[1:4] = [1.0, 0.0, 0.0, 1.0], [description = "Color of the body in animations"]
        render = true, [description = "Render the joint in animations"]
    end
end

@mtkmodel Outer begin
    @extend () = v = Inner()
    @parameters begin
        radius = 0.1, [description = "Radius of the sphere in animations"]
    end
end

@named test = Outer(color=[1,1,1,1])
julia> @named test = Outer(color=[1,1,1,1])
ERROR: MethodError: no method matching __Outer__(; name::Symbol, color::Vector{Int64})

Closest candidates are:
  __Outer__(; name, radius) got unsupported keyword argument "color"
   @ Main ~/.julia/packages/ModelingToolkit/UXr3S/src/systems/model_parsing.jl:138
@baggepinnen baggepinnen added the bug Something isn't working label Sep 19, 2024
@ven-k
Copy link
Member

ven-k commented Sep 20, 2024

One must list all the args (parameter or variable), of a sub-component or a base-system, that should be added to the arglist of the main-component.

This will fix the issue:

@mtkmodel Outer begin
     @extend () = v = Inner(; color, render)
     @parameters begin
         radius = 0.1, [description = "Radius of the sphere in animations"]
     end
 end

@baggepinnen
Copy link
Contributor Author

The component that is extended may have 10s-100s of parameters and variables, if we have to type them all out it kind-of defeats the purpose of extending something in the first place?

@ven-k
Copy link
Member

ven-k commented Sep 20, 2024

It was mainly to keep the syntax same in both cases. If it is more convenient, I can modify the case for extend to automatically add all args.

@baggepinnen
Copy link
Contributor Author

I can modify the case for extend to automatically add all args.

That sounds good to me, and aligns with what I would expect from inheritance

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

No branches or pull requests

2 participants