Skip to content

Commit

Permalink
Merge branch 'SciML:master' into testdocs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanfischer97 authored Oct 26, 2024
2 parents 885fb05 + 6de14a0 commit fec5386
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
14 changes: 7 additions & 7 deletions docs/pages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pages = Any[
"introduction_to_catalyst/introduction_to_catalyst.md",
"introduction_to_catalyst/math_models_intro.md"
],
"Model Creation and Properties" => Any[
"Model creation and properties" => Any[
"model_creation/dsl_basics.md",
"model_creation/dsl_advanced.md",
"model_creation/programmatic_CRN_construction.md",
Expand All @@ -18,21 +18,21 @@ pages = Any[
"model_creation/reactionsystem_content_accessing.md",
"model_creation/network_analysis.md",
"model_creation/chemistry_related_functionality.md",
"Model creation examples" => Any[
"Examples" => Any[
"model_creation/examples/basic_CRN_library.md",
"model_creation/examples/programmatic_generative_linear_pathway.md",
"model_creation/examples/hodgkin_huxley_equation.md",
"model_creation/examples/smoluchowski_coagulation_equation.md"
]
],
"Model simulation" => Any[
"Model simulation and visualization" => Any[
"model_simulation/simulation_introduction.md",
"model_simulation/simulation_plotting.md",
"model_simulation/simulation_structure_interfacing.md",
"model_simulation/ensemble_simulations.md",
"model_simulation/ode_simulation_performance.md",
"model_simulation/sde_simulation_performance.md",
"Model simulation examples" => Any[
"Examples" => Any[
"model_simulation/examples/periodic_events_simulation.md",
"model_simulation/examples/interactive_brusselator_simulation.md"
]
Expand All @@ -44,17 +44,17 @@ pages = Any[
"steady_state_functionality/bifurcation_diagrams.md",
"steady_state_functionality/dynamical_systems.md"
],
"Inverse Problems" => Any[
"Inverse problems" => Any[
"inverse_problems/optimization_ode_param_fitting.md",
# "inverse_problems/petab_ode_param_fitting.md",
"inverse_problems/behaviour_optimisation.md",
# "inverse_problems/structural_identifiability.md",
"inverse_problems/global_sensitivity_analysis.md",
"Inverse problem examples" => Any[
"Examples" => Any[
"inverse_problems/examples/ode_fitting_oscillation.md"
]
],
"Spatial Modelling" => Any[
"Spatial modelling" => Any[
"spatial_modelling/lattice_reaction_systems.md",
"spatial_modelling/lattice_simulation_structure_ interaction.md",
"spatial_modelling/lattice_simulation_plotting.md",
Expand Down
3 changes: 2 additions & 1 deletion src/Catalyst.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ using ModelingToolkit: Symbolic, value, get_unknowns, get_ps, get_iv, get_system
import ModelingToolkit: get_variables, namespace_expr, namespace_equation, get_variables!,
modified_unknowns!, validate, namespace_variables,
namespace_parameters, rename, renamespace, getname, flatten,
is_alg_equation, is_diff_equation
is_alg_equation, is_diff_equation, collect_vars!,
eqtype_supports_collect_vars

# internal but needed ModelingToolkit functions
import ModelingToolkit: check_variables,
Expand Down
24 changes: 24 additions & 0 deletions src/reaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,30 @@ end
MT.is_diff_equation(rx::Reaction) = false
MT.is_alg_equation(rx::Reaction) = false

# MTK functions for extracting variables within equation type object
MT.eqtype_supports_collect_vars(rx::Reaction) = true
function MT.collect_vars!(unknowns, parameters, rx::Reaction, iv; depth = 0,
op = MT.Differential)
MT.collect_vars!(unknowns, parameters, rx.rate, iv; depth, op)
for sub in rx.substrates
MT.collect_vars!(unknowns, parameters, sub, iv; depth, op)
end
for prod in rx.products
MT.collect_vars!(unknowns, parameters, prod, iv; depth, op)
end
for substoich in rx.substoich
MT.collect_vars!(unknowns, parameters, substoich, iv; depth, op)
end
for prodstoich in rx.prodstoich
MT.collect_vars!(unknowns, parameters, prodstoich, iv; depth, op)
end
if hasnoisescaling(rx)
ns = getnoisescaling(rx)
MT.collect_vars!(unknowns, parameters, ns, iv; depth, op)
end
return nothing
end

"""
get_symbolics(set, rx::Reaction)
Expand Down
18 changes: 17 additions & 1 deletion test/reactionsystem_core/reaction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Fetch packages.
using Catalyst, Test
using Catalyst: get_symbolics
using ModelingToolkit: value, get_variables!
using ModelingToolkit: value, get_variables!, collect_vars!, eqtype_supports_collect_vars

# Sets the default `t` to use.
t = default_t()
Expand Down Expand Up @@ -235,4 +235,20 @@ let
@test Catalyst.hasmisc(r2)
@test_throws Exception Catalyst.getmisc(r1)
@test isequal(Catalyst.getmisc(r2), ('M', :M))
end

# tests for collect_vars!
let
t = default_t()
@variables E(t) F(t)
@species A(t) B(t) C(t) D(t)
@parameters k1, k2, η

rx = Reaction(k1*E, [A, B], [C], [k2*D, 3], [F], metadata = [:noise_scaling => η])
us = Set()
ps = Set()
@test eqtype_supports_collect_vars(rx) == true
collect_vars!(us, ps, rx, t)
@test us == Set((A, B, C, D, E, F))
@test ps == Set((k1, k2, η))
end

0 comments on commit fec5386

Please sign in to comment.