Event handling in jump problems

Consider for the sake of a minimal example the following pure jump problem.

rn2 = @reaction_network begin
    a, 0 --> X
end a

prob2_jump = JumpProblem(rn2, DiscreteProblem(rn2, [0], (0.0, 10.0), [1.0]), Direct())

I would like to change the rate a when X passes a certain threshold. A straightforward discrete callback

_cond(u,t,integ) = u[1] > 5
_affect!(integ) = integ.p[1] = 0.0

_cb = DiscreteCallback(_cond, _affect!)

does not work. Certainly because integ.p does not affect the jump callbacks.

Changing the mass-action-rates in the jump problem works as demonstrated in https://diffeq.sciml.ai/stable/types/jump_types/#Remaking-JumpProblems [1], but there is no accessing the jump problem from _affect! as far as I can tell.

The only route I could come up with, is terminating the integration when the condition hits, remake the problem with adjusted rates and final state as new initial condition, and keep integrating until the final time.

That works, yet feels a bit clunky and more importantly is not naturally compatible(?) with ensemble simulations.

Question is thus: How to change the rates of a jump process through callbacks?

This is specifically an issue with mass action jumps. Open an issue in DiffEqJump for us to discuss it. We need to change the way it handles rates a bit.

Thanks for the immediate reply!

See Mass-action jumps and event handling · Issue #185 · SciML/DiffEqJump.jl · GitHub for one possible approach.