# Certain callback does not seem to have an effect when solving JumpProblem

**URL:** https://discourse.julialang.org/t/certain-callback-does-not-seem-to-have-an-effect-when-solving-jumpproblem/46415
**Category:** Modelling & Simulations
**Created:** [September 10, 2020, 9:03pm UTC](https://discourse.julialang.org/t/certain-callback-does-not-seem-to-have-an-effect-when-solving-jumpproblem/46415 "2020-09-10T21:03:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [September 10, 2020, 9:03pm UTC](https://discourse.julialang.org/t/certain-callback-does-not-seem-to-have-an-effect-when-solving-jumpproblem/46415/1 "2020-09-10T21:03:24Z")

</div>

I am trying to solve a jump problem. As a part of it, mid simulation, I change a parameter. This is basically an input being triggered into the system. This does not seem to have much effect though, and I am unsure why:

```julia
using DifferentialEquations, Catalyst

my_network = @reaction_network begin
    v0 + hill(σ,v,K,n), ∅ → σ
    deg, (σ,iσ) → ∅
    (kB,kD), σ ↔ iσ
    input, iσ → σ
end v0 v K n kB kD deg input;
v0 = 0.01; v = 0.25; K = 5.; n = 2.;
kB = 1.; kD = 1.;
deg = 0.01;
input = 0.;
p = [v0, v, K, n, kB, kD, deg, input]

cb_condition(u,t,integrator) = (t==1000.)
function cb_affect!(integrator)
    integrator.p[8] = 10.
    #println(integrator.p) # This shows that p indeed gets modified correctly.
end
cb = DiscreteCallback(cb_condition,cb_affect!,save_positions = (false,false))

prob_disc = DiscreteProblem(my_network,[5,5],(0.,2000.),p)
prob_jump = JumpProblem(my_network,prob_disc,Direct())
sol = solve(prob_jump, SSAStepper(),callback=cb,tstops=[1000.])

using Plots
plot(sol)

```

Here the input should break the symmetry, but in the plot, I can see that both variables are very similar. The callback seems to work though, removing the comment gives me a print confirming that the parameter value is changed. Also, making the callback work on the 2nd parameter (`v`), I can see a drastic change at time `1000`. Finally, by setting the initial value of the input to `10`, I can confirm that the system solution looks very different.

I have never really run much SSA stuff, is there possibly something I am missing where the callback is not registered properly, or is there something else going on?

---

<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: [September 11, 2020, 11:31pm UTC](https://discourse.julialang.org/t/certain-callback-does-not-seem-to-have-an-effect-when-solving-jumpproblem/46415/2 "2020-09-11T23:31:20Z")

</div>

When you change parameters in a jump simulation, you will need to do `reset_jumps!(integrator)` to re-evaluate the next step, otherwise it won’t re-initiate.

---

<div class="post-metadata">

### Author: ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)
#### Post date: [September 12, 2020, 9:34am UTC](https://discourse.julialang.org/t/certain-callback-does-not-seem-to-have-an-effect-when-solving-jumpproblem/46415/3 "2020-09-12T09:34:41Z")

</div>

Sounds good.

When I try

```julia
function cb_affect!(integrator)
    integrator.p[8] = 10.
   reset_jumps!(integrator)
end

```

I get an `UndefVarError: reset_jumps! not defined` error. This is an extract from my `Pkg.status()`

```julia
  [479239e8] Catalyst v5.0.4 `~/.julia/dev/Catalyst`
  [cb7047e7] CatalystSupport v0.1.0 `~/.julia/dev/CatalystSupport`
  [134e5e36] Catlab v0.7.4
  [5ae59095] Colors v0.12.4
  [34da2185] Compat v3.15.0
  [a2441757] Coverage v1.1.1
  [864edb3b] DataStructures v0.17.20
  [31a5f54b] Debugger v0.6.6
  [2b5f629d] DiffEqBase v6.44.3
  [eb300fae] DiffEqBiological v4.2.0 `~/.julia/dev/DiffEqBiological`
  [f3b72e0c] DiffEqDevTools v2.27.0
  [c894b116] DiffEqJump v6.10.0
  [77a26b50] DiffEqNoiseProcess v5.3.0
  [c3c3384c] DiffEqParameters v0.2.0 `https://gitlab.com/slcu/teamHJ/niklas/DiffEqParameters.jl.git#master`
  [0c46a032] DifferentialEquations v6.15.0

```

I found a function `reset_aggregated_jumps!(integrator)`. No idea what it does. I can use it, the code runs, but there’s not change in behaviour:

```julia
function cb_affect!(integrator)
    integrator.p[8] = 10.
    reset_aggregated_jumps!(integrator)
end

```
