Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an optional getname_as_string function #21

Open
isaacsas opened this issue Dec 30, 2023 · 6 comments
Open

Adding an optional getname_as_string function #21

isaacsas opened this issue Dec 30, 2023 · 6 comments

Comments

@isaacsas
Copy link
Member

isaacsas commented Dec 30, 2023

One issue with MTK symbol names is the need to use the unicode lower plus in hierarchical systems since a period can't be used, i.e. "act₊vol₁₊x".

Having a getname_as_string function would allow plot recipes, Latexify, and other formatters to have a systematic way to get a nicer representation of the variable/parameter name for display in output (i.e. SciMLBase could then use getname_as_string for plot recipes, and one could get a nicer act.vol₁.x type representation).

@isaacsas
Copy link
Member Author

Maybe get_display_name would be better?

@AayushSabharwal
Copy link
Member

So this could be an optional method to implement for symbolic types, which defaults to calling getname on the symbol, converting it to a String and then replacing all by .?

@isaacsas
Copy link
Member Author

isaacsas commented Jan 2, 2024

Exactly!

@isaacsas
Copy link
Member Author

isaacsas commented Jan 2, 2024

So for symbolics it would make that substitution and generate the string, but for normal Symbols it could just call string(sym::Symbol) as it does now.

Maybe the signature is get_display_name(sys, sym) then MTK can just define its own dispatches to do the conversion for MTK systems, while SymbolCaches fallback to normal symbol to string conversion.

@AayushSabharwal
Copy link
Member

Why is sys necessary here?

I was thinking something along the lines of

get_display_name(sym::Symbol) = string(sym)

# In Symbolics/SymbolicUtils.jl
get_display_name(sym::Num) = hasname(sym) ? replace(string(getname(sym)), "" => ".") : string(Symbol(sym))

@isaacsas
Copy link
Member Author

isaacsas commented Jan 3, 2024

Adding sys allows anyone who implements the SII interface to add a dispatch and control printing of components of their systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants