SciML / JumpProcesses.jl

Build and simulate jump equations like Gillespie simulations and jump diffusions with constant and state-dependent rates and mix with differential equations and scientific machine learning (SciML)
https://docs.sciml.ai/JumpProcesses/stable/
Other
136 stars 35 forks source link

allocations with update_states! for Direct #305

Closed isaacsas closed 1 year ago

isaacsas commented 1 year ago

See https://discourse.julialang.org/t/memory-usage-while-solving-jumpproblem-increases-with-run-time-even-with-save-positions-false-false/96656/26

These don't seem to be an issue when using DirectFW from what I can tell. (There is a separate issue in that thread with Symbolics-generated functions via RuntimeGeneratedFunctions appearing to allocate too.)

isaacsas commented 1 year ago

This seems to be the issue for Direct:

https://github.com/SciML/JumpProcesses.jl/blob/f029c45049e425e249abe6f59b88bb1460f67d6c/src/aggregators/ssajump.jl#L184

isaacsas commented 1 year ago

Reading through this thread it seems like for a small enough number of jumps the most performant alternative is not manual splitting but building a Union type and storing the affects in a vector (NTuple?) with this type.

https://discourse.julialang.org/t/union-splitting-vs-c/61772/9

ChrisRackauckas commented 1 year ago

Union splitting is just doing the manual splitting at the compiler level.

isaacsas commented 1 year ago

Which seems to get better optimized from that thread (at least as of a few years ago).

isaacsas commented 1 year ago

I couldn't figure out how to have the compiler do it without converting to using a vector of the union type instead of a tuple, which seemed less ideal than manual splitting.