# Memory usage while solving \`JumpProblem\` increases with run time, even with \`save\_positions=(false,false)\`

**URL:** <https://discourse.julialang.org/t/memory-usage-while-solving-jumpproblem-increases-with-run-time-even-with-save-positions-false-false/96656>\
**Category:** New to Julia\
**Tags:** differentialequation, catalyst\
**Created:** [March 27, 2023, 11:47am UTC](https://discourse.julialang.org/t/memory-usage-while-solving-jumpproblem-increases-with-run-time-even-with-save-positions-false-false/96656 "2023-03-27T11:47:31Z")\
**Posts on this page:** 1\
**Showing post:** 25

<div class="post-metadata">

**Author:** ![johannesnauta](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johannesnauta/32/47434_2.png) [@johannesnauta](https://discourse.julialang.org/u/johannesnauta)\
**Post date:** [March 27, 2023, 4:58pm UTC](https://discourse.julialang.org/t/memory-usage-while-solving-jumpproblem-increases-with-run-time-even-with-save-positions-false-false/96656/25 "2023-03-27T16:58:19Z")

</div>

I rewrote my code to not use a `Symbolics` `@reaction_network`, similar to your implementation, but I do see the increase in memory allocations still (albeit a bit less)…

# Code

(I didn’t want to hide your discussion in my long functions, so here’s a fold:

> **See code details here**
>
> ```julia
> function catalystplasmiddirect(;T = 100.0)    
> function rate(η,X,Y,K)
> return η*(1-(X+Y)/K)
> end
> 
> r1(u,p,t) = rate(p[1],u[1],u[2],p[2])*u[1]
> r2(u,p,t) = rate(p[1],u[2],u[1],p[2])*u[2]
> r3(u,p,t) = p[3]*u[1]
> r4(u,p,t) = p[3]*u[2]
> r5(u,p,t) = p[4]*u[1]*u[2]
> r6(u,p,t) = p[5]*u[2]
> aff1!(integrator) = integrator.u[1] += 1
> aff2!(integrator) = integrator.u[2] += 1
> aff3!(integrator) = integrator.u[1] -= 1
> aff4!(integrator) = integrator.u[2] -= 1
> function aff5!(integrator)
> integrator.u[1] -= 1
> integrator.u[2] += 1
> end
> function aff6!(integrator)
> integrator.u[1] += 1
> integrator.u[2] -= 1
> end
> # η K μ γ ρ
> p = (1.0, 1e4, 0.1, 1e-4, 0.01)
> u0 = [1000,10]
> tspan = (0.0, T)
> 
> dprob = DiscreteProblem(u0, tspan, p)
> jprob = JumpProblem(
> dprob, Direct(),
> ConstantRateJump(r1,aff1!), ConstantRateJump(r2,aff2!), ConstantRateJump(r3,aff3!),
> ConstantRateJump(r4,aff4!), ConstantRateJump(r5,aff5!), ConstantRateJump(r6,aff6!);
> save_positions=(false,false)
> )
> return jprob
> end
> 
> ```
> 
> And the benchmarks:
> 
> ```julia
> julia> long_prob = catalystplasmiddirect(T=1e5)
> JumpProblem with problem DiscreteProblem with aggregator Direct
> Number of jumps with discrete aggregation: 6
> Number of jumps with continuous aggregation: 0
> Number of mass action jumps: 0
> 
> julia> long_sol = solve(long_prob, stepper)
> retcode: Success
> Interpolation: Piecewise constant interpolation
> t: 2-element Vector{Float64}:
> 0.0
> 100000.0
> u: 2-element Vector{Vector{Int64}}:
> [1000, 10]
> [98, 8850]
> 
> julia> @btime solve($long_prob, $stepper)
> 11.082 s (195816952 allocations: 2.92 GiB)
> retcode: Success
> Interpolation: Piecewise constant interpolation
> t: 2-element Vector{Float64}:
> 0.0
> 100000.0
> u: 2-element Vector{Vector{Int64}}:
> [1000, 10]
> [96, 8951]
> 
> julia> short_prob = catalystplasmiddirect(T=1e2)
> JumpProblem with problem DiscreteProblem with aggregator Direct
> Number of jumps with discrete aggregation: 6
> Number of jumps with continuous aggregation: 0
> Number of mass action jumps: 0
> 
> julia> short_sol = solve(short_prob, stepper)
> retcode: Success
> Interpolation: Piecewise constant interpolation
> t: 2-element Vector{Float64}:
> 0.0
> 100.0
> u: 2-element Vector{Vector{Int64}}:
> [1000, 10]
> [92, 8892]
> 
> julia> @btime solve($short_prob, $stepper)
> 10.677 ms (204394 allocations: 3.12 MiB)
> retcode: Success
> Interpolation: Piecewise constant interpolation
> t: 2-element Vector{Float64}:
> 0.0
> 100.0
> u: 2-element Vector{Vector{Int64}}:
> [1000, 10]
> [118, 8933]
> 
> ```

---

_[View the full topic](https://discourse.julialang.org/t/memory-usage-while-solving-jumpproblem-increases-with-run-time-even-with-save-positions-false-false/96656)._
