Skip to content

Conversation

@ven-k
Copy link
Member

@ven-k ven-k commented Dec 7, 2023

  • So far, only the 1st positional-arg was canonicalized. This PR canonicalizes all positional args in @named
  • Add relevant tests.

Checklist

  • Appropriate tests were added
  • Any code changes were done in a way that does not break public API
  • All documentation related to code changes were updated
  • The new code follows the
    contributor guidelines, in particular the SciML Style Guide and
    COLPRAC.
  • Any new documentation only uses public API

Additional context

@ven-k
Copy link
Member Author

ven-k commented Dec 7, 2023

Earlier:

julia> @mtkmodel LevelThree begin
           @variables begin
               x(t)
               y(t)
               z(t)
           end
       end
ModelingToolkit.Model{typeof(__LevelThree__), Dict{Symbol, Any}}(__LevelThree__, Dict{Symbol, Any}(:variables => Dict{Symbol, Dict{Symbol, Any}}(:y => Dict(), :z => Dict(), :x => Dict()), :kwargs => Dict{Symbol, Any}(:y => nothing, :z => nothing, :x => nothing), :independent_variable => t), false)

julia>

julia> @parameters begin
           l
           m
           n
       end
3-element Vector{Num}:
 l
 m
 n

julia> @macroexpand1 @named three = LevelThree(x = l, y = m, z = n)
:(three = begin
          #= C:\Users\user\.julia\packages\ModelingToolkit\66mEN\src\systems\abstractsystem.jl:1002 =#
          var"#####__is_system_construction####774" = LevelThree isa DataType && LevelThree <: ModelingToolkit.AbstractSystem
          #= C:\Users\user\.julia\packages\ModelingToolkit\66mEN\src\systems\abstractsystem.jl:1003 =#
          LevelThree(y = m, z = n; name = :three, x = if var"#####__is_system_construction####774"
                      l
                  else
                      (ModelingToolkit.default_to_parentscope)(l)
                  end)
      end)

Now:

@mtkmodel LevelThree begin
    @variables begin
        x(t)
        y(t)
        z(t)
    end
end

@parameters begin
    l
    m
    n
end
@macroexpand1 @named three = LevelThree(x = l, y = m, z = n)
:(three = begin
          #= C:\Users\user\.julia\dev\ModelingToolkit.jl\src\systems\abstractsystem.jl:1002 =#    
          var"#####__is_system_construction####297" = LevelThree isa DataType && LevelThree <: ModelingToolkit.AbstractSystem
          #= C:\Users\user\.julia\dev\ModelingToolkit.jl\src\systems\abstractsystem.jl:1003 =#    
          LevelThree(; name = :three, x = if var"#####__is_system_construction####297"
                      l
                  else
                      (ModelingToolkit.default_to_parentscope)(l)
                  end, y = if var"#####__is_system_construction####297"
                      m
                  else
                      (ModelingToolkit.default_to_parentscope)(m)
                  end, z = if var"#####__is_system_construction####297"
                      n
                  else
                      (ModelingToolkit.default_to_parentscope)(n)
                  end)
      end)

- So far, only the 1st positional-arg was canonicalized.
- Add relevant tests.
@ven-k ven-k force-pushed the vkb/parameter-canon-in-at-named branch from a71a820 to 65440fe Compare December 7, 2023 14:47
@ChrisRackauckas ChrisRackauckas merged commit 8efd0a4 into SciML:master Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Failure to propagate default parameter value to inner system

2 participants