# Event handling in jump problems

**URL:** <https://discourse.julialang.org/t/event-handling-in-jump-problems/63882>\
**Category:** Modelling & Simulations\
**Tags:** question, diffeq\
**Created:** [July 1, 2021, 10:32am UTC](https://discourse.julialang.org/t/event-handling-in-jump-problems/63882 "2021-07-01T10:32:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [July 1, 2021, 10:32am UTC](https://discourse.julialang.org/t/event-handling-in-jump-problems/63882/1 "2021-07-01T10:32:23Z")

</div>

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

```julia
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

```julia
_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](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?

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [July 1, 2021, 10:37am UTC](https://discourse.julialang.org/t/event-handling-in-jump-problems/63882/2 "2021-07-01T10:37:49Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![skleinbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/skleinbo/32/36080_2.png) [@skleinbo](https://discourse.julialang.org/u/skleinbo)\
**Post date:** [July 1, 2021, 11:16am UTC](https://discourse.julialang.org/t/event-handling-in-jump-problems/63882/3 "2021-07-01T11:16:24Z")

</div>

Thanks for the immediate reply!

[https://github.com/SciML/DiffEqJump.jl/issues/185](https://github.com/SciML/DiffEqJump.jl/issues/185)

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [July 1, 2021, 4:40pm UTC](https://discourse.julialang.org/t/event-handling-in-jump-problems/63882/4 "2021-07-01T16:40:26Z")

</div>

See [https://github.com/SciML/DiffEqJump.jl/issues/185#issuecomment-872342884](https://github.com/SciML/DiffEqJump.jl/issues/185#issuecomment-872342884) for one possible approach.
