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.38k stars 196 forks source link

Cannot use structural parameter as array size #2704

Open baggepinnen opened 2 months ago

baggepinnen commented 2 months ago
@mtkmodel Foo begin
    @structural_parameters begin
        nx = 2
    end
    @variables begin
        (x(t)[1:nx]), [description = "State"]
    end
    @equations begin
    end
end
ERROR: promotion of types Int64 and Symbol failed to change any arguments

With explicit array size, it works

julia> @mtkmodel Foo begin
           @structural_parameters begin
               nx = 2
           end
           @variables begin
               (x(t)[1:2]), [description = "State"]
           end
           @equations begin
           end
       end
ModelingToolkit.Model{typeof(__Foo__), Dict{Symbol, Any}}(__Foo__, Dict{Symbol, Any}(:variables => Dict{Symbol, Dict{Symbol, Any}}(:x => Dict(:type => Real, :description => "State", :size => (2,))), :kwargs => Dict{Symbol, Dict}(:nx => Dict(:value => 2), :x => Dict{Symbol, Union{Nothing, UnionAll}}(:value => nothing, :type => AbstractArray{Real})), :structural_parameters => Dict{Symbol, Dict}(:nx => Dict(:value => 2)), :independent_variable => t, :equations => Any[]), false)
jaakkor2 commented 2 months ago

Duplicate of https://github.com/SciML/ModelingToolkit.jl/issues/2453?

dfabianus commented 3 weeks ago

Is there a workaround to allow variable sized arrays?

ChrisRackauckas commented 3 weeks ago

For what? That seems very orthogonal to this issue.