From 5275a1d6e9eb400fa325cdacfc99ede307e3245a Mon Sep 17 00:00:00 2001 From: Torkel Date: Wed, 29 May 2024 19:38:20 -0400 Subject: [PATCH 01/12] use iscall --- Project.toml | 1 + ext/CatalystHomotopyContinuationExtension.jl | 3 ++- .../homotopy_continuation_extension.jl | 4 ++-- src/Catalyst.jl | 3 ++- src/latexify_recipes.jl | 2 +- src/reaction.jl | 2 +- src/reactionsystem.jl | 4 ++-- src/reactionsystem_conversions.jl | 4 ++-- src/registered_functions.jl | 2 +- test/dsl/dsl_basic_model_construction.jl | 5 +++-- 10 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Project.toml b/Project.toml index 2b90ff7b2a..4b5f8651d4 100644 --- a/Project.toml +++ b/Project.toml @@ -23,6 +23,7 @@ Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" +TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" [weakdeps] diff --git a/ext/CatalystHomotopyContinuationExtension.jl b/ext/CatalystHomotopyContinuationExtension.jl index 6e7fdac50f..6c6185112f 100644 --- a/ext/CatalystHomotopyContinuationExtension.jl +++ b/ext/CatalystHomotopyContinuationExtension.jl @@ -6,7 +6,8 @@ import DynamicPolynomials import ModelingToolkit as MT import HomotopyContinuation as HC import Setfield: @set -import Symbolics: unwrap, wrap, Rewriters, symtype, issym, istree +import Symbolics: unwrap, wrap, Rewriters, symtype, issym +using TermInterface: iscall # Creates and exports hc_steady_states function. include("CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl") diff --git a/ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl b/ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl index 1dcc64d9ba..848e158987 100644 --- a/ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl +++ b/ext/CatalystHomotopyContinuationExtension/homotopy_continuation_extension.jl @@ -63,7 +63,7 @@ end # Parses and expression and return a version where any exponents that are Float64 (but an int, like 2.0) are turned into Int64s. make_int_exps(expr) = wrap(Rewriters.Postwalk(Rewriters.PassThrough(___make_int_exps))(unwrap(expr))).val function ___make_int_exps(expr) - !istree(expr) && return expr + !iscall(expr) && return expr if (operation(expr) == ^) if isinteger(arguments(expr)[2]) return arguments(expr)[1] ^ Int64(arguments(expr)[2]) @@ -76,7 +76,7 @@ end # If the input is a fraction, removes the denominator. function remove_denominators(expr) s_expr = simplify_fractions(expr) - !istree(expr) && return expr + !iscall(expr) && return expr if operation(s_expr) == / return remove_denominators(arguments(s_expr)[1]) end diff --git a/src/Catalyst.jl b/src/Catalyst.jl index d80c115119..b9a89f5f2f 100644 --- a/src/Catalyst.jl +++ b/src/Catalyst.jl @@ -24,7 +24,8 @@ RuntimeGeneratedFunctions.init(@__MODULE__) import Symbolics: BasicSymbolic import SymbolicUtils -using ModelingToolkit: Symbolic, value, istree, get_unknowns, get_ps, get_iv, get_systems, +using TermInterface: iscall +using ModelingToolkit: Symbolic, value, get_unknowns, get_ps, get_iv, get_systems, get_eqs, get_defaults, toparam, get_var_to_name, get_observed, getvar diff --git a/src/latexify_recipes.jl b/src/latexify_recipes.jl index a7d5cf1e7c..9528bd6bed 100644 --- a/src/latexify_recipes.jl +++ b/src/latexify_recipes.jl @@ -194,7 +194,7 @@ function make_stoich_str(spec, stoich, subber; mathrm = true, kwargs...) if isequal(stoich, one(stoich)) prestr * latexraw(subber(spec); kwargs...) * poststr else - if (stoich isa Symbolic) && istree(stoich) + if (stoich isa Symbolic) && iscall(stoich) LaTeXString("(") * latexraw(subber(stoich); kwargs...) * LaTeXString(")") * diff --git a/src/reaction.jl b/src/reaction.jl index 95eb7c0e71..a68a2dc2af 100644 --- a/src/reaction.jl +++ b/src/reaction.jl @@ -255,7 +255,7 @@ function print_rxside(io::IO, specs, stoich) spec : MT.operation(spec) if isequal(stoich[i], one(stoich[i])) print(io, prspec) - elseif istree(stoich[i]) + elseif iscall(stoich[i]) print(io, "(", stoich[i], ")*", prspec) else print(io, stoich[i], "*", prspec) diff --git a/src/reactionsystem.jl b/src/reactionsystem.jl index 5c04b2e642..d691cf35eb 100644 --- a/src/reactionsystem.jl +++ b/src/reactionsystem.jl @@ -1443,7 +1443,7 @@ function validate(rs::ReactionSystem, info::String = "") # Needs additional checks because for cases: (1.0^n) and (1.0^n1)*(1.0^n2). # These are not considered (be default) considered equal to `1.0` for unitless reactions. isequal(rxunits, rateunits) && continue - if istree(rxunits) + if iscall(rxunits) unitless_exp(rxunits) && continue (operation(rxunits) == *) && all(unitless_exp(arg) for arg in arguments(rxunits)) && continue end @@ -1456,4 +1456,4 @@ function validate(rs::ReactionSystem, info::String = "") end # Checks if a unit consist of exponents with base 1 (and is this unitless). -unitless_exp(u) = istree(u) && (operation(u) == ^) && (arguments(u)[1] == 1) \ No newline at end of file +unitless_exp(u) = iscall(u) && (operation(u) == ^) && (arguments(u)[1] == 1) \ No newline at end of file diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index 38a634ff77..1c070e10ae 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -560,7 +560,7 @@ function nonlinear_convert_differentials_check(rs::ReactionSystem) # If the contenct of the differential is not a variable (and nothing more). # If either of this is a case, throws the warning. if Symbolics._occursin(Symbolics.is_derivative, eq.rhs) || - !Symbolics.istree(eq.lhs) || + !Symbolics.iscall(eq.lhs) || !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || (length(arguments(eq.lhs)) != 1) || !any(isequal(arguments(eq.lhs)[1]), nonspecies(rs)) @@ -895,7 +895,7 @@ function to_multivariate_poly(polyeqs::AbstractVector{Symbolics.BasicSymbolic{Re pvar2sym, sym2term = SymbolicUtils.get_pvar2sym(), SymbolicUtils.get_sym2term() ps = map(polyeqs) do x - if istree(x) && operation(x) == (/) + if iscall(x) && operation(x) == (/) error("We should not be able to get here, please contact the package authors.") else PolyForm(x, pvar2sym, sym2term).p diff --git a/src/registered_functions.jl b/src/registered_functions.jl index 70f06ac080..5de41e4d0f 100644 --- a/src/registered_functions.jl +++ b/src/registered_functions.jl @@ -118,7 +118,7 @@ expand_registered_functions(expr) Takes an expression, and expands registered function expressions. E.g. `mm(X,v,K)` is replaced with v*X/(X+K). Currently supported functions: `mm`, `mmr`, `hill`, `hillr`, and `hill`. """ function expand_registered_functions(expr) - istree(expr) || return expr + iscall(expr) || return expr args = arguments(expr) if operation(expr) == Catalyst.mm return args[2]*args[1]/(args[1] + args[3]) diff --git a/test/dsl/dsl_basic_model_construction.jl b/test/dsl/dsl_basic_model_construction.jl index 72dd01f1ab..dba2bbea01 100644 --- a/test/dsl/dsl_basic_model_construction.jl +++ b/test/dsl/dsl_basic_model_construction.jl @@ -2,8 +2,9 @@ # Fetch packages. using DiffEqBase, Catalyst, Random, Test -using ModelingToolkit: operation, istree, get_unknowns, get_ps, get_eqs, get_systems, +using ModelingToolkit: operation, get_unknowns, get_ps, get_eqs, get_systems, get_iv, nameof +using TermInterface: iscall # Sets stable rng number. using StableRNGs @@ -22,7 +23,7 @@ function unpacksys(sys) get_eqs(sys), get_iv(sys), get_unknowns(sys), get_ps(sys), nameof(sys), get_systems(sys) end -opname(x) = istree(x) ? nameof(operation(x)) : nameof(x) +opname(x) = iscall(x) ? nameof(operation(x)) : nameof(x) alleq(xs, ys) = all(isequal(x, y) for (x, y) in zip(xs, ys)) # Gets all the reactants in a set of equations. From 18813a282095ff13441536c99ac2bf8d3be982a3 Mon Sep 17 00:00:00 2001 From: Torkel Date: Wed, 29 May 2024 19:38:46 -0400 Subject: [PATCH 02/12] reactivate old tests --- test/runtests.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 8f255921d7..2de4ae3ee8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,7 +18,7 @@ using SafeTestsets, Test @time @safetestset "Symbolic Stoichiometry" begin include("reactionsystem_core/symbolic_stoichiometry.jl") end @time @safetestset "Parameter Type Designation" begin include("reactionsystem_core/parameter_type_designation.jl") end @time @safetestset "Custom CRN Functions" begin include("reactionsystem_core/custom_crn_functions.jl") end - # @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end + @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end @time @safetestset "Events" begin include("reactionsystem_core/events.jl") end # Tests model creation via the @reaction_network DSL. @@ -72,9 +72,9 @@ using SafeTestsets, Test end # Tests extensions. - # @time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end - # @time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end - # @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end + @time @safetestset "BifurcationKit Extension" begin include("extensions/bifurcation_kit.jl") end + @time @safetestset "HomotopyContinuation Extension" begin include("extensions/homotopy_continuation.jl") end + @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end #end end # @time From dd833de03d2a993eefacf12d1dad54eda9e0ee0c Mon Sep 17 00:00:00 2001 From: Torkel Date: Thu, 30 May 2024 10:50:03 -0400 Subject: [PATCH 03/12] Symbolics -> TermInterface --- src/reactionsystem_conversions.jl | 2 +- test/runtests.jl | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index 1c070e10ae..70c17c3f8c 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -560,7 +560,7 @@ function nonlinear_convert_differentials_check(rs::ReactionSystem) # If the contenct of the differential is not a variable (and nothing more). # If either of this is a case, throws the warning. if Symbolics._occursin(Symbolics.is_derivative, eq.rhs) || - !Symbolics.iscall(eq.lhs) || + !iscall(eq.lhs) || !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || (length(arguments(eq.lhs)) != 1) || !any(isequal(arguments(eq.lhs)[1]), nonspecies(rs)) diff --git a/test/runtests.jl b/test/runtests.jl index 2de4ae3ee8..1a8f58c323 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,13 +11,6 @@ using SafeTestsets, Test @time begin #if GROUP == "All" || GROUP == "ModelCreation" - # Tests the `ReactionSystem` structure and its properties. - @time @safetestset "Reaction Structure" begin include("reactionsystem_core/reaction.jl") end - @time @safetestset "ReactionSystem Structure" begin include("reactionsystem_core/reactionsystem.jl") end - @time @safetestset "Higher Order Reactions" begin include("reactionsystem_core/higher_order_reactions.jl") end - @time @safetestset "Symbolic Stoichiometry" begin include("reactionsystem_core/symbolic_stoichiometry.jl") end - @time @safetestset "Parameter Type Designation" begin include("reactionsystem_core/parameter_type_designation.jl") end - @time @safetestset "Custom CRN Functions" begin include("reactionsystem_core/custom_crn_functions.jl") end @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end @time @safetestset "Events" begin include("reactionsystem_core/events.jl") end From ac3057b563cc937fa34ce160987de50ecf1226eb Mon Sep 17 00:00:00 2001 From: Torkel Date: Thu, 6 Jun 2024 11:02:28 -0400 Subject: [PATCH 04/12] Update SymbolicUtils compat --- Project.toml | 3 ++- src/reactionsystem_conversions.jl | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index d87c0cd88b..2ccc5fbc24 100644 --- a/Project.toml +++ b/Project.toml @@ -56,8 +56,9 @@ Requires = "1.0" RuntimeGeneratedFunctions = "0.5.12" Setfield = "1" StructuralIdentifiability = "0.5.1" -SymbolicUtils = "1.0.3" Symbolics = "5.27" +SymbolicUtils = "2.0.2" +TermInterface = "0.4.1" Unitful = "1.12.4" julia = "1.10" diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index d87cf7c3da..e0b230bb10 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -560,7 +560,7 @@ function nonlinear_convert_differentials_check(rs::ReactionSystem) # If the contenct of the differential is not a variable (and nothing more). # If either of this is a case, throws the warning. if Symbolics._occursin(Symbolics.is_derivative, eq.rhs) || - !iscall(eq.lhs) || + !Symbolics.is_derivative(eq.lhs) || !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || (length(arguments(eq.lhs)) != 1) || !any(isequal(arguments(eq.lhs)[1]), nonspecies(rs)) From 4b61e467cc6bd2608f9fcef3c696871e7111171c Mon Sep 17 00:00:00 2001 From: Torkel Date: Thu, 6 Jun 2024 12:42:30 -0400 Subject: [PATCH 05/12] up --- src/reactionsystem_conversions.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index e0b230bb10..c37c5b12b3 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -443,8 +443,8 @@ end # Finds and differentials in an expression, and sets these to 0. function remove_diffs(expr) - if Symbolics._occursin(Symbolics.is_derivative, expr) - return Symbolics.replace(expr, diff_2_zero) + if Symbolics.hasnode(Symbolics.is_derivative, expr) + return Symbolics.replacenode(expr, diff_2_zero) else return expr end From 295678db402f61398ba9a4b62d3c2a3e2c8b4651 Mon Sep 17 00:00:00 2001 From: Torkel Date: Fri, 7 Jun 2024 15:09:00 -0400 Subject: [PATCH 06/12] remove SymbolicUtils and related stuff --- Project.toml | 2 -- src/Catalyst.jl | 1 - src/chemistry_functionality.jl | 2 +- .../serialisation_support.jl | 8 ++--- .../serialise_fields.jl | 2 +- src/spatial_reaction_systems/utility.jl | 2 +- .../reactionsystem_serialisation.jl | 5 +-- .../parameter_type_designation.jl | 22 ++++++------ .../symbolic_stoichiometry.jl | 6 ++-- .../lattice_reaction_systems.jl | 34 +++++++++---------- 10 files changed, 41 insertions(+), 43 deletions(-) diff --git a/Project.toml b/Project.toml index 2ccc5fbc24..defcce26a8 100644 --- a/Project.toml +++ b/Project.toml @@ -21,7 +21,6 @@ Requires = "ae029012-a4dd-5104-9daa-d747884805df" RuntimeGeneratedFunctions = "7e49a35a-f44a-4d26-94aa-eba1b4ca6b47" Setfield = "efcf1570-3423-57d1-acb7-fd33fddbac46" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" -SymbolicUtils = "d1185830-fcd6-423d-90d6-eec64667417b" Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" TermInterface = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d" @@ -57,7 +56,6 @@ RuntimeGeneratedFunctions = "0.5.12" Setfield = "1" StructuralIdentifiability = "0.5.1" Symbolics = "5.27" -SymbolicUtils = "2.0.2" TermInterface = "0.4.1" Unitful = "1.12.4" julia = "1.10" diff --git a/src/Catalyst.jl b/src/Catalyst.jl index 6cfba05a9b..be74c2964e 100644 --- a/src/Catalyst.jl +++ b/src/Catalyst.jl @@ -23,7 +23,6 @@ using RuntimeGeneratedFunctions RuntimeGeneratedFunctions.init(@__MODULE__) import Symbolics: BasicSymbolic -import SymbolicUtils using TermInterface: iscall using ModelingToolkit: Symbolic, value, get_unknowns, get_ps, get_iv, get_systems, get_eqs, get_defaults, toparam, get_var_to_name, get_observed, diff --git a/src/chemistry_functionality.jl b/src/chemistry_functionality.jl index 941038046b..9cac3186ab 100644 --- a/src/chemistry_functionality.jl +++ b/src/chemistry_functionality.jl @@ -182,7 +182,7 @@ function make_compounds(expr) end push!(compound_declarations.args, :($(Expr(:escape, :($(compound_syms)))))) - # The output needs to be converted to Vector{Num} (from Vector{SymbolicUtils.BasicSymbolic{Real}}) to be consistent with e.g. @variables. + # The output needs to be converted to Vector{Num} (from Vector{BasicSymbolic{Real}}) to be consistent with e.g. @variables. compound_declarations.args[end] = :([ModelingToolkit.wrap(cmp) for cmp in $(compound_declarations.args[end])]) # Returns output that. diff --git a/src/reactionsystem_serialisation/serialisation_support.jl b/src/reactionsystem_serialisation/serialisation_support.jl index 62b366ca5b..c38e2d650e 100644 --- a/src/reactionsystem_serialisation/serialisation_support.jl +++ b/src/reactionsystem_serialisation/serialisation_support.jl @@ -103,9 +103,9 @@ function sym_2_declaration_string(sym; multiline_format = false) dec_string = "$(sym)" # If the symbol have a non-default type, appends the declaration of this. - # Assumes that the type is on the form `SymbolicUtils.BasicSymbolic{X}`. Contain error checks + # Assumes that the type is on the form `BasicSymbolic{X}`. Contain error checks # to ensure that this is the case. - if !(sym isa SymbolicUtils.BasicSymbolic{Real}) + if !(sym isa BasicSymbolic{Real}) sym_type = String(Symbol(typeof(Symbolics.unwrap(sym)))) if (get_substring(sym_type, 1, 28) != "SymbolicUtils.BasicSymbolic{") || (get_char_end(sym_type, 0) != '}') error("Encountered symbolic of unexpected type: $sym_type.") @@ -139,7 +139,7 @@ end # and metadata values (which hopefully almost exclusively) has simple, supported, types. Ideally, # more supported types can be added here. x_2_string(x::Num) = expression_2_string(x) -x_2_string(x::SymbolicUtils.BasicSymbolic{<:Real}) = expression_2_string(x) +x_2_string(x::BasicSymbolic{<:Real}) = expression_2_string(x) x_2_string(x::Bool) = string(x) x_2_string(x::String) = "\"$x\"" x_2_string(x::Char) = "\'$x\'" @@ -293,6 +293,6 @@ end function complicated_declaration(sym) isempty(get_metadata_to_declare(sym)) || (return true) ModelingToolkit.hasdefault(sym) && (return true) - (sym isa SymbolicUtils.BasicSymbolic{Real}) || (return true) + (sym isa BasicSymbolic{Real}) || (return true) return false end \ No newline at end of file diff --git a/src/reactionsystem_serialisation/serialise_fields.jl b/src/reactionsystem_serialisation/serialise_fields.jl index 964e3bb617..ba28d20629 100644 --- a/src/reactionsystem_serialisation/serialise_fields.jl +++ b/src/reactionsystem_serialisation/serialise_fields.jl @@ -445,7 +445,7 @@ function discrete_event_string(discrete_event, strip_call_dict) # Creates the string corresponding to the conditions. The special check is if the condition is # an expression like `X > 5.0`. Here, "(...)" is added for purely aesthetic reasons. condition_string = x_2_string(discrete_event.condition) - if discrete_event.condition isa SymbolicUtils.BasicSymbolic + if discrete_event.condition isa BasicSymbolic @string_prepend! "(" condition_string @string_append! condition_string ")" end diff --git a/src/spatial_reaction_systems/utility.jl b/src/spatial_reaction_systems/utility.jl index 691ba79a3c..f750c93140 100644 --- a/src/spatial_reaction_systems/utility.jl +++ b/src/spatial_reaction_systems/utility.jl @@ -203,7 +203,7 @@ end # If all parameters the rate depend on are uniform all edges, this becomes a length 1 vector. # Else a vector with each value corresponding to the rate at one specific edge. function compute_transport_rates(rate_law::Num, - p_val_dict::Dict{SymbolicUtils.BasicSymbolic{Real}, Vector{Float64}}, num_edges::Int64) + p_val_dict::Dict{BasicSymbolic{Real}, Vector{Float64}}, num_edges::Int64) # Finds parameters involved in rate and create a function evaluating the rate law. relevant_ps = Symbolics.get_variables(rate_law) rate_law_func = drop_expr(@RuntimeGeneratedFunction(build_function(rate_law, relevant_ps...))) diff --git a/test/miscellaneous_tests/reactionsystem_serialisation.jl b/test/miscellaneous_tests/reactionsystem_serialisation.jl index eab88d0abf..3af24e2b64 100644 --- a/test/miscellaneous_tests/reactionsystem_serialisation.jl +++ b/test/miscellaneous_tests/reactionsystem_serialisation.jl @@ -4,10 +4,11 @@ using Catalyst, Test using Catalyst: get_rxs using ModelingToolkit: getdefault, getdescription, get_metadata +using Symbolics: getmetadata # Creates missing getters for MTK metadata (can be removed once added to MTK). -getmisc(x) = SymbolicUtils.getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableMisc, nothing) -getinput(x) = SymbolicUtils.getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableInput, nothing) +getmisc(x) = getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableMisc, nothing) +getinput(x) = getmetadata(Symbolics.unwrap(x), ModelingToolkit.VariableInput, nothing) # Sets the default `t` and `D` to use. t = default_t() diff --git a/test/reactionsystem_core/parameter_type_designation.jl b/test/reactionsystem_core/parameter_type_designation.jl index d6f7a7d13d..204d0f5095 100644 --- a/test/reactionsystem_core/parameter_type_designation.jl +++ b/test/reactionsystem_core/parameter_type_designation.jl @@ -2,7 +2,7 @@ # Fetch packages. using Catalyst, JumpProcesses, NonlinearSolve, OrdinaryDiffEq, StochasticDiffEq, Test -using Symbolics: unwrap +using Symbolics: BasicSymbolic, unwrap # Sets stable rng number. using StableRNGs @@ -47,16 +47,16 @@ end # Tests that parameters stored in the system have the correct type. let - @test Symbolics.unwrap(rs.p1) isa SymbolicUtils.BasicSymbolic{Real} - @test Symbolics.unwrap(rs.d1) isa SymbolicUtils.BasicSymbolic{Real} - @test Symbolics.unwrap(rs.p2) isa SymbolicUtils.BasicSymbolic{Float64} - @test Symbolics.unwrap(rs.d2) isa SymbolicUtils.BasicSymbolic{Float64} - @test Symbolics.unwrap(rs.p3) isa SymbolicUtils.BasicSymbolic{Int64} - @test Symbolics.unwrap(rs.d3) isa SymbolicUtils.BasicSymbolic{Int64} - @test Symbolics.unwrap(rs.p4) isa SymbolicUtils.BasicSymbolic{Float32} - @test Symbolics.unwrap(rs.d4) isa SymbolicUtils.BasicSymbolic{Rational{Int64}} - @test Symbolics.unwrap(rs.p5) isa SymbolicUtils.BasicSymbolic{Rational{Int64}} - @test Symbolics.unwrap(rs.d5) isa SymbolicUtils.BasicSymbolic{Float32} + @test Symbolics.unwrap(rs.p1) isa BasicSymbolic{Real} + @test Symbolics.unwrap(rs.d1) isa BasicSymbolic{Real} + @test Symbolics.unwrap(rs.p2) isa BasicSymbolic{Float64} + @test Symbolics.unwrap(rs.d2) isa BasicSymbolic{Float64} + @test Symbolics.unwrap(rs.p3) isa BasicSymbolic{Int64} + @test Symbolics.unwrap(rs.d3) isa BasicSymbolic{Int64} + @test Symbolics.unwrap(rs.p4) isa BasicSymbolic{Float32} + @test Symbolics.unwrap(rs.d4) isa BasicSymbolic{Rational{Int64}} + @test Symbolics.unwrap(rs.p5) isa BasicSymbolic{Rational{Int64}} + @test Symbolics.unwrap(rs.d5) isa BasicSymbolic{Float32} end # Tests that simulations with differentially typed variables yields correct results. diff --git a/test/reactionsystem_core/symbolic_stoichiometry.jl b/test/reactionsystem_core/symbolic_stoichiometry.jl index 797a78f239..c2ec784919 100644 --- a/test/reactionsystem_core/symbolic_stoichiometry.jl +++ b/test/reactionsystem_core/symbolic_stoichiometry.jl @@ -2,7 +2,7 @@ # Fetch packages. using Catalyst, JumpProcesses, OrdinaryDiffEq, StochasticDiffEq, Statistics, Test -using Symbolics: unwrap +using Symbolics: BasicSymbolic, unwrap # Sets stable rng number. using StableRNGs @@ -46,8 +46,8 @@ let @test rs1 == rs2 == rs3 @test issetequal(unknowns(rs1), [X, Y]) @test issetequal(parameters(rs1), [p, k, d, n1, n2, n3]) - @test unwrap(d) isa SymbolicUtils.BasicSymbolic{Float64} - @test unwrap(n1) isa SymbolicUtils.BasicSymbolic{Int64} + @test unwrap(d) isa BasicSymbolic{Float64} + @test unwrap(n1) isa BasicSymbolic{Int64} end # Declares a network, parameter values, and initial conditions, to be used for the next couple of tests. diff --git a/test/spatial_modelling/lattice_reaction_systems.jl b/test/spatial_modelling/lattice_reaction_systems.jl index a1fce40846..a467baae61 100644 --- a/test/spatial_modelling/lattice_reaction_systems.jl +++ b/test/spatial_modelling/lattice_reaction_systems.jl @@ -2,7 +2,7 @@ # Fetch packages. using Catalyst, Graphs, Test -using Symbolics: unwrap +using Symbolics: BasicSymbolic, unwrap t = default_t() # Pre declares a grid. @@ -311,19 +311,19 @@ end # Loops through all parameters, ensuring that they have the correct type p_types = Dict([ModelingToolkit.nameof(p) => typeof(unwrap(p)) for p in parameters(lrs)]) - @test p_types[:k1] == SymbolicUtils.BasicSymbolic{Real} - @test p_types[:l1] == SymbolicUtils.BasicSymbolic{Real} - @test p_types[:k2] == SymbolicUtils.BasicSymbolic{Float64} - @test p_types[:l2] == SymbolicUtils.BasicSymbolic{Float64} - @test p_types[:k3] == SymbolicUtils.BasicSymbolic{Int64} - @test p_types[:l3] == SymbolicUtils.BasicSymbolic{Int64} - @test p_types[:k4] == SymbolicUtils.BasicSymbolic{Float32} - @test p_types[:l4] == SymbolicUtils.BasicSymbolic{Float32} - @test p_types[:k5] == SymbolicUtils.BasicSymbolic{Rational{Int64}} - @test p_types[:l5] == SymbolicUtils.BasicSymbolic{Rational{Int64}} - @test p_types[:D1] == SymbolicUtils.BasicSymbolic{Float32} - @test p_types[:D2] == SymbolicUtils.BasicSymbolic{Real} - @test p_types[:D3] == SymbolicUtils.BasicSymbolic{Rational{Int64}} + @test p_types[:k1] == BasicSymbolic{Real} + @test p_types[:l1] == BasicSymbolic{Real} + @test p_types[:k2] == BasicSymbolic{Float64} + @test p_types[:l2] == BasicSymbolic{Float64} + @test p_types[:k3] == BasicSymbolic{Int64} + @test p_types[:l3] == BasicSymbolic{Int64} + @test p_types[:k4] == BasicSymbolic{Float32} + @test p_types[:l4] == BasicSymbolic{Float32} + @test p_types[:k5] == BasicSymbolic{Rational{Int64}} + @test p_types[:l5] == BasicSymbolic{Rational{Int64}} + @test p_types[:D1] == BasicSymbolic{Float32} + @test p_types[:D2] == BasicSymbolic{Real} + @test p_types[:D3] == BasicSymbolic{Rational{Int64}} end # Checks that programmatically declared parameters (with types) can be used in `TransportReaction`s. @@ -338,9 +338,9 @@ end lrs = LatticeReactionSystem(rs, [tr], grid) p_types = Dict([ModelingToolkit.nameof(p) => typeof(unwrap(p)) for p in parameters(lrs)]) - @test p_types[:p] == SymbolicUtils.BasicSymbolic{Float32} - @test p_types[:d] == SymbolicUtils.BasicSymbolic{Real} - @test p_types[:D] == SymbolicUtils.BasicSymbolic{Rational{Int64}} + @test p_types[:p] == BasicSymbolic{Float32} + @test p_types[:d] == BasicSymbolic{Real} + @test p_types[:D] == BasicSymbolic{Rational{Int64}} u0 = [:X => [0.25, 0.5, 2.0, 4.0]] ps = [rs.p => 2.0, rs.d => 1.0, D => 1//2] From e6e1612c15f4db57108ff60087cd818f13c5b849 Mon Sep 17 00:00:00 2001 From: Torkel Date: Fri, 7 Jun 2024 16:00:50 -0400 Subject: [PATCH 07/12] enforce latest SI version --- Project.toml | 2 +- docs/Project.toml | 2 +- src/Catalyst.jl | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index defcce26a8..c3868ef59c 100644 --- a/Project.toml +++ b/Project.toml @@ -54,7 +54,7 @@ Reexport = "0.2, 1.0" Requires = "1.0" RuntimeGeneratedFunctions = "0.5.12" Setfield = "1" -StructuralIdentifiability = "0.5.1" +StructuralIdentifiability = "0.5.8" Symbolics = "5.27" TermInterface = "0.4.1" Unitful = "1.12.4" diff --git a/docs/Project.toml b/docs/Project.toml index 83ecae3cc6..60c13c5e50 100644 --- a/docs/Project.toml +++ b/docs/Project.toml @@ -68,5 +68,5 @@ SpecialFunctions = "2.4" StaticArrays = "1.9" SteadyStateDiffEq = "2.2" StochasticDiffEq = "6.65" -StructuralIdentifiability = "0.5.7" +StructuralIdentifiability = "0.5.8" Symbolics = "5.28" diff --git a/src/Catalyst.jl b/src/Catalyst.jl index be74c2964e..c3b66c0be9 100644 --- a/src/Catalyst.jl +++ b/src/Catalyst.jl @@ -44,6 +44,7 @@ import Graphs: DiGraph, SimpleGraph, SimpleDiGraph, vertices, edges, add_vertice import DataStructures: OrderedDict, OrderedSet import Parameters: @with_kw_noshow import Symbolics: occursin, wrap +import Symbolics.RewriteHelpers: hasnode, replacenode # globals for the modulate function default_time_deriv() From 201a675444841eea2e70ed14ddbf5f6795934414 Mon Sep 17 00:00:00 2001 From: Torkel Date: Fri, 7 Jun 2024 18:23:45 -0400 Subject: [PATCH 08/12] re enable all tests --- src/reactionsystem_conversions.jl | 4 ++-- test/runtests.jl | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index c37c5b12b3..f32cab808a 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -443,8 +443,8 @@ end # Finds and differentials in an expression, and sets these to 0. function remove_diffs(expr) - if Symbolics.hasnode(Symbolics.is_derivative, expr) - return Symbolics.replacenode(expr, diff_2_zero) + if hasnode(Symbolics.is_derivative, expr) + return replacenode(expr, diff_2_zero) else return expr end diff --git a/test/runtests.jl b/test/runtests.jl index 10a174ad3d..6743d7fa4b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,6 +11,13 @@ using SafeTestsets, Test @time begin #if GROUP == "All" || GROUP == "ModelCreation" + # Tests the `ReactionSystem` structure and its properties. + @time @safetestset "Reaction Structure" begin include("reactionsystem_core/reaction.jl") end + @time @safetestset "ReactionSystem Structure" begin include("reactionsystem_core/reactionsystem.jl") end + @time @safetestset "Higher Order Reactions" begin include("reactionsystem_core/higher_order_reactions.jl") end + @time @safetestset "Symbolic Stoichiometry" begin include("reactionsystem_core/symbolic_stoichiometry.jl") end + @time @safetestset "Parameter Type Designation" begin include("reactionsystem_core/parameter_type_designation.jl") end + @time @safetestset "Custom CRN Functions" begin include("reactionsystem_core/custom_crn_functions.jl") end @time @safetestset "Coupled CRN/Equation Systems" begin include("reactionsystem_core/coupled_equation_crn_systems.jl") end @time @safetestset "Events" begin include("reactionsystem_core/events.jl") end @@ -72,4 +79,4 @@ using SafeTestsets, Test @time @safetestset "Structural Identifiability Extension" begin include("extensions/structural_identifiability.jl") end #end -end # @time +end # @time \ No newline at end of file From a6f1cf4c9796bce1294cd6146fb965e05df91aec Mon Sep 17 00:00:00 2001 From: Torkel Loman Date: Sat, 8 Jun 2024 00:48:42 +0200 Subject: [PATCH 09/12] Update reactionsystem_conversions.jl --- src/reactionsystem_conversions.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index f32cab808a..b4f506a6c5 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -559,7 +559,7 @@ function nonlinear_convert_differentials_check(rs::ReactionSystem) # If the lhs upper level function is not a differential w.r.t. time. # If the contenct of the differential is not a variable (and nothing more). # If either of this is a case, throws the warning. - if Symbolics._occursin(Symbolics.is_derivative, eq.rhs) || + if hasnode(Symbolics.is_derivative, eq.rhs) || !Symbolics.is_derivative(eq.lhs) || !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || (length(arguments(eq.lhs)) != 1) || @@ -903,4 +903,4 @@ function to_multivariate_poly(polyeqs::AbstractVector{Symbolics.BasicSymbolic{Re end ps -end \ No newline at end of file +end From e7fe9815207de6656f858ed98838d58586366359 Mon Sep 17 00:00:00 2001 From: Torkel Date: Sat, 8 Jun 2024 09:36:59 -0400 Subject: [PATCH 10/12] up --- .../reactionsystem_serialisation.jl | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/test/miscellaneous_tests/reactionsystem_serialisation.jl b/test/miscellaneous_tests/reactionsystem_serialisation.jl index 7a795a9a5a..46ec69863c 100644 --- a/test/miscellaneous_tests/reactionsystem_serialisation.jl +++ b/test/miscellaneous_tests/reactionsystem_serialisation.jl @@ -192,16 +192,16 @@ let @test isequal(getdefault(rs_loaded.rs2.W2), float_md) # Checks that `Reaction` metadata fields are correct. - @test isequal(getmetadata(get_rxs(rs_loaded)[1], :misc), bool_md) - @test isequal(getmetadata(get_rxs(rs_loaded)[2], :misc), int_md) - @test isequal(getmetadata(get_rxs(rs_loaded)[3], :misc), sym_md) - @test isequal(getmetadata(get_rxs(rs_loaded)[4], :misc), str_md) - @test isequal(getmetadata(get_rxs(rs_loaded)[5], :misc), nothing_md) - @test isequal(getmetadata(get_rxs(rs_loaded.rs2)[1], :misc), expr_md) - @test isequal(getmetadata(get_rxs(rs_loaded.rs2)[2], :misc), tup_md) - @test isequal(getmetadata(get_rxs(rs_loaded.rs2)[3], :misc), vec_md) - @test isequal(getmetadata(get_rxs(rs_loaded.rs2)[4], :misc), dict_md) - @test isequal(getmetadata(get_rxs(rs_loaded.rs2)[5], :misc), mat_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded)[1]), bool_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded)[2]), int_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded)[3]), sym_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded)[4]), str_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded)[5]), nothing_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[1]), expr_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[2]), tup_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[3]), vec_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[4]), dict_md) + @test isequal(Catalyst.getmisc(get_rxs(rs_loaded.rs2)[5]), mat_md) # Checks that `ReactionSystem` metadata fields are correct. @test isequal(get_metadata(rs_loaded), mat_md) From e21071093da97727c867d46f745c927a220bb518 Mon Sep 17 00:00:00 2001 From: Torkel Date: Sat, 8 Jun 2024 10:17:34 -0400 Subject: [PATCH 11/12] format --- src/reactionsystem_conversions.jl | 8 ++++---- src/spatial_reaction_systems/utility.jl | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/reactionsystem_conversions.jl b/src/reactionsystem_conversions.jl index dfec8f7e71..0dc1402bc7 100644 --- a/src/reactionsystem_conversions.jl +++ b/src/reactionsystem_conversions.jl @@ -557,10 +557,10 @@ function nonlinear_convert_differentials_check(rs::ReactionSystem) # If the contenct of the differential is not a variable (and nothing more). # If either of this is a case, throws the warning. if hasnode(Symbolics.is_derivative, eq.rhs) || - !Symbolics.is_derivative(eq.lhs) || - !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || - (length(arguments(eq.lhs)) != 1) || - !any(isequal(arguments(eq.lhs)[1]), nonspecies(rs)) + !Symbolics.is_derivative(eq.lhs) || + !isequal(Symbolics.operation(eq.lhs), Differential(get_iv(rs))) || + (length(arguments(eq.lhs)) != 1) || + !any(isequal(arguments(eq.lhs)[1]), nonspecies(rs)) error("You are attempting to convert a `ReactionSystem` coupled with differential equations to a `NonlinearSystem`. However, some of these differentials are not of the form `D(x) ~ ...` where: (1) The left-hand side is a differential of a single variable with respect to the time independent variable, and (2) The right-hand side does not contain any differentials. diff --git a/src/spatial_reaction_systems/utility.jl b/src/spatial_reaction_systems/utility.jl index 26a729f9f0..bf6e0c2a2e 100644 --- a/src/spatial_reaction_systems/utility.jl +++ b/src/spatial_reaction_systems/utility.jl @@ -212,7 +212,7 @@ end # If all parameters the rate depend on are uniform all edges, this becomes a length 1 vector. # Else a vector with each value corresponding to the rate at one specific edge. function compute_transport_rates(rate_law::Num, - p_val_dict::Dict{BasicSymbolic{Real}, Vector{Float64}}, num_edges::Int64) + p_val_dict::Dict{BasicSymbolic{Real}, Vector{Float64}}, num_edges::Int64) # Finds parameters involved in rate and create a function evaluating the rate law. relevant_ps = Symbolics.get_variables(rate_law) rate_law_func = drop_expr(@RuntimeGeneratedFunction(build_function( From acdfca15da2c74b521898c4dc3403458ea8376e0 Mon Sep 17 00:00:00 2001 From: Torkel Date: Sat, 8 Jun 2024 11:16:46 -0400 Subject: [PATCH 12/12] formating fix --- .../structural_identifiability_extension.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl b/ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl index d790db263c..d4cc1ead23 100644 --- a/ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl +++ b/ext/CatalystStructuralIdentifiabilityExtension/structural_identifiability_extension.jl @@ -73,7 +73,7 @@ function SI.assess_local_identifiability(rs::ReactionSystem, args...; funcs_to_check = make_ftc(funcs_to_check, conseqs, vars) # Computes identifiability and converts it to a easy to read form. - out = SI.assess_local_identifiability(sys, args...; measured_quantities, + out = SI.assess_local_identifiability(osys, args...; measured_quantities, funcs_to_check, kwargs...) return make_output(out, funcs_to_check, reverse.(conseqs)) end