Skip to content

Commit db75226

Browse files
committed
check all files round 1
1 parent 3e270fd commit db75226

19 files changed

+176
-184
lines changed

ext/CatalystBifurcationKitExtension/bifurcation_kit_extension.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ function BK.BifurcationProblem(rs::ReactionSystem, u0_bif, ps, bif_par, args...;
2626
nsys = complete(nsys)
2727

2828
# Makes BifurcationProblem (this call goes through the ModelingToolkit-based BifurcationKit extension).
29-
return BK.BifurcationProblem(
30-
nsys, u0_bif, ps, bif_par, args...; plot_var, record_from_solution, jac, kwargs...)
29+
return BK.BifurcationProblem(nsys, u0_bif, ps, bif_par, args...; plot_var,
30+
record_from_solution, jac, kwargs...)
3131
end

ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ function steady_state_polynomial(rs::ReactionSystem, ps, u0)
5252
ns = complete(convert(NonlinearSystem, rs; remove_conserved = true))
5353
pre_varmap = [symmap_to_varmap(rs, u0)..., symmap_to_varmap(rs, ps)...]
5454
Catalyst.conservationlaw_errorcheck(rs, pre_varmap)
55-
p_vals = ModelingToolkit.varmap_to_vars(
56-
pre_varmap, parameters(ns); defaults = ModelingToolkit.defaults(ns))
55+
p_vals = ModelingToolkit.varmap_to_vars(pre_varmap, parameters(ns);
56+
defaults = ModelingToolkit.defaults(ns))
5757
p_dict = Dict(parameters(ns) .=> p_vals)
5858
eqs_pars_funcs = vcat(equations(ns), conservedequations(rs))
5959
eqs = map(eq -> substitute(eq.rhs - eq.lhs, p_dict), eqs_pars_funcs)

ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ function Catalyst.make_si_ode(rs::ReactionSystem; measured_quantities = [], know
3131
# Creates a MTK ODESystem, and a list of measured quantities (there are equations).
3232
# Gives these to SI to create an SI ode model of its preferred form.
3333
osys, conseqs, _ = make_osys(rs; remove_conserved)
34-
measured_quantities = make_measured_quantities(
35-
rs, measured_quantities, known_p, conseqs; ignore_no_measured_warn)
34+
measured_quantities = make_measured_quantities( rs, measured_quantities, known_p, conseqs;
35+
ignore_no_measured_warn)
3636
return SI.mtk_to_si(osys, measured_quantities)[1]
3737
end
3838

@@ -63,19 +63,18 @@ Notes:
6363
- This function is part of the StructuralIdentifiability.jl extension. StructuralIdentifiability.jl must be imported to access it.
6464
- `measured_quantities` and `known_p` input may also be symbolic (e.g. measured_quantities = [rs.X])
6565
"""
66-
function SI.assess_local_identifiability(
67-
rs::ReactionSystem, args...; measured_quantities = [],
68-
known_p = [], funcs_to_check = Vector(), remove_conserved = true,
69-
ignore_no_measured_warn = false, kwargs...)
66+
function SI.assess_local_identifiability(rs::ReactionSystem, args...;
67+
measured_quantities = [], known_p = [], funcs_to_check = Vector(),
68+
remove_conserved = true, ignore_no_measured_warn = false, kwargs...)
7069
# Creates a ODESystem, list of measured quantities, and functions to check, of SI's preferred form.
7170
osys, conseqs, vars = make_osys(rs; remove_conserved)
72-
measured_quantities = make_measured_quantities(
73-
rs, measured_quantities, known_p, conseqs; ignore_no_measured_warn)
71+
measured_quantities = make_measured_quantities( rs, measured_quantities, known_p, conseqs;
72+
ignore_no_measured_warn)
7473
funcs_to_check = make_ftc(funcs_to_check, conseqs, vars)
7574

7675
# Computes identifiability and converts it to a easy to read form.
77-
out = SI.assess_local_identifiability(
78-
osys, args...; measured_quantities, funcs_to_check, kwargs...)
76+
out = SI.assess_local_identifiability( sys, args...; measured_quantities,
77+
funcs_to_check, kwargs...)
7978
return make_output(out, funcs_to_check, reverse.(conseqs))
8079
end
8180

@@ -104,19 +103,18 @@ Notes:
104103
- This function is part of the StructuralIdentifiability.jl extension. StructuralIdentifiability.jl must be imported to access it.
105104
- `measured_quantities` and `known_p` input may also be symbolic (e.g. measured_quantities = [rs.X])
106105
"""
107-
function SI.assess_identifiability(
108-
rs::ReactionSystem, args...; measured_quantities = [], known_p = [],
109-
funcs_to_check = Vector(), remove_conserved = true,
110-
ignore_no_measured_warn = false, kwargs...)
106+
function SI.assess_identifiability( rs::ReactionSystem, args...;
107+
measured_quantities = [], known_p = [], funcs_to_check = Vector(),
108+
remove_conserved = true, ignore_no_measured_warn = false, kwargs...)
111109
# Creates a ODESystem, list of measured quantities, and functions to check, of SI's preferred form.
112110
osys, conseqs, vars = make_osys(rs; remove_conserved)
113-
measured_quantities = make_measured_quantities(
114-
rs, measured_quantities, known_p, conseqs; ignore_no_measured_warn)
111+
measured_quantities = make_measured_quantities(rs, measured_quantities, known_p, conseqs;
112+
ignore_no_measured_warn)
115113
funcs_to_check = make_ftc(funcs_to_check, conseqs, vars)
116114

117115
# Computes identifiability and converts it to a easy to read form.
118-
out = SI.assess_identifiability(
119-
osys, args...; measured_quantities, funcs_to_check, kwargs...)
116+
out = SI.assess_identifiability(osys, args...; measured_quantities,
117+
funcs_to_check, kwargs...)
120118
return make_output(out, funcs_to_check, reverse.(conseqs))
121119
end
122120

@@ -145,10 +143,9 @@ Notes:
145143
- This function is part of the StructuralIdentifiability.jl extension. StructuralIdentifiability.jl must be imported to access it.
146144
- `measured_quantities` and `known_p` input may also be symbolic (e.g. measured_quantities = [rs.X])
147145
"""
148-
function SI.find_identifiable_functions(
149-
rs::ReactionSystem, args...; measured_quantities = [],
150-
known_p = [], remove_conserved = true, ignore_no_measured_warn = false,
151-
kwargs...)
146+
function SI.find_identifiable_functions(rs::ReactionSystem, args...;
147+
measured_quantities = [], known_p = [], remove_conserved = true,
148+
ignore_no_measured_warn = false, kwargs...)
152149
# Creates a ODESystem, and list of measured quantities, of SI's preferred form.
153150
osys, conseqs = make_osys(rs; remove_conserved)
154151
measured_quantities = make_measured_quantities(
@@ -166,8 +163,9 @@ end
166163
function make_osys(rs::ReactionSystem; remove_conserved = true)
167164
# Creates the ODESystem corresponding to the ReactionSystem (expanding functions and flattening it).
168165
# Creates a list of the systems all symbols (unknowns and parameters).
169-
ModelingToolkit.iscomplete(rs) ||
166+
if !ModelingToolkit.iscomplete(rs)
170167
error("Identifiability should only be computed for complete systems. A ReactionSystem can be marked as complete using the `complete` function.")
168+
end
171169
rs = complete(Catalyst.expand_registered_functions(flatten(rs)))
172170
osys = complete(convert(ODESystem, rs; remove_conserved))
173171
vars = [unknowns(rs); parameters(rs)]

src/chemistry_functionality.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ function make_compound(expr)
8585
# Loops through all components, add the component and the coefficients to the corresponding vectors
8686
# Cannot extract directly using e.g. "getfield.(composition, :reactant)" because then
8787
# we get something like :([:C, :O]), rather than :([C, O]).
88-
composition = Catalyst.recursive_find_reactants!(
89-
expr.args[3], 1, Vector{ReactantStruct}(undef, 0))
88+
composition = Catalyst.recursive_find_reactants!( xpr.args[3], 1,
89+
Vector{ReactantStruct}(undef, 0))
9090
components = :([]) # Becomes something like :([C, O]).
9191
coefficients = :([]) # Becomes something like :([1, 2]).
9292
for comp in composition
@@ -105,8 +105,8 @@ function make_compound(expr)
105105
isempty(ivs) && (species_expr = insert_independent_variable(species_expr, :(..)))
106106

107107
# Expression which when evaluated gives a vector with all the ivs of the components.
108-
ivs_get_expr = :(unique(reduce(
109-
vcat, [arguments(ModelingToolkit.unwrap(comp)) for comp in $components])))
108+
ivs_get_expr = :(unique(reduce(vcat, [arguments(ModelingToolkit.unwrap(comp))
109+
for comp in $components])))
110110

111111
# Creates the found expressions that will create the compound species.
112112
# The `Expr(:escape, :(...))` is required so that the expressions are evaluated in
@@ -122,12 +122,12 @@ function make_compound(expr)
122122
species_declaration_expr = Expr(:escape, :(@species $species_expr))
123123
multiple_ivs_error_check_expr = Expr(:escape,
124124
:($(isempty(ivs)) && (length($ivs_get_expr) > 1) &&
125-
error($COMPOUND_CREATION_ERROR_DEPENDENT_VAR_REQUIRED)))
125+
error($COMPOUND_CREATION_ERROR_DEPENDENT_VAR_REQUIRED)))
126126
iv_designation_expr = Expr(:escape,
127127
:($(isempty(ivs)) && ($species_name = $(species_name)($(ivs_get_expr)...))))
128128
iv_check_expr = Expr(:escape,
129129
:(issetequal(arguments(ModelingToolkit.unwrap($species_name)), $ivs_get_expr) ||
130-
error("The independent variable(S) provided to the compound ($(arguments(ModelingToolkit.unwrap($species_name)))), and those of its components ($($ivs_get_expr)))), are not identical.")))
130+
error("The independent variable(S) provided to the compound ($(arguments(ModelingToolkit.unwrap($species_name)))), and those of its components ($($ivs_get_expr)))), are not identical.")))
131131
compound_designation_expr = Expr(:escape,
132132
:($species_name = ModelingToolkit.setmetadata(
133133
$species_name, Catalyst.CompoundSpecies, true)))
@@ -197,7 +197,7 @@ function make_compounds(expr)
197197

198198
# The output needs to be converted to Vector{Num} (from Vector{SymbolicUtils.BasicSymbolic{Real}}) to be consistent with e.g. @variables.
199199
compound_declarations.args[end] = :([ModelingToolkit.wrap(cmp)
200-
for cmp in $(compound_declarations.args[end])])
200+
for cmp in $(compound_declarations.args[end])])
201201

202202
# Returns output that.
203203
return compound_declarations
@@ -264,8 +264,8 @@ function balance_reaction(reaction::Reaction)
264264
prodstoich = stoich[(length(reaction.substrates) + 1):end]
265265

266266
# Create a new reaction with the balanced stoichiometries
267-
balancedrx = Reaction(reaction.rate, reaction.substrates,
268-
reaction.products, substoich, prodstoich)
267+
balancedrx = Reaction(reaction.rate, reaction.substrates, reaction.products,
268+
substoich, prodstoich)
269269

270270
# Add the reaction to the vector of all reactions
271271
balancedrxs[i] = balancedrx

src/dsl.jl

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,7 @@ macro species(ex...)
8787
resize!(vars.args, idx + length(lastarg.args) + 1)
8888
for sym in lastarg.args
8989
vars.args[idx] = :($sym = ModelingToolkit.wrap(setmetadata(
90-
ModelingToolkit.value($sym),
91-
Catalyst.VariableSpecies,
92-
true)))
90+
ModelingToolkit.value($sym), Catalyst.VariableSpecies, true)))
9391
idx += 1
9492
end
9593

@@ -419,11 +417,11 @@ function get_reactions(exprs::Vector{Expr}, reactions = Vector{ReactionStruct}(u
419417
push_reactions!(reactions, reaction.args[3], reaction.args[2],
420418
rate.args[2], metadata.args[2], arrow)
421419
elseif in(arrow, fwd_arrows)
422-
push_reactions!(
423-
reactions, reaction.args[2], reaction.args[3], rate, metadata, arrow)
420+
push_reactions!( reactions, reaction.args[2], reaction.args[3],
421+
rate, metadata, arrow)
424422
elseif in(arrow, bwd_arrows)
425-
push_reactions!(
426-
reactions, reaction.args[3], reaction.args[2], rate, metadata, arrow)
423+
push_reactions!(reactions, reaction.args[3], reaction.args[2],
424+
rate, metadata, arrow)
427425
else
428426
throw("Malformed reaction, invalid arrow type used in: $(MacroTools.striplines(line))")
429427
end
@@ -437,8 +435,9 @@ function read_reaction_line(line::Expr)
437435
# Special routine required for the`-->` case, which creates different expression from all other cases.
438436
rate = line.args[1]
439437
reaction = line.args[2]
440-
(reaction.head == :-->) &&
441-
(reaction = Expr(:call, :, reaction.args[1], reaction.args[2]))
438+
if reaction.head == :-->
439+
reaction = Expr(:call, :, reaction.args[1], reaction.args[2])
440+
end
442441
arrow = reaction.args[1]
443442

444443
# Handles metadata. If not provided, empty metadata is created.
@@ -455,9 +454,8 @@ end
455454

456455
# Takes a reaction line and creates reaction(s) from it and pushes those to the reaction array.
457456
# Used to create multiple reactions from, for instance, `k, (X,Y) --> 0`.
458-
function push_reactions!(
459-
reactions::Vector{ReactionStruct}, sub_line::ExprValues, prod_line::ExprValues,
460-
rate::ExprValues, metadata::ExprValues, arrow::Symbol)
457+
function push_reactions!(reactions::Vector{ReactionStruct}, sub_line::ExprValues,
458+
prod_line::ExprValues, rate::ExprValues, metadata::ExprValues, arrow::Symbol)
461459
# The rates, substrates, products, and metadata may be in a tupple form (e.g. `k, (X,Y) --> 0`).
462460
# This finds the length of these tuples (or 1 if not in tuple forms). Errors if lengs inconsistent.
463461
lengs = (tup_leng(sub_line), tup_leng(prod_line), tup_leng(rate), tup_leng(metadata))
@@ -478,9 +476,8 @@ function push_reactions!(
478476
error("Some reaction metadata fields where repeated: $(metadata_entries)")
479477
end
480478

481-
push!(reactions,
482-
ReactionStruct(get_tup_arg(sub_line, i), get_tup_arg(prod_line, i),
483-
get_tup_arg(rate, i), metadata_i))
479+
push!(reactions, ReactionStruct(get_tup_arg(sub_line, i),
480+
get_tup_arg(prod_line, i), get_tup_arg(rate, i), metadata_i))
484481
end
485482
end
486483

@@ -630,8 +627,9 @@ end
630627
# Read the events (continious or discrete) provided as options to the DSL. Returns an expression which evalutes to these.
631628
function read_events_option(options, event_type::Symbol)
632629
# Prepares the events, if required to, converts them to block form.
633-
(event_type in [:continuous_events, :discrete_events]) ||
630+
if event_type [:continuous_events, :discrete_events]
634631
error("Trying to read an unsupported event type.")
632+
end
635633
events_input = haskey(options, event_type) ? options[event_type].args[3] :
636634
MacroTools.striplines(:(begin end))
637635
events_input = option_block_form(events_input)
@@ -642,11 +640,11 @@ function read_events_option(options, event_type::Symbol)
642640
# Formatting error checks.
643641
# NOTE: Maybe we should move these deeper into the system (rather than the DSL), throwing errors more generally?
644642
if (arg isa Expr) && (arg.head != :call) || (arg.args[1] != :(=>)) ||
645-
length(arg.args) != 3
643+
(length(arg.args) != 3)
646644
error("Events should be on form `condition => affect`, separated by a `=>`. This appears not to be the case for: $(arg).")
647645
end
648646
if (arg isa Expr) && (arg.args[2] isa Expr) && (arg.args[2].head != :vect) &&
649-
(event_type == :continuous_events)
647+
(event_type == :continuous_events)
650648
error("The condition part of continious events (the left-hand side) must be a vector. This is not the case for: $(arg).")
651649
end
652650
if (arg isa Expr) && (arg.args[3] isa Expr) && (arg.args[3].head != :vect)
@@ -670,8 +668,8 @@ function read_equations_options(options, variables_declared)
670668
eqs_input = haskey(options, :equations) ? options[:equations].args[3] : :(begin end)
671669
eqs_input = option_block_form(eqs_input)
672670
equations = Expr[]
673-
ModelingToolkit.parse_equations!(
674-
Expr(:block), equations, Dict{Symbol, Any}(), eqs_input)
671+
ModelingToolkit.parse_equations!(Expr(:block), equations,
672+
Dict{Symbol, Any}(), eqs_input)
675673

676674
# Loops through all equations, checks for lhs of the form `D(X) ~ ...`.
677675
# When this is the case, the variable X and differential D are extracted (for automatic declaration).
@@ -689,7 +687,7 @@ function read_equations_options(options, variables_declared)
689687
lhs = eq.args[2]
690688
# if lhs: is an expression. Is a function call. The function's name is D. Calls a single symbol.
691689
if (lhs isa Expr) && (lhs.head == :call) && (lhs.args[1] == :D) &&
692-
(lhs.args[2] isa Symbol)
690+
(lhs.args[2] isa Symbol)
693691
diff_var = lhs.args[2]
694692
if in(diff_var, forbidden_symbols_error)
695693
error("A forbidden symbol ($(diff_var)) was used as an variable in this differential equation: $eq")
@@ -749,15 +747,15 @@ function read_observed_options(options, species_n_vars_declared, ivs_sorted)
749747
error("An observable ($obs_name) was given independent variable(s). These should not be given, as they are inferred automatically.")
750748
isnothing(defaults) ||
751749
error("An observable ($obs_name) was given a default value. This is forbidden.")
752-
in(obs_name, forbidden_symbols_error) &&
750+
(obs_name in forbidden_symbols_error) &&
753751
error("A forbidden symbol ($(obs_eq.args[2])) was used as an observable name.")
754752

755753
# Error checks.
756754
if (obs_name in species_n_vars_declared) && is_escaped_expr(obs_eq.args[2])
757755
error("An interpoalted observable have been used, which has also been explicitly delcared within the system using eitehr @species or @variables. This is not permited.")
758756
end
759757
if ((obs_name in species_n_vars_declared) || is_escaped_expr(obs_eq.args[2])) &&
760-
!isnothing(metadata)
758+
!isnothing(metadata)
761759
error("Metadata was provided to observable $obs_name in the `@observables` macro. However, the obervable was also declared separately (using either @species or @variables). When this is done, metadata should instead be provided within the original @species or @variable declaration.")
762760
end
763761

@@ -773,10 +771,10 @@ function read_observed_options(options, species_n_vars_declared, ivs_sorted)
773771
# Adds a line to the `observed_vars` expression, setting the ivs for this observable.
774772
# Cannot extract directly using e.g. "getfield.(dependants_structs, :reactant)" because
775773
# then we get something like :([:X1, :X2]), rather than :([X1, X2]).
776-
dep_var_expr = :(filter(
777-
!MT.isparameter, Symbolics.get_variables($(obs_eq.args[3]))))
778-
ivs_get_expr = :(unique(reduce(
779-
vcat, [arguments(MT.unwrap(dep)) for dep in $dep_var_expr])))
774+
dep_var_expr = :(filter(!MT.isparameter,
775+
Symbolics.get_variables($(obs_eq.args[3]))))
776+
ivs_get_expr = :(unique(reduce(vcat, [arguments(MT.unwrap(dep))
777+
for dep in $dep_var_expr])))
780778
ivs_get_expr_sorted = :(sort($(ivs_get_expr);
781779
by = iv -> findfirst(MT.getname(iv) == ivs for ivs in $ivs_sorted)))
782780
push!(observed_vars.args,

src/expression_utils.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,15 @@ function find_varinfo_in_declaration(expr)
8282
# Case: X(t) = 1.0
8383
(expr.args[1].head == :call) &&
8484
(return expr.args[1].args[1], expr.args[1].args[2:end], expr.args[2].args[1],
85-
nothing)
85+
nothing)
8686
end
8787
if expr.head == :tuple
8888
# Case: X, [metadata=true]
8989
(expr.args[1] isa Symbol) && (return expr.args[1], [], nothing, expr.args[2])
9090
# Case: X(t), [metadata=true]
9191
(expr.args[1].head == :call) &&
9292
(return expr.args[1].args[1], expr.args[1].args[2:end], nothing, expr.args[2])
93-
if (expr.args[1].head == :(=))
93+
if expr.args[1].head == :(=)
9494
# Case: X = 1.0, [metadata=true]
9595
(expr.args[1].args[1] isa Symbol) &&
9696
(return expr.args[1].args[1], [], expr.args[1].args[2], expr.args[2])

src/reaction.jl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,6 @@ encountered in:
367367
- Among potential noise scaling metadata.
368368
"""
369369
function ModelingToolkit.get_variables!(set, rx::Reaction)
370-
if isdefined(Main, :Infiltrator)
371-
Main.infiltrate(@__MODULE__, Base.@locals, @__FILE__, @__LINE__)
372-
end
373370
get_variables!(set, rx.rate)
374371
foreach(sub -> push!(set, sub), rx.substrates)
375372
foreach(prod -> push!(set, prod), rx.products)

0 commit comments

Comments
 (0)