Catalyst.jl icon indicating copy to clipboard operation
Catalyst.jl copied to clipboard

How to get the name of a species?

Open oxinabox opened this issue 3 months ago • 3 comments

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

oxinabox avatar Sep 30 '25 11:09 oxinabox

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

TorkelE avatar Sep 30 '25 12:09 TorkelE

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?

oxinabox avatar Oct 01 '25 01:10 oxinabox

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.

TorkelE avatar Oct 01 '25 05:10 TorkelE