Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/SciML/JumpProcesses.jl in…
Browse files Browse the repository at this point in the history
…to spatial-constant-rate-jump-2
  • Loading branch information
Vilin97 committed Sep 14, 2023
2 parents 865aa69 + 42404e0 commit 5c97a63
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
12 changes: 7 additions & 5 deletions test/spatial/ABC.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using JumpProcesses, DiffEqBase
# using BenchmarkTools
using Test, Graphs
using StableRNGs
rng = StableRNG(12345)

Nsims = 100
reltol = 0.05
Expand Down Expand Up @@ -67,19 +69,19 @@ grids = [CartesianGridRej(dims), Graphs.grid(dims)]
jump_problems = JumpProblem[JumpProblem(prob, NSM(), majumps,
hopping_constants = hopping_constants,
spatial_system = grid,
save_positions = (false, false)) for grid in grids]
save_positions = (false, false), rng = rng) for grid in grids]
push!(jump_problems,
JumpProblem(prob, DirectCRDirect(), majumps, hopping_constants = hopping_constants,
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
# setup constant rate jump problems
push!(jump_problems, JumpProblem(prob, NSM(), crjumps, hopping_constants = hopping_constants,
spatial_system = CartesianGrid(dims), save_positions = (false, false), dep_graph = dep_graph, jumptovars_map = jumptovars_map))
spatial_system = CartesianGrid(dims), save_positions = (false, false), dep_graph = dep_graph, jumptovars_map = jumptovars_map, rng = rng))
push!(jump_problems, JumpProblem(prob, DirectCRDirect(), crjumps, hopping_constants = hopping_constants,
spatial_system = CartesianGrid(dims), save_positions = (false, false), dep_graph = dep_graph, jumptovars_map = jumptovars_map))
spatial_system = CartesianGrid(dims), save_positions = (false, false), dep_graph = dep_graph, jumptovars_map = jumptovars_map, rng = rng))
# setup flattenned jump prob
push!(jump_problems,
JumpProblem(prob, NRM(), majumps, hopping_constants = hopping_constants,
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
# test
for spatial_jump_prob in jump_problems
solution = solve(spatial_jump_prob, SSAStepper())
Expand Down
26 changes: 14 additions & 12 deletions test/spatial/diffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ using JumpProcesses, DiffEqBase
using Test
using LinearAlgebra
using Graphs
using StableRNGs
rng = StableRNG(12345)

function get_mean_sol(jump_prob, Nsims, saveat)
sol = solve(jump_prob, SSAStepper(), saveat = saveat).u
Expand Down Expand Up @@ -55,7 +57,7 @@ Bt = B'
analytic_solution(t) = B * diagm(ℯ .^ (t * evals)) * Bt * reshape(prob.u0, num_nodes, 1)

num_time_points = 10
Nsims = 50000
Nsims = 10000
rel_tol = 0.02
times = 0.0:(tf / num_time_points):tf

Expand All @@ -64,23 +66,23 @@ grids = [CartesianGridRej(dims), Graphs.grid(dims)]
jump_problems = JumpProblem[JumpProblem(prob, algs[2], majumps,
hopping_constants = hopping_constants,
spatial_system = grid,
save_positions = (false, false)) for grid in grids]
save_positions = (false, false), rng = rng) for grid in grids]
sizehint!(jump_problems, 15 + length(jump_problems))

# flattenned jump prob
push!(jump_problems,
JumpProblem(prob, NRM(), majumps, hopping_constants = hopping_constants,
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))

# hop rates of form D_s
hop_constants = [hopping_rate]
for alg in algs
push!(jump_problems,
JumpProblem(prob, alg, majumps, hopping_constants = hop_constants,
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
push!(jump_problems,
JumpProblem(prob, alg, majumps, hopping_constants = hop_constants,
spatial_system = grids[end], save_positions = (false, false)))
spatial_system = grids[end], save_positions = (false, false), rng = rng))
end

# hop rates of form L_{s,i,j}
Expand All @@ -93,10 +95,10 @@ end
for alg in algs
push!(jump_problems,
JumpProblem(prob, alg, majumps, hopping_constants = hop_constants,
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
push!(jump_problems,
JumpProblem(prob, alg, majumps, hopping_constants = hop_constants,
spatial_system = grids[end], save_positions = (false, false)))
spatial_system = grids[end], save_positions = (false, false), rng = rng))
end

# hop rates of form D_s * L_{i,j}
Expand All @@ -109,11 +111,11 @@ for alg in algs
push!(jump_problems,
JumpProblem(prob, alg, majumps,
hopping_constants = Pair(species_hop_constants, site_hop_constants),
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
push!(jump_problems,
JumpProblem(prob, alg, majumps,
hopping_constants = Pair(species_hop_constants, site_hop_constants),
spatial_system = grids[end], save_positions = (false, false)))
spatial_system = grids[end], save_positions = (false, false), rng = rng))
end

# hop rates of form D_{s,i} * L_{i,j}
Expand All @@ -126,11 +128,11 @@ for alg in algs
push!(jump_problems,
JumpProblem(prob, alg, majumps,
hopping_constants = Pair(species_hop_constants, site_hop_constants),
spatial_system = grids[1], save_positions = (false, false)))
spatial_system = grids[1], save_positions = (false, false), rng = rng))
push!(jump_problems,
JumpProblem(prob, alg, majumps,
hopping_constants = Pair(species_hop_constants, site_hop_constants),
spatial_system = grids[end], save_positions = (false, false)))
spatial_system = grids[end], save_positions = (false, false), rng = rng))
end

# testing
Expand Down Expand Up @@ -162,7 +164,7 @@ tspan = (0.0, 10.0)
prob = DiscreteProblem(starting_state, tspan, [])

jp = JumpProblem(prob, NSM(), majumps, hopping_constants = hopping_constants,
spatial_system = grid, save_positions = (false, false))
spatial_system = grid, save_positions = (false, false), rng = rng)
sol = solve(jp, SSAStepper())

@test sol.u[end][1, 1] == sum(sol.u[end])
10 changes: 6 additions & 4 deletions test/spatial/spatial_majump.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using JumpProcesses, DiffEqBase, OrdinaryDiffEq
using Test, Graphs, LinearAlgebra
using StableRNGs
rng = StableRNG(12345)

reltol = 0.05
Nsims = 10^4
Nsims = 10^3

dim = 1
linear_size = 5
Expand Down Expand Up @@ -57,19 +59,19 @@ non_uniform_majumps = [non_uniform_majumps_1, non_uniform_majumps_2, non_uniform
uniform_jump_problems = JumpProblem[JumpProblem(prob, NSM(), majump,
hopping_constants = hopping_constants,
spatial_system = grid,
save_positions = (false, false))
save_positions = (false, false), rng = rng)
for majump in uniform_majumps]
# flattenned
append!(uniform_jump_problems,
JumpProblem[JumpProblem(prob, NRM(), majump, hopping_constants = hopping_constants,
spatial_system = grid, save_positions = (false, false))
spatial_system = grid, save_positions = (false, false), rng = rng)
for majump in uniform_majumps])

# non-uniform
non_uniform_jump_problems = JumpProblem[JumpProblem(prob, NSM(), majump,
hopping_constants = hopping_constants,
spatial_system = grid,
save_positions = (false, false))
save_positions = (false, false), rng = rng)
for majump in non_uniform_majumps]

# testing
Expand Down

0 comments on commit 5c97a63

Please sign in to comment.