Skip to content

Commit d08e5c4

Browse files
Merge pull request #473 from isaacsas/threading_fix
don't access callbacks till checking they exist
2 parents 7f7bee5 + f6996d0 commit d08e5c4

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ end
4747

4848
function resetted_jump_problem(_jump_prob, seed)
4949
jump_prob = deepcopy(_jump_prob)
50-
rng = jump_prob.jump_callback.discrete_callbacks[1].condition.rng
5150
if !isempty(jump_prob.jump_callback.discrete_callbacks)
51+
rng = jump_prob.jump_callback.discrete_callbacks[1].condition.rng
5252
if seed === nothing
5353
Random.seed!(rng, rand(UInt64))
5454
else

test/thread_safety.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
using DiffEqBase
2-
using JumpProcesses
2+
using JumpProcesses, OrdinaryDiffEq
33
using StableRNGs
44
rng = StableRNG(12345)
55

@@ -13,3 +13,19 @@ jprob = JumpProblem(dprob, Direct(), maj; rng = rng)
1313
solve(EnsembleProblem(jprob), SSAStepper(), EnsembleThreads(); trajectories = 10)
1414
solve(EnsembleProblem(jprob; safetycopy = true), SSAStepper(), EnsembleThreads();
1515
trajectories = 10)
16+
17+
# test for https://github.com/SciML/JumpProcesses.jl/issues/472
18+
let
19+
function f!(du, u, p, t)
20+
du[1] = -u[1]
21+
nothing
22+
end
23+
u_0 = [1.0]
24+
ode_prob = ODEProblem(f!, u_0, (0.0, 10))
25+
rate(u, p, t) = 1.0
26+
jump!(integrator) = nothing
27+
jump_prob = JumpProblem(ode_prob, Direct(), VariableRateJump(rate, jump!); rng)
28+
prob_func(prob, i, repeat) = deepcopy(prob)
29+
prob = EnsembleProblem(jump_prob,prob_func = prob_func)
30+
solve(prob, Tsit5(), EnsembleThreads(), trajectories=10)
31+
end

0 commit comments

Comments
 (0)