Skip to content

Commit

Permalink
don't use callbacks till check they exist
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacsas committed Feb 10, 2025
1 parent 7f7bee5 commit 33e63fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/solve.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ end

function resetted_jump_problem(_jump_prob, seed)
jump_prob = deepcopy(_jump_prob)
rng = jump_prob.jump_callback.discrete_callbacks[1].condition.rng
if !isempty(jump_prob.jump_callback.discrete_callbacks)
rng = jump_prob.jump_callback.discrete_callbacks[1].condition.rng
if seed === nothing
Random.seed!(rng, rand(UInt64))
else
Expand Down
18 changes: 17 additions & 1 deletion test/thread_safety.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DiffEqBase
using JumpProcesses
using JumpProcesses, OrdinaryDiffEqTsit5
using StableRNGs
rng = StableRNG(12345)

Expand All @@ -13,3 +13,19 @@ jprob = JumpProblem(dprob, Direct(), maj; rng = rng)
solve(EnsembleProblem(jprob), SSAStepper(), EnsembleThreads(); trajectories = 10)
solve(EnsembleProblem(jprob; safetycopy = true), SSAStepper(), EnsembleThreads();
trajectories = 10)

# test for https://github.com/SciML/JumpProcesses.jl/issues/472
let
function f!(du, u, p, t)
du[1] = -u[1]
nothing
end
u_0 = [1.0]
ode_prob = ODEProblem(f!, u_0, (0.0, 10))
rate(u, p, t) = 1.0
jump!(integrator) = nothing
jump_prob = JumpProblem(ode_prob, Direct(), VariableRateJump(rate, jump!); rng)
prob_func(prob, i, repeat) = deepcopy(prob)
prob = EnsembleProblem(jump_prob,prob_func = prob_func)
solve(prob, Tsit5(), EnsembleThreads(), trajectories=10)
end

0 comments on commit 33e63fd

Please sign in to comment.