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
140 stars 35 forks source link

Better documentation of `remake` mutating original problems #416

Open TorkelE opened 5 months ago

TorkelE commented 5 months ago

Normally remake does not affect the input problems. However, for JumpProblem this is the case:

using Catalyst, JumpProcesses
# Creates the model.
rn = @reaction_network begin
    p1*p2, A + B --> C
end
@unpack p1, p2 = rn

u0 = [:A => 1, :B => 2, :C => 3]
ps = [:p1 => 3.0, :p2 => 2.0]
dprob = DiscreteProblem(rn, u0, (0.0, 1.0), ps)
jprob = JumpProblem(rn, dprob, Direct())

jprob.massaction_jump.scaled_rates[1] # Returns 6.0.
jprob2 = remake(jprob; p = [p1 => 0.0]) 
jprob.massaction_jump.scaled_rates[1]  # returns 0.0 
jprob2.massaction_jump.scaled_rates[1] # returns 0.0

This should be documented properly, and a kwarg added to instead make a deepcopy of the input problem (so that there is no mutation).