Skip to content

get_variables drops metadata for callables #1396

@SebastianM-C

Description

@SebastianM-C

It looks like there are some cases in which get_variables drops variable metadata, leading to the variables that are return to not be isequal to the original ones. This seems to be the case for callables, which are currently generated by the @mtkmodel macro as pointed out in #1364 (comment).

MWE

using Symbolics

@variables t x(..)
x = x(t)

Symbolics.get_variables(x + 1)
# 2-element Vector{SymbolicUtils.BasicSymbolic}:
# x
# t

isequal(Symbolics.get_variables(x + 1)[1], Symbolics.value(x)) # false

Symbolics.metadata(Symbolics.value(x))
# Base.ImmutableDict{DataType, Any} with 2 entries:
#   CallWithParent => x⋆
#   VariableSource => (:variables, :x)

Symbolics.metadata(Symbolics.get_variables(x + 1)[1]) # nothing

While SciML/ModelingToolkit.jl#3217 could help avoid the issue for @mtkmodel based systems, I would expect the metadata to still be there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions