Skip to content

Commit 9c476c1

Browse files
committed
Makestate_name work for arbitrary expressions
1 parent a3c75f5 commit 9c476c1

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DynamicalSystemsBase"
22
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
33
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
4-
version = "3.8.2"
4+
version = "3.8.3"
55

66
[deps]
77
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"

src/core/dynamicalsystem_interface.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,9 @@ Return the state `u` of `ds` _observed_ at "index" `i`. Possibilities are:
189189
such as a `Num` or `Symbol` instance with the name of the symbolic variable.
190190
In this case, a last fourth optional positional argument `t` defaults to
191191
`current_time(ds)` and is the time to observe the state at.
192+
- Any symbolic expression involving variables present in the symbolic
193+
variables tracked by the system, e.g., `i = x^2 - y` with `x, y`
194+
symbolic variables.
192195
193196
For [`ProjectedDynamicalSystem`](@ref), this function assumes that the
194197
state of the system is the full state space state, not the projected one

src/core/pretty_printing.jl

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,18 @@ Return a name that matches the outcome of [`observe_state`](@ref) with `index`.
8080
state_name(f::Int) = "u"*subscript(f)
8181
state_name(f::Function) = string(f)
8282
state_name(f::Union{AbstractString,Symbol}) = string(f)
83-
state_name(f) = string(DynamicalSystemsBase.SymbolicIndexingInterface.getname(f))
83+
function state_name(f)
84+
# First, try a symbolic name
85+
try
86+
n = string(DynamicalSystemsBase.SymbolicIndexingInterface.getname(f))
87+
return n
88+
catch e
89+
end
90+
# if it failed, cast into string
91+
n = string(f)
92+
# and remove `(t)`
93+
replace(n, "(t)" => "")
94+
end
8495

8596
"""
8697
parameter_name(index)::String

0 commit comments

Comments
 (0)