Skip to content

Commit

Permalink
fix error
Browse files Browse the repository at this point in the history
  • Loading branch information
TorkelE committed Sep 25, 2023
1 parent 6500568 commit 2df28db
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/reaction_network.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
11 changes: 7 additions & 4 deletions src/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 " *
Expand Down Expand Up @@ -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,
Expand Down
27 changes: 13 additions & 14 deletions test/model_simulation/simulate_SDEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 2df28db

Please sign in to comment.