# StackOverflowError for large set of Jumps in JumpProcesses.jl with high-dimensional set of ODEs

Hello,
I have to simulate a large (n=1000) set of simple ODEs, and each ODE gets an independent realisation of Poisson input.
When trying to set up the JumpProblem as in the documentation.
However, when the number of dynamical variables is large somehow a StackOverflowError is raised when constructing the problem:

``````using DifferentialEquations, JumpProcesses
using StatsBase

# Define the ODE system
function large_ode_system!(du, u, p, t)
n = length(u)
for i in 1:n
du[i] = - u[i]
end
end

# Define initial conditions and parameters
n = 1000 #n=50 works
u0 = ones(n)
tspan = (0.0, 1.0)

rate(u, p, t) = 1. #in Hz
function create_jump_affect(affected_id)

function jump_affect_by_id!(integrator)
refractory = sample(1:n, 10)
if !(affected_id in refractory)
integrator.u[affected_id] +=  1.
end
nothing
end
return jump_affect_by_id!
end

# Define the problem
prob = ODEProblem(large_ode_system!, u0, tspan, p)

# Generate individual jumps
jumps = ConstantRateJump[]
for i in 1:n
push!(jumps,ConstantRateJump(rate, create_jump_affect(i)))
end

# Create jump set
try
jumpset_1 = JumpSet(jumps...);#gives StackOverflowError (because of recursion)?
catch error
println(error)
finally
nothing
end

########################################################
#alternative: create jump set 'manually':
function create_jump_set(constant_jumps::Vector{ConstantRateJump})
# Create a JumpSet with the provided constant rate jumps and empty/nil for other jump types
return JumpSet((), tuple(constant_jumps...), nothing, nothing)
end

jumpset_2 = create_jump_set(jumps);#works fine

# Manual handling of multiple jumps (conceptual, adjust based on actual usage)
jump_prob = JumpProblem(prob, Direct(), jumpset_2)

# Solve the problem
sol = solve(jump_prob, ImplicitEuler(), saveat=0.1) #now this gives a StackOverflowError ('Internal error: stack overflow in type inference of solve!')
``````

How can one get around this? Any suggestion is more than welcome!

Try `DirectFW()` for large numbers of jumps.