Skip to content

Commit 0489d30

Browse files
finalize the upgrade
1 parent 748547e commit 0489d30

File tree

5 files changed

+84
-20
lines changed

5 files changed

+84
-20
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
2323
DataStructures = "0.17"
2424
DelayDiffEq = "5"
2525
DiffEqBase = "6.29"
26-
DiffEqNoiseProcess = "3.3.1"
26+
DiffEqNoiseProcess = "5"
2727
RandomNumbers = "1"
2828
RecursiveArrayTools = "1,2"
2929
Reexport = "0.2"
3030
StaticArrays = "0.11, 0.12"
3131
StochasticDiffEq = "6.19"
3232
UnPack = "0.1, 1.0"
33-
julia = "1.3"
33+
julia = "1.4"
3434

3535
[extras]
3636
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"

src/integrators/interface.jl

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,24 @@ end
298298
end
299299
end
300300
return saved, savedexactly
301-
end
301+
end
302+
303+
@inline function DiffEqNoiseProcess.setup_next_step!(integrator::SDDEIntegrator)
304+
!isnothing(integrator.W) && DiffEqNoiseProcess.setup_next_step!(integrator.W,integrator.u,integrator.p)
305+
!isnothing(integrator.P) && DiffEqNoiseProcess.setup_next_step!(integrator.P,integrator.u,integrator.p)
306+
end
307+
308+
@inline function DiffEqNoiseProcess.reject_step!(integrator::SDDEIntegrator,dtnew = integrator.dtnew)
309+
!isnothing(integrator.W) && reject_step!(integrator.W,dtnew,integrator.u,integrator.p)
310+
!isnothing(integrator.P) && reject_step!(integrator.P,dtnew,integrator.u,integrator.p)
311+
end
312+
313+
@inline function DiffEqNoiseProcess.accept_step!(integrator::SDDEIntegrator,setup)
314+
!isnothing(integrator.W) && accept_step!(integrator.W,integrator.dt,integrator.u,integrator.p,setup)
315+
!isnothing(integrator.P) && accept_step!(integrator.P,integrator.dt,integrator.u,integrator.p,setup)
316+
end
317+
318+
@inline function DiffEqNoiseProcess.save_noise!(integrator::SDDEIntegrator)
319+
!isnothing(integrator.W) && DiffEqNoiseProcess.save_noise!(integrator.W)
320+
!isnothing(integrator.P) && DiffEqNoiseProcess.save_noise!(integrator.P)
321+
end

src/integrators/type.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ mutable struct HistorySDEIntegrator{algType,IIP,uType,tType,SolType,CacheType} <
1313
end
1414

1515
mutable struct
16-
SDDEIntegrator{algType,IIP,uType,uEltype,tType,P,eigenType,tTypeNoUnits,uEltypeNoUnits,randType,rateType,solType,cacheType,F,G,OType,noiseType,EventErrorType,CallbackCacheType,H,IType} <: AbstractSDDEIntegrator{algType,IIP,uType,tType}
16+
SDDEIntegrator{algType,IIP,uType,uEltype,tType,P,eigenType,tTypeNoUnits,uEltypeNoUnits,randType,randType2,rateType,solType,cacheType,F,G,F6,OType,noiseType,EventErrorType,CallbackCacheType,H,IType} <: AbstractSDDEIntegrator{algType,IIP,uType,tType}
1717
f::F
1818
g::G
19+
c::F6
1920
noise::noiseType
2021
uprev::uType
2122
tprev::tType
@@ -53,6 +54,7 @@ mutable struct
5354
callback_cache::CallbackCacheType
5455
sqdt::tType
5556
W::randType
57+
P::randType2
5658
opts::OType
5759
iter::Int
5860
success_iter::Int
@@ -64,11 +66,11 @@ mutable struct
6466
history::H
6567
integrator::IType # history integrator
6668
end
67-
69+
6870
function (integrator::SDDEIntegrator)(t, deriv::Type=Val{0}; idxs=nothing)
6971
StochasticDiffEq.current_interpolant(t, integrator, idxs, deriv)
7072
end
71-
73+
7274
function (integrator::SDDEIntegrator)(val::AbstractArray, t::Union{Number,AbstractArray},deriv::Type=Val{0}; idxs=nothing)
7375
StochasticDiffEq.current_interpolant!(val, t, integrator, idxs, deriv)
74-
end
76+
end

src/solve.jl

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
7676
error("Bridge function must be given for adaptivity. Either declare this function in noise process or set adaptive=false")
7777
end
7878

79-
if !StochasticDiffEq.alg_compatible(prob, getalg(alg))
80-
error("The algorithm is not compatible with the chosen noise type. Please see the documentation on the solver methods")
81-
end
79+
#if !StochasticDiffEq.alg_compatible(prob, getalg(alg))
80+
# error("The algorithm is not compatible with the chosen noise type. Please see the documentation on the solver methods")
81+
#end
8282

8383
if haskey(kwargs, :initial_order)
8484
@warn "initial_order has been deprecated. Please specify order_discontinuity_t0 in the DDEProblem instead."
@@ -171,6 +171,41 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
171171
end
172172
end
173173

174+
#= TODO: Jump handling
175+
if typeof(_prob) <: JumpProblem && _prob.regular_jump !== nothing
176+
177+
if !isnothing(_prob.regular_jump.mark_dist) == nothing # https://github.com/JuliaDiffEq/DifferentialEquations.jl/issues/250
178+
error("Mark distributions are currently not supported in SimpleTauLeaping")
179+
end
180+
181+
jump_prototype = zeros(_prob.regular_jump.numjumps)
182+
c = _prob.regular_jump.c
183+
184+
if isinplace(_prob.regular_jump)
185+
rate_constants = zeros(_prob.regular_jump.numjumps)
186+
_prob.regular_jump.rate(rate_constants,u./u,prob.p,tspan[1])
187+
P = CompoundPoissonProcess!(_prob.regular_jump.rate,t,jump_prototype,
188+
computerates = !alg_control_rate(alg) || !adaptive,
189+
save_everystep=save_noise,
190+
rng = Xorshifts.Xoroshiro128Plus(_seed))
191+
alg_control_rate(alg) && adaptive && P.cache.rate(P.cache.currate,u,p,tspan[1])
192+
else
193+
rate_constants = _prob.regular_jump.rate(u./u,prob.p,tspan[1])
194+
P = CompoundPoissonProcess(_prob.regular_jump.rate,t,jump_prototype,
195+
save_everystep=save_noise,
196+
computerates = !alg_control_rate(alg) || !adaptive,
197+
rng = Xorshifts.Xoroshiro128Plus(_seed))
198+
alg_control_rate(alg) && adaptive && (P.cache.currate = P.cache.rate(u,p,tspan[1]))
199+
end
200+
201+
else
202+
=#
203+
jump_prototype = nothing
204+
c = nothing
205+
P = nothing
206+
rate_constants = nothing
207+
#end
208+
174209
# tstops_internal, saveat_internal, d_discontinuities_internal =
175210
# tstop_saveat_disc_handling(tstops, saveat, d_discontinuities, tspan) # TODO add delays to discontinuities
176211
# retrieve time stops, time points at which solutions is saved, and discontinuities
@@ -284,14 +319,14 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
284319

285320
# create a history function
286321
history = build_history_function(prob, alg, reltol_internal,
287-
rate_prototype, noise_rate_prototype, W, _seed, dense;
322+
rate_prototype, noise_rate_prototype, jump_prototype, W, _seed, dense;
288323
dt = dt, adaptive = adaptive,
289324
internalnorm = internalnorm)
290325
f_with_history, g_with_history = wrap_functions_and_history(f, g, history)
291326

292327
sde_integrator = history.integrator;
293328

294-
cache = StochasticDiffEq.alg_cache(getalg(alg), prob, u, W.dW, W.dZ, p, rate_prototype, noise_rate_prototype, uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits, uprev, f_with_history, t, dt, Val{isinplace(prob)})
329+
cache = StochasticDiffEq.alg_cache(getalg(alg), prob, u, W.dW, W.dZ, p, rate_prototype, noise_rate_prototype, jump_prototype, uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits, uprev, f_with_history, t, dt, Val{isinplace(prob)})
295330

296331
# id = StochasticDiffEq.LinearInterpolationData(timeseries,ts)
297332
id = StochasticDiffEq.LinearInterpolationData(sde_integrator.sol.u, sde_integrator.sol.t)
@@ -364,12 +399,19 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
364399
success_iter = 0
365400
q = tTypeNoUnits(1)
366401

367-
integrator = SDDEIntegrator{typeof(getalg(alg)),isinplace(prob),uType,uBottomEltype,tType,typeof(p),typeof(eigen_est),QT,uEltypeNoUnits,typeof(W),rateType,typeof(sol),typeof(cache),FType,GType,typeof(opts),typeof(noise),typeof(last_event_error),typeof(callback_cache),typeof(history),typeof(sde_integrator)}(f_with_history, g_with_history, noise, uprev, tprev,
402+
integrator = SDDEIntegrator{typeof(getalg(alg)),isinplace(prob),uType,
403+
uBottomEltype,tType,typeof(p),typeof(eigen_est),
404+
QT,uEltypeNoUnits,typeof(W),typeof(P),
405+
rateType,typeof(sol),typeof(cache),FType,GType,typeof(c),
406+
typeof(opts),typeof(noise),typeof(last_event_error),
407+
typeof(callback_cache),typeof(history),
408+
typeof(sde_integrator)}(f_with_history,
409+
g_with_history, c, noise, uprev, tprev,
368410
order_discontinuity_t0, tracked_discontinuities,
369411
t, u, p, tType(dt), tType(dt), tType(dt), dtcache, tspan[2], tdir,
370412
just_hit_tstop, isout, event_last_time, vector_event_last_time, last_event_error, accept_step,
371413
last_stepfail, force_stepfail, dtchangeable, u_modified, saveiter, getalg(alg), sol,
372-
cache, callback_cache, tType(dt), W,
414+
cache, callback_cache, tType(dt), W, P,
373415
opts, iter, success_iter, eigen_est, EEst, q, QT(qoldinit), q11, history, sde_integrator)
374416

375417
if initialize_integrator
@@ -387,7 +429,7 @@ function DiffEqBase.__init(prob::AbstractSDDEProblem,# TODO DiffEqBasee.Abstract
387429
integrator.sqdt = integrator.tdir * sqrt(abs(integrator.dt))
388430

389431
integrator.W.dt = integrator.dt
390-
DiffEqNoiseProcess.setup_next_step!(integrator.W)
432+
DiffEqNoiseProcess.setup_next_step!(integrator)
391433

392434
integrator
393435
end

src/utils.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ depends on the parameter settings of the numerical solver.
107107
"""
108108
function Base.sizehint!(sol::RODESolution, alg, tspan, tstops, saveat;
109109
save_everystep = isempty(saveat),
110-
adaptive = StochasticDiffEq.isadaptive(getalg(alg)),
111-
internalnorm = DiffEqBase.ODE_DEFAULT_NORM,
110+
adaptive = StochasticDiffEq.isadaptive(getalg(alg)),
111+
internalnorm = DiffEqBase.ODE_DEFAULT_NORM,
112112
dt = zero(eltype(tspan)))
113113
# obtain integration time
114114
t0 = first(tspan)
@@ -134,7 +134,7 @@ function Base.sizehint!(sol::RODESolution, alg, tspan, tstops, saveat;
134134
nothing
135135
end
136136

137-
function build_history_function(prob, alg, reltol, rate_prototype, noise_rate_prototype, W, _seed, dense;
137+
function build_history_function(prob, alg, reltol, rate_prototype, noise_rate_prototype, jump_prototype, W, _seed, dense;
138138
dt = zero(eltype(prob.tspan)),
139139
adaptive = StochasticDiffEq.isadaptive(getalg(alg)),
140140
calck = false,
@@ -172,7 +172,7 @@ function build_history_function(prob, alg, reltol, rate_prototype, noise_rate_pr
172172
save_start = true)
173173

174174
# # obtain cache (we alias uprev2 and uprev)
175-
sde_cache = StochasticDiffEq.alg_cache(getalg(alg),prob, sde_u, W.dW, W.dZ, p, rate_prototype,noise_rate_prototype, uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits, sde_uprev, f, t0, dt, Val{isinplace(prob)})
175+
sde_cache = StochasticDiffEq.alg_cache(getalg(alg),prob, sde_u, W.dW, W.dZ, p, rate_prototype, noise_rate_prototype, jump_prototype, uEltypeNoUnits, uBottomEltypeNoUnits, tTypeNoUnits, sde_uprev, f, t0, dt, Val{isinplace(prob)})
176176

177177
# build dense interpolation of history
178178
id = StochasticDiffEq.LinearInterpolationData(sde_timeseries,sde_ts)
@@ -253,4 +253,4 @@ function DiffEqBase.unwrap_cache(integrator::SDDEIntegrator, is_stiff)
253253
else
254254
return cache.caches[integrator.cache.current]
255255
end
256-
end
256+
end

0 commit comments

Comments
 (0)