From f952ed1009eff41c4a5d4bf4f14d18dcc5df8157 Mon Sep 17 00:00:00 2001 From: Alexander Demin Date: Sun, 10 Mar 2024 14:29:45 +0300 Subject: [PATCH] fix issues with unicode names --- src/ODE.jl | 3 ++- src/util.jl | 6 +++--- test/ode.jl | 29 +++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/ODE.jl b/src/ODE.jl index 36301d5a1..96af63167 100644 --- a/src/ODE.jl +++ b/src/ODE.jl @@ -264,7 +264,8 @@ end function Base.show(io::IO, ode::ODE) for x in ode.x_vars if endswith(var_to_str(x), "(t)") - print(io, var_to_str(x)[1:(end - 3)] * "'(t) = ") + print(io, chopsuffix(var_to_str(x), "(t)") * "'(t) = ") + # print(io, var_to_str(x)[1:(end - 3)] * "'(t) = ") else print(io, var_to_str(x) * "' = ") end diff --git a/src/util.jl b/src/util.jl index fbb3fbfae..b79df495d 100644 --- a/src/util.jl +++ b/src/util.jl @@ -490,9 +490,9 @@ If yes, returns a pair (a, number), otherwise nothing function decompose_derivative(varname::String, prefixes::Array{String}) for pr in prefixes if startswith(varname, pr) && length(varname) > length(pr) + 1 - if varname[length(pr) + 1] == '_' && - all(map(isdigit, collect(varname[(length(pr) + 2):end]))) - return (pr, parse(Int, varname[(length(pr) + 2):end])) + if varname[nextind(varname, ncodeunits(pr))] == '_' && + all(isdigit, varname[(nextind(varname, ncodeunits(pr)) + 1):end]) + return (pr, parse(Int, varname[(nextind(varname, ncodeunits(pr)) + 1):end])) end end end diff --git a/test/ode.jl b/test/ode.jl index f8035a7ee..1382d2737 100644 --- a/test/ode.jl +++ b/test/ode.jl @@ -16,3 +16,32 @@ y(t) = x1 ) end + +@testset "ODE unicode" begin + ode = StructuralIdentifiability.@ODEmodel( + 🐁'(t) = a * 🐁 - b * 🐁 * 🦉, + 🦉'(t) = c * 🦉 + d * 🐁 * 🦉, + y(t) = 🐁 + ) + println(ode) + res = StructuralIdentifiability.assess_identifiability(ode) + println(res) + @test res == Dict( + a => :globally, + b => :nonidentifiable, + c => :globally, + d => :globally, + 🐁 => :globally, + 🦉 => :nonidentifiable, + ) + + ode = StructuralIdentifiability.@ODEmodel( + ⬜'(t) = a⬜ * ⬜ * 🐁b🦉c, + 🐁b🦉c'(t) = 🐁b🦉c, + 🐁y🐁(t) = ⬜ + ) + println(ode) + StructuralIdentifiability.assess_identifiability(ode) + StructuralIdentifiability.find_identifiable_functions(ode) + StructuralIdentifiability.reparametrize_global(ode) +end