Skip to content

Commit 1865f90

Browse files
committed
Merge remote-tracking branch 'refs/remotes/upstream/master'
Conflicts: src/spatial/topology.jl
2 parents 23044f4 + 32e0153 commit 1865f90

File tree

6 files changed

+62
-18
lines changed

6 files changed

+62
-18
lines changed

.github/workflows/Documentation.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,8 @@ jobs:
2222
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For authentication with GitHub Actions token
2323
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
2424
GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988
25-
run: julia --project=docs/ docs/make.jl
25+
run: julia --project=docs/ --code-coverage=user docs/make.jl
26+
- uses: julia-actions/julia-processcoverage@v1
27+
- uses: codecov/codecov-action@v1
28+
with:
29+
file: lcov.info

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "JumpProcesses"
22
uuid = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
33
authors = ["Chris Rackauckas <[email protected]>"]
4-
version = "9.1.0"
4+
version = "9.2.0"
55

66
[deps]
77
ArrayInterfaceCore = "30b0a656-2188-435a-8636-2ec0e6a096e2"
@@ -33,7 +33,7 @@ PoissonRandom = "0.4"
3333
RandomNumbers = "1.3"
3434
RecursiveArrayTools = "2"
3535
Reexport = "0.2, 1.0"
36-
SciMLBase = "1.35.1"
36+
SciMLBase = "1.51"
3737
StaticArrays = "0.10, 0.11, 0.12, 1.0"
3838
TreeViews = "0.3"
3939
UnPack = "1.0.2"

src/coupling.jl

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,13 @@ end
2020
function cat_problems(prob::DiffEqBase.AbstractODEProblem,
2121
prob_control::DiffEqBase.AbstractODEProblem)
2222
l = length(prob.u0) # add l_c = length(prob_control.u0)
23+
24+
_f = SciMLBase.unwrapped_f(prob.f)
25+
_f_control = SciMLBase.unwrapped_f(prob_control.f)
26+
2327
new_f = function (du, u, p, t)
24-
prob.f(@view(du[1:l]), u.u, p, t)
25-
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
28+
_f(@view(du[1:l]), u.u, p, t)
29+
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
2630
end
2731
u0_coupled = CoupledArray(prob.u0, prob_control.u0, true)
2832
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
@@ -33,9 +37,13 @@ function cat_problems(prob::DiscreteProblem, prob_control::DiffEqBase.AbstractOD
3337
if !(typeof(prob.f) <: typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
3438
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
3539
end
40+
41+
_f = SciMLBase.unwrapped_f(prob.f)
42+
_f_control = SciMLBase.unwrapped_f(prob_control.f)
43+
3644
new_f = function (du, u, p, t)
37-
prob.f(@view(du[1:l]), u.u, p, t)
38-
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
45+
_f(@view(du[1:l]), u.u, p, t)
46+
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
3947
end
4048
u0_coupled = CoupledArray(prob.u0, prob_control.u0, true)
4149
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
@@ -59,9 +67,13 @@ end
5967
function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
6068
prob_control::DiffEqBase.AbstractODEProblem)
6169
l = length(prob.u0)
70+
71+
_f = SciMLBase.unwrapped_f(prob.f)
72+
_f_control = SciMLBase.unwrapped_f(prob_control.f)
73+
6274
new_f = function (du, u, p, t)
63-
prob.f(@view(du[1:l]), u.u, p, t)
64-
prob_control.f(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
75+
_f(@view(du[1:l]), u.u, p, t)
76+
_f_control(@view(du[(l + 1):(2 * l)]), u.u_control, p, t)
6577
end
6678
new_g = function (du, u, p, t)
6779
prob.g(@view(du[1:l]), u.u, p, t)

src/problem.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,13 @@ function extend_problem(prob::DiffEqBase.AbstractDiscreteProblem, jumps; rng = D
227227
end
228228

229229
function extend_problem(prob::DiffEqBase.AbstractODEProblem, jumps; rng = DEFAULT_RNG)
230-
function jump_f(du::ExtendedJumpArray, u::ExtendedJumpArray, p, t)
231-
prob.f(du.u, u.u, p, t)
232-
update_jumps!(du, u, p, t, length(u.u), jumps.variable_jumps...)
230+
_f = SciMLBase.unwrapped_f(prob.f)
231+
232+
jump_f = let _f = _f
233+
function jump_f(du::ExtendedJumpArray, u::ExtendedJumpArray, p, t)
234+
_f(du.u, u.u, p, t)
235+
update_jumps!(du, u, p, t, length(u.u), jumps.variable_jumps...)
236+
end
233237
end
234238
ttype = eltype(prob.tspan)
235239
u0 = ExtendedJumpArray(prob.u0,

src/spatial/topology.jl

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ struct CartesianGridRej{N, T}
109109
dims::NTuple{N, Int}
110110

111111
"number of neighbor for each site"
112-
nums_neighbors::Vector{Int}
112+
nums_neighbors::Vector{Int8}
113113
CI::CartesianIndices{N, T}
114114
LI::LinearIndices{N, T}
115115

@@ -127,7 +127,7 @@ function CartesianGridRej(dims::Tuple)
127127
CI = CartesianIndices(dims)
128128
LI = LinearIndices(dims)
129129
offsets = potential_offsets(dim)
130-
nums_neighbors = [count(x -> x + CI[site] in CI, offsets) for site in 1:prod(dims)]
130+
nums_neighbors = Int8[count(x -> x + CI[site] in CI, offsets) for site in 1:prod(dims)]
131131
CartesianGridRej(dims, nums_neighbors, CI, LI, offsets)
132132
end
133133
CartesianGridRej(dims) = CartesianGridRej(Tuple(dims))
@@ -144,6 +144,30 @@ function rand_nbr(rng, grid::CartesianGridRej, site::Int)
144144
end
145145
end
146146

147+
# neighbor sampling is iterator-based
148+
struct CartesianGridIter{N, T}
149+
dims::NTuple{N, Int}
150+
nums_neighbors::Vector{Int8}
151+
CI::CartesianIndices{N, T}
152+
LI::LinearIndices{N, T}
153+
offsets::Vector{CartesianIndex{N}}
154+
end
155+
function CartesianGridIter(dims::Tuple)
156+
dim = length(dims)
157+
CI = CartesianIndices(dims)
158+
LI = LinearIndices(dims)
159+
offsets = potential_offsets(dim)
160+
nums_neighbors = Int8[count(x -> x + CI[site] in CI, offsets) for site in 1:prod(dims)]
161+
CartesianGridIter(dims, nums_neighbors, CI, LI, offsets)
162+
end
163+
CartesianGridIter(dims) = CartesianGridIter(Tuple(dims))
164+
function CartesianGridIter(dimension, linear_size::Int)
165+
CartesianGridIter([linear_size for i in 1:dimension])
166+
end
167+
function rand_nbr(rng, grid::CartesianGridIter, site::Int)
168+
nth_nbr(grid, site, rand(rng, 1:outdegree(grid, site)))
169+
end
170+
147171
function Base.show(io::IO, ::MIME"text/plain",
148172
grid::CartesianGridRej)
149173
println(io, "A Cartesian grid with dimensions $(grid.dims)")

test/spatial/diffusion.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ Bt = B'
5555
analytic_solution(t) = B * diagm(ℯ .^ (t * evals)) * Bt * reshape(prob.u0, num_nodes, 1)
5656

5757
num_time_points = 10
58-
Nsims = 10000
59-
rel_tol = 0.01
58+
Nsims = 50000
59+
rel_tol = 0.02
6060
times = 0.0:(tf / num_time_points):tf
6161

6262
algs = [NSM(), DirectCRDirect()]
@@ -143,7 +143,7 @@ for (j, spatial_jump_prob) in enumerate(jump_problems)
143143
end
144144
end
145145

146-
# testing non-uniform hopping rates
146+
# testing non-uniform hopping rates. Only hopping up or left.
147147
dims = (2, 2)
148148
num_nodes = prod(dims)
149149
grid = Graphs.grid(dims)
@@ -153,7 +153,7 @@ for ci in CartesianIndices(hopping_constants)
153153
hopping_constants[species, site] = zeros(outdegree(grid, site))
154154
for (n, nb) in enumerate(neighbors(grid, site))
155155
if nb < site
156-
hopping_constants[species, site][n] = 1.0
156+
hopping_constants[species, site][n] = 10.0
157157
end
158158
end
159159
end

0 commit comments

Comments
 (0)