Skip to content

Commit

Permalink
renaming preprocess_ode to mtk_to_si
Browse files Browse the repository at this point in the history
  • Loading branch information
pogudingleb committed Nov 14, 2023
1 parent 2f0c871 commit 8d97f5f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 14 deletions.
45 changes: 36 additions & 9 deletions src/ODE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ end

#------------------------------------------------------------------------------
"""
function preprocess_ode(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{ModelingToolkit.Equation})
function preprocess_ode(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{SymbolicUtils.BasicSymbolic})
function mtk_to_si(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{ModelingToolkit.Equation})
function mtk_to_si(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{SymbolicUtils.BasicSymbolic})
Input:
- `de` - ModelingToolkit.AbstractTimeDependentSystem, a system for identifiability query
Expand All @@ -532,36 +532,63 @@ Output:
- `conversion` dictionary from the symbols in the input MTK model to the variable
involved in the produced `ODE` object
"""
function preprocess_ode(
function mtk_to_si(
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{ModelingToolkit.Equation},
)
return __preprocess_ode(
return __mtk_to_si(
de,
[(replace(string(e.lhs), "(t)" => ""), e.rhs) for e in measured_quantities],
)
end

function preprocess_ode(
function mtk_to_si(
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{<:Symbolics.Num},
)
return __preprocess_ode(
return __mtk_to_si(
de,
[("y$i", Symbolics.value(e)) for (i, e) in enumerate(measured_quantities)],
)
end

function mtk_to_si(
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{<:SymbolicUtils.BasicSymbolic},
)
return __mtk_to_si(de, [("y$i", e) for (i, e) in enumerate(measured_quantities)])
end

#------------------------------------------------------------------------------
# old name kept for compatibility purposes

function preprocess_ode(

Check warning on line 565 in src/ODE.jl

View check run for this annotation

Codecov / codecov/patch

src/ODE.jl#L565

Added line #L565 was not covered by tests
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{ModelingToolkit.Equation},
)
@warn "Function `preprocess_ode` has been renamed to `mtk_to_si`. The old name can be still used but will disappear in the future releases."
return mtk_to_si(de, measured_quantities)

Check warning on line 570 in src/ODE.jl

View check run for this annotation

Codecov / codecov/patch

src/ODE.jl#L569-L570

Added lines #L569 - L570 were not covered by tests
end

function preprocess_ode(

Check warning on line 573 in src/ODE.jl

View check run for this annotation

Codecov / codecov/patch

src/ODE.jl#L573

Added line #L573 was not covered by tests
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{<:Symbolics.Num},
)
@warn "Function `preprocess_ode` has been renamed to `mtk_to_si`. The old name can be still used but will disappear in the future releases."
return mtk_to_si(de, measured_quantities)

Check warning on line 578 in src/ODE.jl

View check run for this annotation

Codecov / codecov/patch

src/ODE.jl#L577-L578

Added lines #L577 - L578 were not covered by tests
end

function preprocess_ode(
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{<:SymbolicUtils.BasicSymbolic},
)
return __preprocess_ode(de, [("y$i", e) for (i, e) in enumerate(measured_quantities)])
@warn "Function `preprocess_ode` has been renamed to `mtk_to_si`. The old name can be still used but will disappear in the future releases."
return mtk_to_si(de, measured_quantities)

Check warning on line 586 in src/ODE.jl

View check run for this annotation

Codecov / codecov/patch

src/ODE.jl#L585-L586

Added lines #L585 - L586 were not covered by tests
end

#------------------------------------------------------------------------------
"""
function __preprocess_ode(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{Tuple{String, SymbolicUtils.BasicSymbolic}})
function __mtk_to_si(de::ModelingToolkit.AbstractTimeDependentSystem, measured_quantities::Array{Tuple{String, SymbolicUtils.BasicSymbolic}})
Input:
- `de` - ModelingToolkit.AbstractTimeDependentSystem, a system for identifiability query
Expand All @@ -572,7 +599,7 @@ Output:
- `conversion` dictionary from the symbols in the input MTK model to the variable
involved in the produced `ODE` object
"""
function __preprocess_ode(
function __mtk_to_si(
de::ModelingToolkit.AbstractTimeDependentSystem,
measured_quantities::Array{<:Tuple{String, <:SymbolicUtils.BasicSymbolic}},
)
Expand Down
4 changes: 2 additions & 2 deletions src/StructuralIdentifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ ParamPunPam.enable_progressbar(false)
using ModelingToolkit

# defining a model
export ODE, @ODEmodel, preprocess_ode
export ODE, @ODEmodel, mtk_to_si

# assessing identifiability
export assess_local_identifiability, assess_identifiability
Expand Down Expand Up @@ -207,7 +207,7 @@ function _assess_identifiability(
measured_quantities = get_measured_quantities(ode)
end

ode, conversion = preprocess_ode(ode, measured_quantities)
ode, conversion = mtk_to_si(ode, measured_quantities)
conversion_back = Dict(v => k for (k, v) in conversion)
if isempty(funcs_to_check)
funcs_to_check = [conversion_back[x] for x in [ode.parameters..., ode.x_vars...]]
Expand Down
2 changes: 1 addition & 1 deletion src/discrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ function assess_local_identifiability(
end
end

dds_aux, conversion = preprocess_ode(dds, measured_quantities)
dds_aux, conversion = mtk_to_si(dds, measured_quantities)
if length(funcs_to_check) == 0
funcs_to_check = vcat(
parameters(dds),
Expand Down
2 changes: 1 addition & 1 deletion src/identifiable_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ function _find_identifiable_functions(
if isempty(measured_quantities)
measured_quantities = get_measured_quantities(ode)
end
ode, conversion = preprocess_ode(ode, measured_quantities)
ode, conversion = mtk_to_si(ode, measured_quantities)
result = _find_identifiable_functions(
ode,
simplify = simplify,
Expand Down
2 changes: 1 addition & 1 deletion src/local_identifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ end
[e for e in ModelingToolkit.states(ode) if !ModelingToolkit.isoutput(e)],
)
end
ode, conversion = preprocess_ode(ode, measured_quantities)
ode, conversion = mtk_to_si(ode, measured_quantities)
funcs_to_check_ = [eval_at_nemo(x, conversion) for x in funcs_to_check]

if isequal(type, :SE)
Expand Down

0 comments on commit 8d97f5f

Please sign in to comment.