Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cleanup #682

Merged
merged 7 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/dsl/dsl_basics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Fetch Packages and Set Global Variables ###

using Catalyst, ModelingToolkit
using Catalyst
@variables t

### Naming Tests ###
Expand Down
18 changes: 9 additions & 9 deletions test/miscellaneous_tests/symbolic_stoichiometry.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Catalyst, ModelingToolkit, OrdinaryDiffEq, Test, LinearAlgebra, JumpProcesses
using Catalyst, OrdinaryDiffEq, Test, LinearAlgebra, JumpProcesses

### Base Tests ###

Expand Down Expand Up @@ -34,7 +34,7 @@ let
du1 = zeros(size(oprob.u0))
oprob.f(du1, oprob.u0, oprob.p, 1.5)

function oderhs(du, u, p, t)
function oderhs1(du, u, p, t)
k = p[1]
α = p[2]
A = u[1]
Expand All @@ -51,15 +51,15 @@ let
end
u0 = [uv[2] for uv in u0map]
p = Tuple(pv[2] for pv in pmap)
oprob2 = ODEProblem(oderhs, u0, tspan, p)
oprob2 = ODEProblem(oderhs1, u0, tspan, p)
du2 = copy(du1)
oprob2.f(du2, oprob2.u0, oprob2.p, 1.5)
@test norm(du1 .- du2) < 100 * eps()

# Test without rate law scalings.
osys = convert(ODESystem, rs, combinatoric_ratelaws = false)
oprob = ODEProblem(osys, u0map, tspan, pmap)
function oderhs(du, u, p, t)
function oderhs2(du, u, p, t)
k = p[1]
α = p[2]
A = u[1]
Expand All @@ -74,7 +74,7 @@ let
du[3] = k * rl2
du[4] = α * rl2
end
oprob2 = ODEProblem(oderhs, [uv[2] for uv in u0map], tspan, oprob.p)
oprob2 = ODEProblem(oderhs2, [uv[2] for uv in u0map], tspan, oprob.p)
du1 .= 0
du2 .= 0
oprob.f(du1, oprob.u0, oprob.p, 1.5)
Expand All @@ -85,7 +85,7 @@ let
ssys = convert(SDESystem, rs)
sf = SDEFunction{false}(ssys, states(ssys), parameters(ssys))
G = sf.g(u0, p, 1.0)
function sdenoise(u, p, t)
function sdenoise1(u, p, t)
k = p[1]
α = p[2]
A = u[1]
Expand All @@ -100,14 +100,14 @@ let
0.0 k*rl2;
0.0 α*rl2]
end
G2 = sdenoise(u0, p, 1.0)
G2 = sdenoise1(u0, p, 1.0)
@test norm(G - G2) < 100 * eps()

# SDESystem test with no combinatoric rate laws.
ssys = convert(SDESystem, rs, combinatoric_ratelaws = false)
sf = SDEFunction{false}(ssys, states(ssys), parameters(ssys))
G = sf.g(u0, p, 1.0)
function sdenoise(u, p, t)
function sdenoise2(u, p, t)
k = p[1]
α = p[2]
A = u[1]
Expand All @@ -122,7 +122,7 @@ let
0.0 k*rl2;
0.0 α*rl2]
end
G2 = sdenoise(u0, p, 1.0)
G2 = sdenoise2(u0, p, 1.0)
@test norm(G - G2) < 100 * eps()

# JumpSystem test.
Expand Down
6 changes: 2 additions & 4 deletions test/model_simulation/simulate_ODEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ using StableRNGs
rng = StableRNG(12345)

# Fetch test networks.
include("../test_networks.jl")
@time include("../test_networks.jl")

### Compares to Known Solution ###

Expand Down Expand Up @@ -119,8 +119,6 @@ end

let
for (i, network) in enumerate(reaction_networks_all)
(i % 5 == 0) &&
println("Iteration " * string(i) * " at line 104 in file solve_ODEs.jl")
for factor in [1e-1, 1e0, 1e1]
u0 = factor * rand(rng, length(get_states(network)))
p = factor * rand(rng, length(get_ps(network)))
Expand Down Expand Up @@ -157,7 +155,7 @@ let
p = [:k => 1.0]
oprob = ODEProblem(rn, u0, tspan, p; combinatoric_ratelaws = false)
du1 = du2 = zeros(2)
u = rand(2)
u = rand(rng, 2)
oprob.f(du1, u, [1.0], 0.0)
oderhs(du2, u, [1.0], 0.0)
@test isapprox(du1, du2, rtol = 1e3 * eps())
Expand Down
6 changes: 5 additions & 1 deletion test/model_simulation/simulate_PDEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ using Catalyst, OrdinaryDiffEq, Test
using ModelingToolkit, DomainSets
const MT = ModelingToolkit

# Sets rnd number.
using StableRNGs
rng = StableRNG(12345)

# Test function.
function icfun(n, x, y, A)
float(rand(Poisson(round(n * A * 10))) / A / 10)
float(rand(rng, Poisson(round(n * A * 10))) / A / 10)
end

### Run Tests ###
Expand Down
10 changes: 4 additions & 6 deletions test/model_simulation/simulate_jumps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ let
push!(identical_networks, reaction_networks_constraint[5] => jumps_3)

for (i, networks) in enumerate(identical_networks)
for factor in [1e-2, 1e-1, 1e0, 1e1], repeat in 1:3
for factor in [1e-2, 1e-1, 1e0, 1e1]
(i == 3) && (factor > 1e-1) && continue # Large numbers seems to crash it.
u0 = rand(rng, 1:Int64(factor * 100), length(get_states(networks[1])))
p = factor * rand(rng, length(get_ps(networks[1])))
Expand All @@ -118,10 +118,8 @@ end
### Checks Simulations Don't Error ###

let
for (i, network) in enumerate(reaction_networks_all)
(i % 5 == 0) &&
println("Iteration " * string(i) * " at line 102 in file solve_jumps.jl")
for factor in [1e-1, 1e0, 1e1]
for network in reaction_networks_all
for factor in [1e0]
u0 = rand(rng, 1:Int64(factor * 100), length(get_states(network)))
p = factor * rand(rng, length(get_ps(network)))
prob = JumpProblem(network, DiscreteProblem(network, u0, (0.0, 1.0), p),
Expand All @@ -136,7 +134,7 @@ end
# No parameter test.
let
no_param_network = @reaction_network begin (1.2, 5), X1 ↔ X2 end
for factor in [1e1, 1e2]
for factor in [1e1]
u0 = rand(rng, 1:Int64(factor * 100), length(get_states(no_param_network)))
prob = JumpProblem(no_param_network,
DiscreteProblem(no_param_network, u0, (0.0, 1000.0)), Direct())
Expand Down
2 changes: 1 addition & 1 deletion test/reactionsystem_structure/higher_order_reactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ let
d * binomial(X10, 2), 2X10 ⟾ ∅
end

for factor in [1e-1, 1e0], repeat in 1:5
for factor in [1e-1, 1e0]
u0 = rand(rng, 1:Int64(factor * 100), length(get_states(higher_order_network_1)))
p = factor * rand(rng, length(get_ps(higher_order_network_3)))
prob1 = JumpProblem(higher_order_network_1,
Expand Down
28 changes: 16 additions & 12 deletions test/reactionsystem_structure/reactionsystem.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
using Catalyst, LinearAlgebra, JumpProcesses, Test, OrdinaryDiffEq, StochasticDiffEq
const MT = ModelingToolkit

# Sets rnd number.
using StableRNGs
rng = StableRNG(12345)

# Create test network.
@parameters k[1:20]
@variables t
Expand Down Expand Up @@ -140,8 +144,8 @@ end
# Don't ask me (Torkel) why the statement before/after is needed.
t = 0.0
let
p = rand(length(k))
u = rand(length(k))
p = rand(rng, length(k))
u = rand(rng, length(k))
du = oderhs(u, p, t)
G = sdenoise(u, p, t)
sdesys = convert(SDESystem, rs)
Expand All @@ -162,8 +166,8 @@ end

# Tests the noise_scaling argument.
let
p = rand(length(k) + 1)
u = rand(length(k))
p = rand(rng, length(k) + 1)
u = rand(rng, length(k))
t = 0.0
G = p[21] * sdenoise(u, p, t)
@variables η
Expand All @@ -176,8 +180,8 @@ end

# Tests the noise_scaling vector argument.
let
p = rand(length(k) + 3)
u = rand(length(k))
p = rand(rng, length(k) + 3)
u = rand(rng, length(k))
t = 0.0
G = vcat(fill(p[21], 8), fill(p[22], 3), fill(p[23], 9))' .* sdenoise(u, p, t)
@variables η[1:3]
Expand All @@ -192,8 +196,8 @@ end

# Tests using previous parameter for noise scaling
let
p = rand(length(k))
u = rand(length(k))
p = rand(rng, length(k))
u = rand(rng, length(k))
t = 0.0
G = [p p p p]' .* sdenoise(u, p, t)
sdesys_noise_scaling = convert(SDESystem, rs; noise_scaling = k)
Expand All @@ -205,7 +209,7 @@ end

# Test with JumpSystem.
let
p = rand(length(k))
p = rand(rng, length(k))
@variables t
@species A(t) B(t) C(t) D(t) E(t) F(t)
rxs = [Reaction(k[1], nothing, [A]), # 0 -> A
Expand Down Expand Up @@ -239,9 +243,9 @@ let
@test all(map(i -> typeof(equations(js)[i]) <: JumpProcesses.ConstantRateJump, cidxs))
@test all(map(i -> typeof(equations(js)[i]) <: JumpProcesses.VariableRateJump, vidxs))

pars = rand(length(k))
u0 = rand(2:10, 6)
ttt = rand()
pars = rand(rng, length(k))
u0 = rand(rng, 2:10, 6)
ttt = rand(rng)
jumps = Vector{Union{ConstantRateJump, MassActionJump, VariableRateJump}}(undef,
length(rxs))

Expand Down
Loading