Skip to content

Cannot pass empty array of initial conditions #4206

@hersle

Description

@hersle

For consistency, would it be possible to make M4 work like M3?

using ModelingToolkit
@independent_variables t
D = Differential(t)
@variables x(t)
@named M1 = System([D(x) ~ 0], t; initial_conditions = Dict(x => 0)) # works
@named M2 = System([D(x) ~ 0], t; initial_conditions = [x => 0]) # works
@named M3 = System([D(x) ~ 0], t; initial_conditions = Dict()) # works
@named M4 = System([D(x) ~ 0], t; initial_conditions = []) # fails
ERROR: MethodError: no method matching defsdict(::Vector{Any})
The function `defsdict` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  defsdict(::ModelingToolkitBase.AtomicArrayDict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, Dict{SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}, SymbolicUtils.BasicSymbolicImpl.var"typeof(BasicSymbolicImpl)"{SymReal}}})
   @ ModelingToolkitBase ~/.julia/packages/ModelingToolkitBase/lC2g8/src/systems/system.jl:379
  defsdict(::Union{AbstractDict, AbstractArray{<:Pair}})
   @ ModelingToolkitBase ~/.julia/packages/ModelingToolkitBase/lC2g8/src/systems/system.jl:380

I am programmatically generating initial_conditions. Sometimes it ends up as an empty array, and it would be nice to not have to treat that with a special case in my code. Similarly for bindings and other similar fields.

I know I can probably always use a Dict and be fine, but maybe it would be nice to support arrays in the same way?

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