Skip to content

check for Symbolics.VariableSource => :Parameter in isparameter #3636

@oameye

Description

@oameye

I have the problem that my symbols are detected as variables instead of parameters. This is due they not have the MTKVariableTypeCtx metadata information. I could set by:

SymbolicUtils.setmetadata(s,MTK.MTKVariableTypeCtx,MTK.PARAMETER)

However, I would like my package to be independent of the ModelingToolkit dependency. I was wondering if in the isparameter function in

function isparameter(x)
x = unwrap(x)
if x isa Symbolic && (varT = getvariabletype(x, nothing)) !== nothing
return varT === PARAMETER
#TODO: Delete this branch
elseif x isa Symbolic && Symbolics.getparent(x, false) !== false
p = Symbolics.getparent(x)
isparameter(p) ||
(hasmetadata(p, Symbolics.VariableSource) &&
getmetadata(p, Symbolics.VariableSource)[1] == :parameters)
elseif iscall(x) && operation(x) isa Symbolic
varT === PARAMETER || isparameter(operation(x))
elseif iscall(x) && operation(x) == (getindex)
isparameter(arguments(x)[1])
elseif x isa Symbolic
varT === PARAMETER
else
false
end
end

we could add an extra case which checks the Symbolics.VariableSource metadata outside of the symbolic having a parent. That way symbolic parameters that were not made with MTK.@parameters can still be used in ModelingToolkit.

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