Catalyst.jl
Catalyst.jl copied to clipboard
How to get the name of a species?
Consider:
julia> using Catalyst
julia> t = default_t()
t
julia> @species a(t)
1-element Vector{Num}:
a(t)
julia> nameof(a)
ERROR: None Sym BasicSymbolic doesn't have a name
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:35
[2] nameof(s::SymbolicUtils.BasicSymbolic{Real})
@ SymbolicUtils ~/.julia/packages/SymbolicUtils/N76BL/src/types.jl:545
[3] nameof(n::Num)
@ Symbolics ~/.julia/packages/Symbolics/lJiB2/src/num.jl:108
[4] top-level scope
@ REPL[4]:1
Now if i am willing to do evil i can do:
julia> a.val.f.name
:a
Which is what i wanted
nameof returns the name of a model (e.g. a ReactionSystem), you have to use ModelingToolkit.getname:
using Catalyst
t = default_t()
@species a(t)
ModelingToolkit.getname(a)
gives
:a
Thanks! I will open a docs PR
Why is it overloaded for model but not for BasicSymbolic? Are these two distinct meanings/use cases for a name?
I'm not sure to be honest, you will have to ask over at MTK. Generally, unless something is fairly central to Catalyst, to avoid additional confusion, we try to avoid changing the MTK API and just follow what they do.