Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pogudingleb committed Nov 10, 2023
1 parent 0a4e694 commit c2be531
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 55 deletions.
16 changes: 12 additions & 4 deletions src/ODE.jl
Original file line number Diff line number Diff line change
Expand Up @@ -461,10 +461,18 @@ macro ODEmodel(ex::Expr...)

logging_exprs = [
:(StructuralIdentifiability.info_si("Summary of the model:")),
:(StructuralIdentifiability.info_si("State variables: " * $(join(map(string, collect(x_vars)), ", ")))),
:(StructuralIdentifiability.info_si("Parameters: " * $(join(map(string, collect(params)), ", ")))),
:(StructuralIdentifiability.info_si("Inputs: " * $(join(map(string, collect(u_vars)), ", ")))),
:(StructuralIdentifiability.info_si("Outputs: " * $(join(map(string, collect(y_vars)), ", ")))),
:(StructuralIdentifiability.info_si(
"State variables: " * $(join(map(string, collect(x_vars)), ", ")),
)),
:(StructuralIdentifiability.info_si(
"Parameters: " * $(join(map(string, collect(params)), ", ")),
)),
:(StructuralIdentifiability.info_si(
"Inputs: " * $(join(map(string, collect(u_vars)), ", ")),
)),
:(StructuralIdentifiability.info_si(
"Outputs: " * $(join(map(string, collect(y_vars)), ", ")),
)),
]
# creating the ode object
ode_expr = :(StructuralIdentifiability.ODE{StructuralIdentifiability.Nemo.fmpq_mpoly}(
Expand Down
4 changes: 3 additions & 1 deletion src/RationalFunctionFields/IdealMQS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ mutable struct IdealMQS{T} <: AbstractBlackboxIdeal
lcm,
1:length(funcs_den_nums),
)
debug_si("Rational functions common denominator is of degree $(total_degree(den_lcm)) and of length $(length(den_lcm))")
debug_si(
"Rational functions common denominator is of degree $(total_degree(den_lcm)) and of length $(length(den_lcm))",
)
is_constant(den_lcm) &&
(debug_si("Common denominator of the field generators is constant"))
existing_varnames = map(String, symbols(ring))
Expand Down
28 changes: 20 additions & 8 deletions src/RationalFunctionFields/RationalFunctionField.jl
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ function beautifuly_generators(
end
end
end
debug_si("Out of $(length(fracs)) simplified generators there are $(length(non_redundant)) non redundant")
debug_si(
"Out of $(length(fracs)) simplified generators there are $(length(non_redundant)) non redundant",
)
fracs = fracs[non_redundant]
end
sort!(fracs, lt = rational_function_cmp)
Expand Down Expand Up @@ -356,7 +358,9 @@ function groebner_basis_coeffs(
debug_si("Inclusion checked in $(runtime) seconds. Result: $two_sided_inclusion")
current_degrees = current_degrees .* 2
end
debug_si("The coefficients of the Groebner basis are presented by $(length(fracs)) rational functions")
debug_si(
"The coefficients of the Groebner basis are presented by $(length(fracs)) rational functions",
)
new_rff.mqs.cached_groebner_bases[ordering, up_to_degree] = gb
rff.mqs.cached_groebner_bases[ordering, up_to_degree] = gb
return new_rff
Expand All @@ -382,7 +386,9 @@ function generating_sets_fan(
time_start = time_ns()
vars = gens(parent(rff.mqs))
nbases = length(vars)
info_si("Computing $nbases Groebner bases for degrees $up_to_degree for block orderings")
info_si(
"Computing $nbases Groebner bases for degrees $up_to_degree for block orderings",
)
ordering_to_generators = Dict()
if code == 0
return ordering_to_generators
Expand Down Expand Up @@ -552,9 +558,11 @@ function simplified_generating_set(
append!(new_fracs, generators)
end
new_fracs_unique = unique(new_fracs)
debug_si("""
Final cleaning and simplification of generators.
Out of $(length(new_fracs)) fractions $(length(new_fracs_unique)) are syntactically unique.""")
debug_si(
"""
Final cleaning and simplification of generators.
Out of $(length(new_fracs)) fractions $(length(new_fracs_unique)) are syntactically unique.""",
)
runtime =
@elapsed new_fracs = beautifuly_generators(RationalFunctionField(new_fracs_unique))
debug_si("Checking inclusion with probability $p")
Expand All @@ -564,8 +572,12 @@ function simplified_generating_set(
warn_si("Field membership check failed. Error will follow.")
throw("The new subfield generators are not correct.")
end
info_si("Inclusion checked with probability $p in $(_runtime_logger[:id_inclusion_check]) seconds")
debug_si("Out of $(length(rff.mqs.nums_qq)) initial generators there are $(length(new_fracs)) indepdendent")
info_si(
"Inclusion checked with probability $p in $(_runtime_logger[:id_inclusion_check]) seconds",
)
debug_si(
"Out of $(length(rff.mqs.nums_qq)) initial generators there are $(length(new_fracs)) indepdendent",
)
ranking = generating_set_rank(new_fracs)
_runtime_logger[:id_ranking] = ranking
debug_si("The ranking of the new set of generators is $ranking")
Expand Down
16 changes: 11 additions & 5 deletions src/RationalFunctionFields/normalforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -365,9 +365,11 @@ function linear_relations_between_normal_forms(
push!(zeroed_relations_inds, i)
end
end
debug_si("""
Relations in the previous intersection: $(length(complete_intersection_relations_ff))
Vanished at the current point: $(length(zeroed_relations_inds))""")
debug_si(
"""
Relations in the previous intersection: $(length(complete_intersection_relations_ff))
Vanished at the current point: $(length(zeroed_relations_inds))""",
)
non_zeroed_relations_inds =
setdiff(collect(1:n_relations_ff), zeroed_relations_inds)
zeroed_relations_from_complete_intersection =
Expand All @@ -383,7 +385,9 @@ function linear_relations_between_normal_forms(
non_zeroed_relations_from_complete_intersection,
zeroed_relations_from_complete_intersection,
)
debug_si("There are $(length(complete_intersection_relations_ff)) relations in the intersection")
debug_si(
"There are $(length(complete_intersection_relations_ff)) relations in the intersection",
)
m_relations_ff = length(complete_intersection_relations_ff)
if n_relations_ff == m_relations_ff || isempty(complete_intersection_relations_ff)
break
Expand Down Expand Up @@ -412,6 +416,8 @@ function linear_relations_between_normal_forms(
)
relations_qq[i] = relation_qq_param // one(relation_qq_param)
end
info_si("Used $iters specializations in $((time_ns() - time_start) / 1e9) seconds, found $(length(complete_intersection_relations_ff)) relations")
info_si(
"Used $iters specializations in $((time_ns() - time_start) / 1e9) seconds, found $(length(complete_intersection_relations_ff)) relations",
)
relations_qq
end
7 changes: 6 additions & 1 deletion src/StructuralIdentifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ function assess_identifiability(
end
funcs_to_check_ = [eval_at_nemo(each, conversion) for each in funcs_to_check]

result = assess_identifiability(ode, funcs_to_check = funcs_to_check_, p = p, loglevel = loglevel)
result = assess_identifiability(
ode,
funcs_to_check = funcs_to_check_,
p = p,
loglevel = loglevel,
)
nemo2mtk = Dict(funcs_to_check_ .=> funcs_to_check)
out_dict = Dict(nemo2mtk[param] => result[param] for param in funcs_to_check_)
return out_dict
Expand Down
8 changes: 6 additions & 2 deletions src/discrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,9 @@ function assess_local_identifiability(
)
if length(measured_quantities) == 0
if any(ModelingToolkit.isoutput(eq.lhs) for eq in ModelingToolkit.equations(dds))
info_si("Measured quantities are not provided, trying to find the outputs in input dynamical system.")
info_si(
"Measured quantities are not provided, trying to find the outputs in input dynamical system.",
)
measured_quantities = filter(
eq -> (ModelingToolkit.isoutput(eq.lhs)),
ModelingToolkit.equations(dds),
Expand Down Expand Up @@ -342,7 +344,9 @@ function assess_local_identifiability(
nemo2mtk = Dict(funcs_to_check_ .=> funcs_to_check)
out_dict = Dict(nemo2mtk[param] => result[param] for param in funcs_to_check_)
if length(known_ic) > 0
warn_si("Since known initial conditions were provided, identifiability of states (e.g., `x(t)`) is at t = 0 only !")
warn_si(
"Since known initial conditions were provided, identifiability of states (e.g., `x(t)`) is at t = 0 only !",
)
end
return out_dict
end
Expand Down
12 changes: 9 additions & 3 deletions src/global_identifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ function initial_identifiable_functions(
_runtime_logger[:rank_time] = rank_times

if any([dim != rk + 1 for (dim, rk) in zip(dims, wranks)])
warn_si("One of the Wronskians has corank greater than one, so the results of the algorithm will be valid only for multiexperiment identifiability. If you still would like to assess single-experiment identifiability, we recommend using SIAN (https://github.com/alexeyovchinnikov/SIAN-Julia) or transforming all the parameters to states with zero derivative")
warn_si(
"One of the Wronskians has corank greater than one, so the results of the algorithm will be valid only for multiexperiment identifiability. If you still would like to assess single-experiment identifiability, we recommend using SIAN (https://github.com/alexeyovchinnikov/SIAN-Julia) or transforming all the parameters to states with zero derivative",
)
end
end

Expand All @@ -142,7 +144,9 @@ function initial_identifiable_functions(
)

if with_states && !isempty(ode.parameters)
debug_si("Generators of identifiable functions involve states, the parameter-only part is getting simplified")
debug_si(
"Generators of identifiable functions involve states, the parameter-only part is getting simplified",
)
# NOTE: switching to a ring without states for a moment
param_ring, _ = PolynomialRing(
base_ring(bring),
Expand Down Expand Up @@ -305,7 +309,9 @@ function assess_global_identifiability(
) where {P <: MPolyElem{fmpq}}
submodels = find_submodels(ode)
if length(submodels) > 0
info_si("Note: the input model has nontrivial submodels. If the computation for the full model will be too heavy, you may want to try to first analyze one of the submodels. They can be produced using function `find_submodels`")
info_si(
"Note: the input model has nontrivial submodels. If the computation for the full model will be too heavy, you may want to try to first analyze one of the submodels. They can be produced using function `find_submodels`",
)
end

result = check_identifiability(
Expand Down
6 changes: 4 additions & 2 deletions src/identifiable_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function find_identifiable_functions(
rational_interpolator = :VanDerHoevenLecerf,
loglevel = Logging.Info,
) where {T <: MPolyElem{fmpq}}
restart_logging(loglevel=loglevel)
restart_logging(loglevel = loglevel)
Random.seed!(seed)
@assert simplify in (:standard, :weak, :strong, :absent)
runtime_start = time_ns()
Expand Down Expand Up @@ -91,7 +91,9 @@ function find_identifiable_functions(
id_funcs_fracs = [parent_ring_change(f, parent(ode)) for f in id_funcs_fracs]
_runtime_logger[:id_total] = (time_ns() - runtime_start) / 1e9
_runtime_logger[:are_id_funcs_polynomial] = all(isone denominator, id_funcs_fracs)
info_si("The search for identifiable functions concluded in $(_runtime_logger[:id_total]) seconds")
info_si(
"The search for identifiable functions concluded in $(_runtime_logger[:id_total]) seconds",
)
return id_funcs_fracs
end

Expand Down
14 changes: 10 additions & 4 deletions src/io_equation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ function find_ioprojections(
A, B = simplify_frac(A, B)
if isempty(filter!(v -> (v in keys(x_equations)), vars(A))) && (B != 0) # && (length(coeffs(A))==1)
# variable change x_i' --> x_i' - (B/A)', x_i --> x_i - B/A
debug_si("\t Applying variable change: $(x) --> $(x) - ( $B )/( $A )")
debug_si(
"\t Applying variable change: $(x) --> $(x) - ( $B )/( $A )",
)
dB = diff_poly(B, derivation)
dA = diff_poly(A, derivation)
numer_d, denom_d = simplify_frac(A * dB - dA * B, A * A)
Expand Down Expand Up @@ -339,7 +341,7 @@ Output:
function find_ioequations(
ode::ODE{P};
var_change_policy = :default,
loglevel = Logging.Info
loglevel = Logging.Info,
) where {P <: MPolyElem{<:FieldElem}}
# Setting the var_change policy
if (var_change_policy == :yes) ||
Expand All @@ -358,13 +360,17 @@ function find_ioequations(

debug_si("Check whether the original projections are enough")
if length(io_projections) == 1 || check_primality(io_projections)
debug_si("The projections generate an ideal with a single components of highest dimension, returning")
debug_si(
"The projections generate an ideal with a single components of highest dimension, returning",
)
return io_projections
end

sampling_range = 5
while true
debug_si("There are several components of the highest dimension, trying to isolate one")
debug_si(
"There are several components of the highest dimension, trying to isolate one",
)
extra_projection = sum(rand(1:sampling_range) * v for v in keys(io_projections))
debug_si("Extra projections: $extra_projection")
new_projections, _, projection_equation =
Expand Down
12 changes: 8 additions & 4 deletions src/local_identifiability.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ function assess_local_identifiability(
restart_logging(loglevel = loglevel)
if length(measured_quantities) == 0
if any(ModelingToolkit.isoutput(eq.lhs) for eq in ModelingToolkit.equations(ode))
info_si("Measured quantities are not provided, trying to find the outputs in input ODE.")
info_si(
"Measured quantities are not provided, trying to find the outputs in input ODE.",
)
measured_quantities = filter(
eq -> (ModelingToolkit.isoutput(eq.lhs)),
ModelingToolkit.equations(ode),
Expand Down Expand Up @@ -202,7 +204,7 @@ function assess_local_identifiability(
funcs_to_check = funcs_to_check_,
p = p,
type = type,
loglevel = loglevel
loglevel = loglevel,
)
nemo2mtk = Dict(funcs_to_check_ .=> funcs_to_check)
out_dict = Dict(nemo2mtk[param] => result[param] for param in funcs_to_check_)
Expand Down Expand Up @@ -238,7 +240,7 @@ function assess_local_identifiability(
p::Float64 = 0.99,
type = :SE,
trbasis = nothing,
loglevel = Logging.Info
loglevel = Logging.Info,
) where {P <: MPolyElem{Nemo.fmpq}}
restart_logging(loglevel = loglevel)
if isempty(funcs_to_check)
Expand All @@ -254,7 +256,9 @@ function assess_local_identifiability(
num, den = unpack_fraction(f)
for v in vcat(vars(num), vars(den))
if !(v in ode.parameters)
error_si("Multi-experiment identifiability is not properly defined for the states")
error_si(
"Multi-experiment identifiability is not properly defined for the states",
)
throw(ArgumentError("State variable $v appears in $f"))
end
end
Expand Down
12 changes: 4 additions & 8 deletions src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# not the exhaustive list, just the ones to be initialized
const _runtime_rubrics = (
:id_calls_to_gb,
:id_groebner_time,
:id_calls_to_gb,
:id_groebner_time,
:id_inclusion_check_mod_p,
:id_npoints_degree,
:id_npoints_interpolation,
Expand All @@ -25,12 +25,8 @@ const _runtime_logger = Dict(
:id_beautifulization => 0,
)

const _si_logger = Ref{Logging.ConsoleLogger}(
Logging.ConsoleLogger(
Logging.Info,
show_limited = false,
)
)
const _si_logger =
Ref{Logging.ConsoleLogger}(Logging.ConsoleLogger(Logging.Info, show_limited = false))

function restart_logging(; loglevel = Logging.Info)
_si_logger[] = Logging.ConsoleLogger(loglevel, show_limited = false)
Expand Down
31 changes: 20 additions & 11 deletions src/parametrizations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,14 @@ function check_constructive_field_membership(
gen_tag_names(length(fracs_gen), "Tag")
end
sat_string = gen_tag_name("Sat")
debug_si("""
Tags:
$(join(map(x -> string(x[1]) * " -> " * string(x[2]), zip(fracs_gen, tag_strings)), "\t\n"))
Saturation tag:
$sat_string
""")
debug_si(
"""
Tags:
$(join(map(x -> string(x[1]) * " -> " * string(x[2]), zip(fracs_gen, tag_strings)), "\t\n"))
Saturation tag:
$sat_string
""",
)
poly_ring_tag, vars_tag = PolynomialRing(K, vcat(sat_string, orig_strings, tag_strings))
sat_var = vars_tag[1]
orig_vars = vars_tag[2:(nvars(poly_ring) + 1)]
Expand Down Expand Up @@ -225,10 +227,12 @@ function check_constructive_field_membership(
ring_of_tags, tags = PolynomialRing(K, tag_strings)
tag_to_gen = Dict(tags[i] => fracs_gen[i] for i in 1:length(fracs_gen))
if !isempty(intersect(tag_strings, orig_strings))
warn_si("""
There is an intersection between the names of the tag variables and the original variables.
Tags: $tag_strings
Original vars: $orig_strings""")
warn_si(
"""
There is an intersection between the names of the tag variables and the original variables.
Tags: $tag_strings
Original vars: $orig_strings""",
)
end
parametric_ring, _ =
PolynomialRing(FractionField(ring_of_tags), orig_strings, ordering = :degrevlex)
Expand Down Expand Up @@ -464,7 +468,12 @@ Dict{Nemo.QQMPolyRingElem, AbstractAlgebra.Generic.Frac{Nemo.QQMPolyRingElem}} w
Notice that the `new_ode` is fully identifiabile, and has `1` less parameter
compared to the original one.
"""
function reparametrize_global(ode::ODE{P}; p = 0.99, seed = 42, loglevel = Logging.Info) where {P}
function reparametrize_global(
ode::ODE{P};
p = 0.99,
seed = 42,
loglevel = Logging.Info,
) where {P}
restart_logging(loglevel = loglevel)
Random.seed!(seed)
id_funcs =
Expand Down
6 changes: 5 additions & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
)
assess_identifiability(ode, loglevel = Logging.Warn)
assess_identifiability(de; measured_quantities = [x0], loglevel = Logging.Warn)
assess_identifiability(de; measured_quantities = [y ~ x0], loglevel = Logging.Warn)
assess_identifiability(
de;
measured_quantities = [y ~ x0],
loglevel = Logging.Warn,
)
find_identifiable_functions(ode, with_states = true, loglevel = Logging.Warn)
restart_logging(loglevel = Logging.Info)
end
Expand Down
Loading

0 comments on commit c2be531

Please sign in to comment.