From 2df28db186898315704f791037a7fbb9576fc465 Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 25 Sep 2023 17:43:52 -0400 Subject: [PATCH] fix error --- src/reaction_network.jl | 6 +----- src/reactionsystem.jl | 11 +++++++---- test/model_simulation/simulate_SDEs.jl | 27 +++++++++++++------------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/reaction_network.jl b/src/reaction_network.jl index 53ead0ddac..a74040affc 100644 --- a/src/reaction_network.jl +++ b/src/reaction_network.jl @@ -408,10 +408,6 @@ function make_reaction_system(ex::Expr; name = :(gensym(:ReactionSystem))) push!(rxexprs.args, get_rxexprs(reaction)) end - println(ps) - println(ns_ps) - println(sps) - # Returns the rephrased expression. quote $ps @@ -676,7 +672,7 @@ end # macro, similar to @parameters, but all paraemters become noise scaling parameters. macro noise_scaling_parameters(ex...) - vars = Symbolics._parse_vars(:parameters, Real, ex) + vars = Symbolics._parse_vars(:parameters, Real, ex, toparam) # vector of symbols that get defined lastarg = vars.args[end] diff --git a/src/reactionsystem.jl b/src/reactionsystem.jl index 21d38520b2..9f67c7fc68 100644 --- a/src/reactionsystem.jl +++ b/src/reactionsystem.jl @@ -1390,11 +1390,8 @@ function Base.convert(::Type{<:SDESystem}, rs::ReactionSystem; flatrs = Catalyst.flatten(rs) error_if_constraints(SDESystem, flatrs) - if any(isnoisescalingparameter, get_ps(flatrs)) - any(is_noise_scaling_parameter.(parameters(rs))) && error("You have declared some paraemters as noise scaling parameters, and also given a \"noise_scaling\" argument to SDEProblem. Please remove the \"noise_scaling\", as this way of scaling CLE noise is being depricated.") - @warn "Passing noise scaling input into SDEProblem will be deprecated. New standard is to declare one (or several) paraemter as noise scaling parameters when the ReactionSystem is created. Please read https://docs.sciml.ai/Catalyst/stable/catalyst_applications/advanced_simulations/#Scaling-the-noise-magnitude-in-the-chemical-Langevin-equations." - end + isnothing(noise_scaling) && (noise_scaling = get_noise_scaling(rs)) # Required until passing nosie into SDEProblem can be depricated. if noise_scaling isa AbstractArray (length(noise_scaling) != numreactions(flatrs)) && error("The number of elements in 'noise_scaling' must be equal " * @@ -1529,6 +1526,12 @@ function DiffEqBase.SDEProblem(rs::ReactionSystem, u0, tspan, include_zero_odes = true, checks = false, check_length = false, remove_conserved = false, kwargs...) + + if !isnothing(noise_scaling) + !isnothing(get_noise_scaling(rs)) && error("You have declared some parameters as noise scaling parameters, and also given a \"noise_scaling\" argument to SDEProblem. Please remove the \"noise_scaling\", as this way of scaling CLE noise is being depricated.") + @warn "Passing noise scaling input into SDEProblem will be deprecated. New standard is to declare one (or several) paraemter as noise scaling parameters when the ReactionSystem is created. Please read https://docs.sciml.ai/Catalyst/stable/catalyst_applications/advanced_simulations/#Scaling-the-noise-magnitude-in-the-chemical-Langevin-equations." + end + u0map = symmap_to_varmap(rs, u0) pmap = symmap_to_varmap(rs, p) sde_sys = convert(SDESystem, rs; noise_scaling, name, combinatoric_ratelaws, diff --git a/test/model_simulation/simulate_SDEs.jl b/test/model_simulation/simulate_SDEs.jl index e7647eb422..ffa2792118 100644 --- a/test/model_simulation/simulate_SDEs.jl +++ b/test/model_simulation/simulate_SDEs.jl @@ -119,6 +119,19 @@ let end end +### Checks Simulations Don't Error ### + +#Tries to create a large number of problem, ensuring there are no errors (cannot solve as solution likely to go into negatives). +let + for reaction_network in reaction_networks_all + for factor in [1e-2, 1e-1, 1e0, 1e1] + u0 = factor * rand(rng, length(states(reaction_network))) + p = factor * rand(rng, length(parameters(reaction_network))) + prob = SDEProblem(reaction_network, u0, (0.0, 1.0), p) + end + end +end + ### Noise Scaling ### # Tests with multiple noise scaling parameters directly in the macro. @@ -173,20 +186,6 @@ let @test sprob[:η1] == sprob[:η2] == sprob[:η3] == sprob[:η4] == 0.0 end - -### Checks Simulations Don't Error ### - -#Tries to create a large number of problem, ensuring there are no errors (cannot solve as solution likely to go into negatives). -let - for reaction_network in reaction_networks_all - for factor in [1e-2, 1e-1, 1e0, 1e1] - u0 = factor * rand(rng, length(states(reaction_network))) - p = factor * rand(rng, length(parameters(reaction_network))) - prob = SDEProblem(reaction_network, u0, (0.0, 1.0), p) - end - end -end - ### Other Tests ### # No parameter test.