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

`Coevolve` can call `urate` with a time beyond the time span #330

Closed gaurav-arya closed 1 year ago

gaurav-arya commented 1 year ago

MWE

using JumpProcesses

test_rate(u, p, t) = 3.0 
test_affect!(integrator) = (integrator.u[1] += 1)
function test_urate(u, p, t) 
    if t > 1.0
        error("test_urate does not handle t > 1.0")
    else
        return 4.0
    end
end

test_jump = VariableRateJump(test_rate, test_affect!; urate=test_urate, rateinterval=(u,p,t)->0.9)

dprob = DiscreteProblem([0], (0.0, 1.0), nothing) 
jprob = JumpProblem(dprob, Coevolve(), test_jump; dep_graph=[[1]])

for i in 1:100
    solve(jprob, SSAStepper())
end 
# sometimes throws ERROR: test_urate does not handle t > 1.0

I had a practical case where I ran into the above issue because my supplied urate function actually went haywire for t beyond my timespan. In general I think it would be a good property to only call the user-supplied functions for t in the timespan?

isaacsas commented 1 year ago

This should now be closed, but we can reopen if it recurs.