@ChrisRackauckas can confirm this pure JumpProcesses version of the first network does not exhibit this issue. So this seems to be coming from the Symbolics codegen or RuntimeGeneratedFunctions.
julia> function lotkavolterradirect(; T = 100.0)
r1(u,p,t) = growth(p[1], u[1], u[2], p[2]) * u[1]
r2(u,p,t) = growth(p[1], u[2], u[1], p[2]) * u[2]
aff1!(int) = int.u[1] += 1
aff2!(int) = int.u[2] += 1
p = (.1, 1000)
u0 = [50, 100]
tspan = (0.0, T)
dprob = DiscreteProblem(u0, tspan, p)
jprob = JumpProblem(dprob, Direct(), ConstantRateJump(r1,aff1!), ConstantRateJump(r2, aff2!); save_positions = (false,false))
jprob
end
lotkavolterradirect (generic function with 1 method)
julia> jprob = lotkavolterradirect(T = 10.0)
JumpProblem with problem DiscreteProblem with aggregator Direct
Number of jumps with discrete aggregation: 2
Number of jumps with continuous aggregation: 0
Number of mass action jumps: 0
julia> sol = solve(jprob, SSAStepper())
retcode: Success
Interpolation: Piecewise constant interpolation
t: 2-element Vector{Float64}:
0.0
10.0
u: 2-element Vector{Vector{Int64}}:
[50, 100]
[102, 216]
julia> @btime solve($jprob, SSAStepper())
5.858 μs (11 allocations: 1.03 KiB)
retcode: Success
Interpolation: Piecewise constant interpolation
t: 2-element Vector{Float64}:
0.0
10.0
u: 2-element Vector{Vector{Int64}}:
[50, 100]
[109, 228]
julia> jprob2 = lotkavolterradirect(T = 100.0)
JumpProblem with problem DiscreteProblem with aggregator Direct
Number of jumps with discrete aggregation: 2
Number of jumps with continuous aggregation: 0
Number of mass action jumps: 0
julia> @btime solve($jprob2, SSAStepper())
30.625 μs (11 allocations: 1.03 KiB)
retcode: Success
Interpolation: Piecewise constant interpolation
t: 2-element Vector{Float64}:
0.0
100.0
u: 2-element Vector{Vector{Int64}}:
[50, 100]
[402, 598]
Example:
julia> jprob = lotkavolterra(T = 10.0)
JumpProblem with problem DiscreteProblem with aggregator Direct
Number of jumps with discrete aggregation: 2
Number of jumps with continuous aggregation: 0
Number of mass action jumps: 0
julia> aff1 = jprob.discrete_jump_aggregation.affects![1]
RuntimeGeneratedFunction(#=in ModelingToolkit=#, #=using ModelingToolkit=#, :((var"##MTKIntegrator#1026",)->begin
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:350 =#
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:351 =#
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:352 =#
begin
ˍ₋out = (var"##MTKIntegrator#1026").u
ˍ₋arg1 = (var"##MTKIntegrator#1026").u
ˍ₋arg2 = (var"##MTKIntegrator#1026").p
t = (var"##MTKIntegrator#1026").t
begin
begin
#= /Users/isaacsas/.julia/packages/Symbolics/VIBnK/src/build_function.jl:520 =#
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:399 =# @inbounds begin
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:395 =#
ˍ₋out[1] = (+)(1, ˍ₋arg1[1])
#= /Users/isaacsas/.julia/packages/SymbolicUtils/1JRDc/src/code.jl:397 =#
nothing
end
end
end
end
end))
julia> int = (u = [1.0], p = (1.0, 1.0, 1.0), t = 1.0)
(u = [1.0], p = (1.0, 1.0, 1.0), t = 1.0)
julia> @btime aff1($int)
14.194 ns (1 allocation: 48 bytes)
julia> @btime aff1($int)
14.194 ns (1 allocation: 48 bytes)