Skip to content

Commit

Permalink
Merge pull request #411 from isaacsas/fix_test_warnings
Browse files Browse the repository at this point in the history
Fix test warnings
  • Loading branch information
isaacsas committed Mar 26, 2024
2 parents e640a12 + 1d96b75 commit afab13e
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 37 deletions.
4 changes: 2 additions & 2 deletions test/constant_rate.jl
Expand Up @@ -33,7 +33,7 @@ nums = Int[]
@time for i in 1:10000
local jump_prob = JumpProblem(prob, Direct(), jump, jump2; rng = rng)
local sol = solve(jump_prob, FunctionMap())
push!(nums, sol[end])
push!(nums, sol.u[end])
end

@test mean(nums) - 45 < 1
Expand All @@ -47,7 +47,7 @@ nums = Int[]
@time for i in 1:10000
local jump_prob = JumpProblem(prob, Direct(), jump, jump2; rng = rng)
local sol = solve(jump_prob, FunctionMap())
push!(nums, sol[2])
push!(nums, sol.u[2])
end

@test sum(nums .== 0) / 10000 - 0.33 < 0.02
16 changes: 8 additions & 8 deletions test/ensemble_uniqueness.jl
Expand Up @@ -9,12 +9,12 @@ u0 = [0]
prob = DiscreteProblem(u0, (0.0, 100.0))
jump_prob = JumpProblem(prob, Direct(), j1, j2; rng = rng)
sol = solve(EnsembleProblem(jump_prob), FunctionMap(), trajectories = 3)
@test Array(sol[1]) !== Array(sol[2])
@test Array(sol[1]) !== Array(sol[3])
@test Array(sol[2]) !== Array(sol[3])
@test eltype(sol[1].u[1]) == Int
@test Array(sol.u[1]) !== Array(sol.u[2])
@test Array(sol.u[1]) !== Array(sol.u[3])
@test Array(sol.u[2]) !== Array(sol.u[3])
@test eltype(sol.u[1].u[1]) == Int
sol = solve(EnsembleProblem(jump_prob), SSAStepper(), trajectories = 3)
@test Array(sol[1]) !== Array(sol[2])
@test Array(sol[1]) !== Array(sol[3])
@test Array(sol[2]) !== Array(sol[3])
@test eltype(sol[1].u[1]) == Int
@test Array(sol.u[1]) !== Array(sol.u[2])
@test Array(sol.u[1]) !== Array(sol.u[3])
@test Array(sol.u[2]) !== Array(sol.u[3])
@test eltype(sol.u[1].u[1]) == Int
6 changes: 3 additions & 3 deletions test/extinction_test.jl
Expand Up @@ -58,15 +58,15 @@ sol = solve(jprob, SSAStepper(), callback = cb, save_end = false)
@test sol.t[end] < 1000.0

# test terminate
function extinction_condition(u, t, integrator)
function extinction_condition2(u, t, integrator)
u[1] == 1
end
function extinction_affect!(integrator)
function extinction_affect!2(integrator)
(saved, savedexactly) = savevalues!(integrator, true)
terminate!(integrator)
nothing
end
cb = DiscreteCallback(extinction_condition, extinction_affect!,
cb = DiscreteCallback(extinction_condition2, extinction_affect!2,
save_positions = (false, false))
dprob = DiscreteProblem(u0, (0.0, 1000.0), rates)
jprob = JumpProblem(dprob, Direct(), majump; save_positions = (false, false), rng = rng)
Expand Down
2 changes: 1 addition & 1 deletion test/longtimes_test.jl
Expand Up @@ -13,4 +13,4 @@ dt = tspan[2] / 1000
dprob = DiscreteProblem(u0, tspan, p)
jprob = JumpProblem(dprob, Direct(), maj, save_positions = (false, false), rng = rng)
sol = solve(jprob, SSAStepper(), saveat = tspan[1]:dt:tspan[2])
@test length(unique(sol[(end - 10):end][:])) > 1
@test length(unique(sol.u[(end - 10):end][:])) > 1
4 changes: 2 additions & 2 deletions test/monte_carlo_test.jl
Expand Up @@ -12,11 +12,11 @@ jump_prob = JumpProblem(prob, Direct(), jump; rng = rng)
monte_prob = EnsembleProblem(jump_prob)
sol = solve(monte_prob, SRIW1(), EnsembleSerial(), trajectories = 3,
save_everystep = false, dt = 0.001, adaptive = false)
@test sol[1].t[2] != sol[2].t[2] != sol[3].t[2]
@test sol.u[1].t[2] != sol.u[2].t[2] != sol.u[3].t[2]

jump = ConstantRateJump(rate, affect!)
jump_prob = JumpProblem(prob, Direct(), jump, save_positions = (true, false), rng = rng)
monte_prob = EnsembleProblem(jump_prob)
sol = solve(monte_prob, SRIW1(), EnsembleSerial(), trajectories = 3,
save_everystep = false, dt = 0.001, adaptive = false)
@test sol[1].t[2] != sol[2].t[2] != sol[3].t[2]
@test sol.u[1].t[2] != sol.u[2].t[2] != sol.u[3].t[2]
4 changes: 2 additions & 2 deletions test/saveat_regression.jl
Expand Up @@ -18,7 +18,7 @@ sol = JumpProcesses.solve(EnsembleProblem(jprob), SSAStepper(), saveat = ts,
trajectories = Nsims)

for i in 1:length(sol)
NA .+= sol[i][1, :]
NA .+= sol.u[i][1, :]
end

for i in 1:length(ts)
Expand All @@ -33,7 +33,7 @@ sol = JumpProcesses.solve(EnsembleProblem(jprob), SSAStepper(), trajectories = N

for i in 1:Nsims
for n in 1:length(ts)
NA[n] += sol[i](ts[n])[1]
NA[n] += sol.u[i](ts[n])[1]
end
end

Expand Down
4 changes: 2 additions & 2 deletions test/spatial/diffusion.jl
Expand Up @@ -45,7 +45,7 @@ starting_state = zeros(Int, length(u0), num_nodes)
center_node = trunc(Int, (num_nodes + 1) / 2)
starting_state[:, center_node] = copy(u0)
tspan = (0.0, tf)
prob = DiscreteProblem(starting_state, tspan, [])
prob = DiscreteProblem(starting_state, tspan)

hopping_rate = diffusivity * (linear_size / domain_size)^2
hopping_constants = [hopping_rate for i in starting_state]
Expand Down Expand Up @@ -162,7 +162,7 @@ for ci in CartesianIndices(hopping_constants)
end
starting_state = 25 * ones(Int, length(u0), num_nodes)
tspan = (0.0, 10.0)
prob = DiscreteProblem(starting_state, tspan, [])
prob = DiscreteProblem(starting_state, tspan)

jp = JumpProblem(prob, NSM(), majumps, hopping_constants = hopping_constants,
spatial_system = grid, save_positions = (false, false), rng = rng)
Expand Down
16 changes: 10 additions & 6 deletions test/spatial/spatial_majump.jl
Expand Up @@ -116,8 +116,10 @@ for spatial_jump_prob in uniform_jump_problems
end

# birth and death zero outside of center site
f(u, p, t) = L * u - diagm([0.0, 0.0, death_rate, 0.0, 0.0]) * u + [0.0, 0.0, 1.0, 0.0, 0.0]
ode_prob = ODEProblem(f, zeros(num_nodes), tspan)
function f2(u, p, t)
L * u - diagm([0.0, 0.0, death_rate, 0.0, 0.0]) * u + [0.0, 0.0, 1.0, 0.0, 0.0]
end
ode_prob = ODEProblem(f2, zeros(num_nodes), tspan)
sol = solve(ode_prob, Tsit5())

solution = solve(non_uniform_jump_problems[1], SSAStepper())
Expand All @@ -129,8 +131,8 @@ for (i, d) in enumerate(diff)
end

# birth everywhere, death only at center site
f(u, p, t) = L * u - diagm([0.0, 0.0, death_rate, 0.0, 0.0]) * u + ones(num_nodes)
ode_prob = ODEProblem(f, zeros(num_nodes), tspan)
f3(u, p, t) = L * u - diagm([0.0, 0.0, death_rate, 0.0, 0.0]) * u + ones(num_nodes)
ode_prob = ODEProblem(f3, zeros(num_nodes), tspan)
sol = solve(ode_prob, Tsit5())

solution = solve(non_uniform_jump_problems[2], SSAStepper())
Expand All @@ -142,8 +144,10 @@ for (i, d) in enumerate(diff)
end

# birth on left end, death on right end
f(u, p, t) = L * u - diagm([0.0, 0.0, 0.0, 0.0, death_rate]) * u + [1.0, 0.0, 0.0, 0.0, 0.0]
ode_prob = ODEProblem(f, zeros(num_nodes), tspan)
function f4(u, p, t)
L * u - diagm([0.0, 0.0, 0.0, 0.0, death_rate]) * u + [1.0, 0.0, 0.0, 0.0, 0.0]
end
ode_prob = ODEProblem(f4, zeros(num_nodes), tspan)
sol = solve(ode_prob, Tsit5())

solution = solve(non_uniform_jump_problems[3], SSAStepper())
Expand Down
22 changes: 11 additions & 11 deletions test/variable_rate.jl
Expand Up @@ -40,8 +40,8 @@ sol = solve(jump_prob, Rosenbrock23())
# @show sol[end]
# display(sol[end])

@test maximum([sol[i][2] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol[i][3] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol.u[i][2] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol.u[i][3] for i in 1:length(sol)]) <= 1e-12

g = function (du, u, p, t)
du[1] = u[1]
Expand All @@ -52,8 +52,8 @@ jump_prob = JumpProblem(prob, Direct(), jump, jump2; rng = rng)

sol = solve(jump_prob, SRIW1())

@test maximum([sol[i][2] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol[i][3] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol.u[i][2] for i in 1:length(sol)]) <= 1e-12
@test maximum([sol.u[i][3] for i in 1:length(sol)]) <= 1e-12

function ff(du, u, p, t)
if p == 0
Expand Down Expand Up @@ -95,16 +95,16 @@ jump = ConstantRateJump(rate2, affect2!)
jump_prob = JumpProblem(prob, Direct(), jump; rng = rng)
sol = solve(jump_prob, Tsit5())
sol(4.0)
sol[4]
sol.u[4]

rate2(u, p, t) = u[1]
rate2b(u, p, t) = u[1]
affect2!(integrator) = (integrator.u[1] = integrator.u[1] / 2)
jump = VariableRateJump(rate2, affect2!)
jump = VariableRateJump(rate2b, affect2!)
jump2 = deepcopy(jump)
jump_prob = JumpProblem(prob, Direct(), jump, jump2; rng = rng)
sol = solve(jump_prob, Tsit5())
sol(4.0)
sol[4]
sol.u[4]

function g2(du, u, p, t)
du[1] = u[1]
Expand All @@ -114,7 +114,7 @@ prob = SDEProblem(f2, g2, [0.2], (0.0, 10.0))
jump_prob = JumpProblem(prob, Direct(), jump, jump2; rng = rng)
sol = solve(jump_prob, SRIW1())
sol(4.0)
sol[4]
sol.u[4]

function f3(du, u, p, t)
du .= u
Expand Down Expand Up @@ -151,7 +151,7 @@ function drift(x, p, t)
return p * x
end

function rate2(x, p, t)
function rate2c(x, p, t)
return 3 * max(0.0, x[1])
end

Expand All @@ -160,7 +160,7 @@ function affect!2(integrator)
end
x0 = rand(2)
prob = ODEProblem(drift, x0, (0.0, 10.0), 2.0)
jump = VariableRateJump(rate2, affect!2)
jump = VariableRateJump(rate2c, affect!2)
jump_prob = JumpProblem(prob, Direct(), jump)

# test to check lack of dependency graphs is caught in Coevolve for systems with non-maj
Expand Down

0 comments on commit afab13e

Please sign in to comment.