Metadata
Symbolics.jl provides a metadata system for attaching additional information to symbolic variables. This system allows for extensible annotations that can be used to store default values, source information, and custom user-defined metadata.
Using Metadata
Metadata can be attached to variables when they are created with the @variables macro. Common metadata includes default values and other annotations:
using Symbolics
# Variable with default value
@variables x=1.0 y=2.0
# Variables with custom metadata (once registered)
@variables z [description="Temperature in Kelvin"]Extending Metadata
You can define custom metadata types for use with the @variables macro by defining a new metadata type and registering it:
using Symbolics
# Define a custom metadata type
struct MyCustomMetadata <: Symbolics.AbstractVariableMetadata end
# Register it for use in @variables
Symbolics.option_to_metadata_type(::Val{:my_custom}) = MyCustomMetadata
# Now you can use it
@variables x [my_custom = "some value"]Metadata API
Symbolics.VariableDefaultValue — Typestruct VariableDefaultValue <: Symbolics.AbstractVariableMetadataSymbolic metadata key for storing the default value of a symbolic variable.
Symbolics.VariableSource — Typestruct VariableSource <: Symbolics.AbstractVariableMetadataSymbolic metadata key for storing the macro used to create a symbolic variable.
Missing docstring for Symbolics.CallWithMetadata. Check Documenter's build log for details.
Missing docstring for Symbolics.Unknown. Check Documenter's build log for details.
Symbolics.option_to_metadata_type — Functionoption_to_metadata_type(_::Val{opt})
Define a new metadata key assignable in @variables. This function should take Val{name} where name is a Symbol, and return the key type for the given metadata name name. For example,
Symbolics.option_to_metadata_type(::Val{:custom_name}) = CustomTypeAllows the following syntax:
@variables x [custom_name = 1]And stores 1 as the value associated with the CustomType key in the symbolic metadata of x.