Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ JumpProcessesOrdinaryDiffEqCoreExt = "OrdinaryDiffEqCore"
[compat]
ADTypes = "1.22.0"
Adapt = "4.6.0"
Aqua = "0.8.16"
ArrayInterface = "7.25.0"
DataStructures = "0.19.5, 0.19"
DiffEqBase = "7.5.5, 7"
DiffEqCallbacks = "4.17.0"
DocStringExtensions = "0.9.5"
ExplicitImports = "1"
FastBroadcast = "1.3.2, 1"
FunctionWrappers = "1.1.3"
Graphs = "1.14.0"
Expand All @@ -55,6 +53,7 @@ RecursiveArrayTools = "4.3.0, 4"
Reexport = "1.2.2"
SafeTestsets = "0.1"
SciMLBase = "3.18.0, 3.1"
SciMLTesting = "1.6"
StableRNGs = "1"
StaticArrays = "1.9.18"
Statistics = "1"
Expand All @@ -65,19 +64,18 @@ julia = "1.10"

[extras]
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
ExplicitImports = "7d51a73a-1435-4ff3-83d9-f097790105c7"
FastBroadcast = "7034ab61-46d4-4ed7-9d0f-46aef9175898"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
OrdinaryDiffEqFunctionMap = "d3585ca7-f5d3-4ba6-8057-292ed1abd90f"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["ADTypes", "Aqua", "ExplicitImports", "FastBroadcast", "LinearAlgebra", "LinearSolve", "OrdinaryDiffEq", "OrdinaryDiffEqFunctionMap", "Pkg", "SafeTestsets", "StableRNGs", "Statistics", "StochasticDiffEq", "Test"]
test = ["ADTypes", "FastBroadcast", "LinearAlgebra", "LinearSolve", "OrdinaryDiffEq", "OrdinaryDiffEqFunctionMap", "Pkg", "SafeTestsets", "SciMLTesting", "StableRNGs", "Statistics", "StochasticDiffEq", "Test"]
5 changes: 3 additions & 2 deletions ext/JumpProcessesOrdinaryDiffEqCoreExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module JumpProcessesOrdinaryDiffEqCoreExt

using JumpProcesses
import DiffEqBase
import SciMLBase
import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, DAEAlgorithm,
StochasticDiffEqAlgorithm, StochasticDiffEqRODEAlgorithm

Expand All @@ -14,8 +15,8 @@ import OrdinaryDiffEqCore: OrdinaryDiffEqAlgorithm, DAEAlgorithm,
# This method resolves the ambiguity by being more specific in the problem type
# (AbstractJumpProblem vs Union{..., AbstractJumpProblem, ...}) while matching
# the exact algorithm union from OrdinaryDiffEqCore.
function DiffEqBase.__init(
_jump_prob::DiffEqBase.AbstractJumpProblem{P},
function SciMLBase.__init(
_jump_prob::SciMLBase.AbstractJumpProblem{P},
alg::Union{OrdinaryDiffEqAlgorithm, DAEAlgorithm,
StochasticDiffEqAlgorithm, StochasticDiffEqRODEAlgorithm};
merge_callbacks = true, kwargs...) where {P}
Expand Down
14 changes: 7 additions & 7 deletions src/SSA_stepper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ see the
[tutorial](https://docs.sciml.ai/JumpProcesses/stable/tutorials/discrete_stochastic_example/)
for details.
"""
struct SSAStepper <: DiffEqBase.AbstractDEAlgorithm end
struct SSAStepper <: SciMLBase.AbstractDEAlgorithm end
SciMLBase.allows_late_binding_tstops(::SSAStepper) = true

"""
Expand Down Expand Up @@ -149,7 +149,7 @@ end
end
end

function DiffEqBase.__solve(jump_prob::JumpProblem, alg::SSAStepper; kwargs...)
function SciMLBase.__solve(jump_prob::JumpProblem, alg::SSAStepper; kwargs...)
# init will handle kwargs merging via init_call
integrator = init(jump_prob, alg; kwargs...)
solve!(integrator)
Expand Down Expand Up @@ -194,7 +194,7 @@ function DiffEqBase.solve!(integrator::SSAIntegrator)
end

if integrator.sol.retcode === ReturnCode.Default
integrator.sol = DiffEqBase.solution_new_retcode(integrator.sol, ReturnCode.Success)
integrator.sol = SciMLBase.solution_new_retcode(integrator.sol, ReturnCode.Success)
end
end

Expand Down Expand Up @@ -225,7 +225,7 @@ function check_continuous_callback_error(callback)
return nothing
end

function DiffEqBase.__init(jump_prob::JumpProblem,
function SciMLBase.__init(jump_prob::JumpProblem,
alg::SSAStepper;
save_start = true,
save_end = true,
Expand Down Expand Up @@ -276,10 +276,10 @@ function DiffEqBase.__init(jump_prob::JumpProblem,
end
save_everystep = any(cb.save_positions)

sol = DiffEqBase.build_solution(prob, alg, t, u, dense = save_everystep,
sol = SciMLBase.build_solution(prob, alg, t, u, dense = save_everystep,
calculate_error = false,
stats = DiffEqBase.Stats(0),
interp = DiffEqBase.ConstantInterpolation(t, u))
interp = SciMLBase.ConstantInterpolation(t, u))

_saveat = (saveat isa Number) ? (prob.tspan[1]:saveat:prob.tspan[2]) : saveat
if _saveat !== nothing && !isempty(_saveat) && _saveat[1] == prob.tspan[1]
Expand Down Expand Up @@ -465,7 +465,7 @@ end

function DiffEqBase.terminate!(integrator::SSAIntegrator, retcode = ReturnCode.Terminated)
integrator.keep_stepping = false
integrator.sol = DiffEqBase.solution_new_retcode(integrator.sol, retcode)
integrator.sol = SciMLBase.solution_new_retcode(integrator.sol, retcode)
nothing
end

Expand Down
36 changes: 18 additions & 18 deletions src/coupling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ David F. Anderson, Masanori Koyama; An asymptotic relationship between coupling
methods for stochastically modeled population processes. IMA J Numer Anal 2015;
35 (4): 1757-1778. doi: 10.1093/imanum/dru044
"""
function SplitCoupledJumpProblem(prob::DiffEqBase.AbstractJumpProblem,
prob_control::DiffEqBase.AbstractJumpProblem,
function SplitCoupledJumpProblem(prob::SciMLBase.AbstractJumpProblem,
prob_control::SciMLBase.AbstractJumpProblem,
aggregator::AbstractAggregatorAlgorithm,
coupling_map::Vector{Tuple{Int, Int}}; kwargs...)
JumpProblem(cat_problems(prob.prob, prob_control.prob), aggregator,
Expand All @@ -17,8 +17,8 @@ function cat_problems(prob::DiscreteProblem, prob_control::DiscreteProblem)
DiscreteProblem(u0_coupled, prob.tspan, prob.p)
end

function cat_problems(prob::DiffEqBase.AbstractODEProblem,
prob_control::DiffEqBase.AbstractODEProblem)
function cat_problems(prob::SciMLBase.AbstractODEProblem,
prob_control::SciMLBase.AbstractODEProblem)
l = length(prob.u0) # add l_c = length(prob_control.u0)

_f = SciMLBase.unwrapped_f(prob.f)
Expand All @@ -32,9 +32,9 @@ function cat_problems(prob::DiffEqBase.AbstractODEProblem,
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
end

function cat_problems(prob::DiscreteProblem, prob_control::DiffEqBase.AbstractODEProblem)
function cat_problems(prob::DiscreteProblem, prob_control::SciMLBase.AbstractODEProblem)
l = length(prob.u0) # add l_c = length(prob_control.u0)
if !(prob.f isa typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
if !(prob.f isa typeof(SciMLBase.DISCRETE_INPLACE_DEFAULT))
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
end

Expand All @@ -49,8 +49,8 @@ function cat_problems(prob::DiscreteProblem, prob_control::DiffEqBase.AbstractOD
ODEProblem(new_f, u0_coupled, prob.tspan, prob.p)
end

function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
prob_control::DiffEqBase.AbstractSDEProblem)
function cat_problems(prob::SciMLBase.AbstractSDEProblem,
prob_control::SciMLBase.AbstractSDEProblem)
l = length(prob.u0)
new_f = function (du, u, p, t)
prob.f(@view(du[1:l]), u.u, p, t)
Expand All @@ -64,8 +64,8 @@ function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
SDEProblem(new_f, new_g, u0_coupled, prob.tspan, prob.p)
end

function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
prob_control::DiffEqBase.AbstractODEProblem)
function cat_problems(prob::SciMLBase.AbstractSDEProblem,
prob_control::SciMLBase.AbstractODEProblem)
l = length(prob.u0)

_f = SciMLBase.unwrapped_f(prob.f)
Expand All @@ -85,9 +85,9 @@ function cat_problems(prob::DiffEqBase.AbstractSDEProblem,
SDEProblem(new_f, new_g, u0_coupled, prob.tspan, prob.p)
end

function cat_problems(prob::DiffEqBase.AbstractSDEProblem, prob_control::DiscreteProblem)
function cat_problems(prob::SciMLBase.AbstractSDEProblem, prob_control::DiscreteProblem)
l = length(prob.u0)
if !(prob_control.f isa typeof(DiffEqBase.DISCRETE_INPLACE_DEFAULT))
if !(prob_control.f isa typeof(SciMLBase.DISCRETE_INPLACE_DEFAULT))
@warn("Coupling to DiscreteProblem with nontrivial f. Note that, unless scale_by_time=true, the meaning of f will change when using an ODE/SDE/DDE/DAE solver.")
end
new_f = function (du, u, p, t)
Expand All @@ -104,20 +104,20 @@ function cat_problems(prob::DiffEqBase.AbstractSDEProblem, prob_control::Discret
SDEProblem(new_f, new_g, u0_coupled, prob.tspan)
end

function cat_problems(prob_control::DiffEqBase.AbstractODEProblem, prob::DiscreteProblem)
function cat_problems(prob_control::SciMLBase.AbstractODEProblem, prob::DiscreteProblem)
cat_problems(prob, prob_control)
end
function cat_problems(prob_control::DiscreteProblem, prob::DiffEqBase.AbstractSDEProblem)
function cat_problems(prob_control::DiscreteProblem, prob::SciMLBase.AbstractSDEProblem)
cat_problems(prob, prob_control)
end
function cat_problems(prob_control::DiffEqBase.AbstractODEProblem,
prob::DiffEqBase.AbstractSDEProblem)
function cat_problems(prob_control::SciMLBase.AbstractODEProblem,
prob::SciMLBase.AbstractSDEProblem)
cat_problems(prob, prob_control)
end

# this only depends on the jumps in prob, not prob.prob
function build_split_jumps(prob::DiffEqBase.AbstractJumpProblem,
prob_control::DiffEqBase.AbstractJumpProblem,
function build_split_jumps(prob::SciMLBase.AbstractJumpProblem,
prob_control::SciMLBase.AbstractJumpProblem,
coupling_map::Vector{Tuple{Int, Int}})
num_jumps = length(prob.discrete_jump_aggregation.rates)
num_jumps_control = length(prob_control.discrete_jump_aggregation.rates)
Expand Down
10 changes: 5 additions & 5 deletions src/problem.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function isinplace_jump(p, rj)
if p isa DiscreteProblem && p.f === DiffEqBase.DISCRETE_INPLACE_DEFAULT &&
if p isa DiscreteProblem && p.f === SciMLBase.DISCRETE_INPLACE_DEFAULT &&
rj !== nothing
# Just a default discrete problem f, so don't use it for iip
DiffEqBase.isinplace(rj)
Expand Down Expand Up @@ -71,7 +71,7 @@ the DifferentialEquations.jl [docs](https://docs.sciml.ai/JumpProcesses/stable/)
examples and commonly asked questions.
"""
mutable struct JumpProblem{iip, P, A, C, J <: Union{Nothing, AbstractJumpAggregator}, J1,
J2, J3, J4, R, K} <: DiffEqBase.AbstractJumpProblem{P, J}
J2, J3, J4, R, K} <: SciMLBase.AbstractJumpProblem{P, J}
"""The type of problem to couple the jumps to. For a pure jump process use `DiscreteProblem`, to couple to ODEs, `ODEProblem`, etc."""
prob::P
"""The aggregator algorithm that determines the next jump times and types for `ConstantRateJump`s and `MassActionJump`s. Examples include `Direct`."""
Expand Down Expand Up @@ -111,7 +111,7 @@ function remake_extended_u0(prob, newu0, rng)
ExtendedJumpArray(newu0, jump_u)
end

Base.@pure remaker_of(prob::T) where {T <: JumpProblem} = DiffEqBase.parameterless_type(T)
Base.@pure remaker_of(prob::T) where {T <: JumpProblem} = SciMLBase.parameterless_type(T)
function DiffEqBase.remake(jprob::JumpProblem; u0 = missing, p = missing,
interpret_symbolicmap = true, use_defaults = false, kwargs...)
T = remaker_of(jprob)
Expand Down Expand Up @@ -240,7 +240,7 @@ make_kwarg(; kwargs...) = kwargs

function JumpProblem(prob, aggregator::AbstractAggregatorAlgorithm, jumps::JumpSet;
vr_aggregator::VariableRateAggregator = VR_FRM(),
save_positions = prob isa DiffEqBase.AbstractDiscreteProblem ?
save_positions = prob isa SciMLBase.AbstractDiscreteProblem ?
(false, true) : (true, true),
rng = DEFAULT_RNG, scale_rates = true, useiszero = true,
spatial_system = nothing, hopping_constants = nothing,
Expand Down Expand Up @@ -319,7 +319,7 @@ end

# Special dispatch for PureLeaping aggregator - bypasses all aggregation
function JumpProblem(prob, aggregator::PureLeaping, jumps::JumpSet;
save_positions = prob isa DiffEqBase.AbstractDiscreteProblem ?
save_positions = prob isa SciMLBase.AbstractDiscreteProblem ?
(false, true) : (true, true),
rng = DEFAULT_RNG, scale_rates = true, useiszero = true,
spatial_system = nothing, hopping_constants = nothing,
Expand Down
12 changes: 6 additions & 6 deletions src/simple_regular_solve.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
struct SimpleTauLeaping <: DiffEqBase.AbstractDEAlgorithm end
struct SimpleTauLeaping <: SciMLBase.AbstractDEAlgorithm end

struct SimpleExplicitTauLeaping{T <: AbstractFloat} <: DiffEqBase.AbstractDEAlgorithm
struct SimpleExplicitTauLeaping{T <: AbstractFloat} <: SciMLBase.AbstractDEAlgorithm
epsilon::T # Error control parameter
end

Expand Down Expand Up @@ -142,9 +142,9 @@ function DiffEqBase.solve(jump_prob::JumpProblem, alg::SimpleTauLeaping;
push!(tsave, tspan[2])
end

sol = DiffEqBase.build_solution(prob, alg, tsave, usave,
sol = SciMLBase.build_solution(prob, alg, tsave, usave,
calculate_error = false,
interp = DiffEqBase.ConstantInterpolation(tsave, usave))
interp = SciMLBase.ConstantInterpolation(tsave, usave))
end

# Compute the highest order of reaction (HOR) for each reaction j, as per Cao et al. (2006), Section IV.
Expand Down Expand Up @@ -399,9 +399,9 @@ function DiffEqBase.solve(jump_prob::JumpProblem, alg::SimpleExplicitTauLeaping;
dtmin, saveat_times, usave, tsave, du, counts, rate_cache, rate_effective, maj,
save_end)

sol = DiffEqBase.build_solution(prob, alg, tsave, usave,
sol = SciMLBase.build_solution(prob, alg, tsave, usave,
calculate_error = false,
interp = DiffEqBase.ConstantInterpolation(tsave, usave))
interp = SciMLBase.ConstantInterpolation(tsave, usave))
return sol
end

Expand Down
20 changes: 10 additions & 10 deletions src/solve.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function DiffEqBase.__solve(jump_prob::DiffEqBase.AbstractJumpProblem{P},
alg::DiffEqBase.AbstractDEAlgorithm;
function SciMLBase.__solve(jump_prob::SciMLBase.AbstractJumpProblem{P},
alg::SciMLBase.AbstractDEAlgorithm;
merge_callbacks = true, kwargs...) where {P}
# Merge jump_prob.kwargs with passed kwargs
kwargs = DiffEqBase.merge_problem_kwargs(jump_prob; merge_callbacks, kwargs...)
Expand All @@ -10,7 +10,7 @@ function DiffEqBase.__solve(jump_prob::DiffEqBase.AbstractJumpProblem{P},
end

#Ambiguity Fix
function DiffEqBase.__solve(jump_prob::DiffEqBase.AbstractJumpProblem{P},
function SciMLBase.__solve(jump_prob::SciMLBase.AbstractJumpProblem{P},
alg::Union{SciMLBase.AbstractRODEAlgorithm, SciMLBase.AbstractSDEAlgorithm};
merge_callbacks = true, kwargs...) where {P}
# Merge jump_prob.kwargs with passed kwargs
Expand All @@ -23,24 +23,24 @@ end

# if passed a JumpProblem over a DiscreteProblem, and no aggregator is selected use
# SSAStepper
function DiffEqBase.__solve(jump_prob::DiffEqBase.AbstractJumpProblem{P};
function SciMLBase.__solve(jump_prob::SciMLBase.AbstractJumpProblem{P};
kwargs...) where {P <: DiscreteProblem}
DiffEqBase.__solve(jump_prob, SSAStepper(); kwargs...)
SciMLBase.__solve(jump_prob, SSAStepper(); kwargs...)
end

function DiffEqBase.__solve(jump_prob::DiffEqBase.AbstractJumpProblem; kwargs...)
function SciMLBase.__solve(jump_prob::SciMLBase.AbstractJumpProblem; kwargs...)
error("Auto-solver selection is currently only implemented for JumpProblems defined over DiscreteProblems. Please explicitly specify a solver algorithm in calling solve.")
end

function DiffEqBase.__init(_jump_prob::DiffEqBase.AbstractJumpProblem{P},
alg::DiffEqBase.AbstractDEAlgorithm; merge_callbacks = true, kwargs...) where {P}
function SciMLBase.__init(_jump_prob::SciMLBase.AbstractJumpProblem{P},
alg::SciMLBase.AbstractDEAlgorithm; merge_callbacks = true, kwargs...) where {P}
# Merge jump_prob.kwargs with passed kwargs
kwargs = DiffEqBase.merge_problem_kwargs(_jump_prob; merge_callbacks, kwargs...)

__jump_init(_jump_prob, alg; kwargs...)
end

function __jump_init(_jump_prob::DiffEqBase.AbstractJumpProblem{P}, alg;
function __jump_init(_jump_prob::SciMLBase.AbstractJumpProblem{P}, alg;
callback = nothing, seed = nothing,
alias_jump = Threads.threadid() == 1,
kwargs...) where {P}
Expand All @@ -52,7 +52,7 @@ function __jump_init(_jump_prob::DiffEqBase.AbstractJumpProblem{P}, alg;
end

# DDEProblems do not have a recompile_flag argument
if jump_prob.prob isa DiffEqBase.AbstractDDEProblem
if jump_prob.prob isa SciMLBase.AbstractDDEProblem
# callback comes after jump consistent with SSAStepper
integrator = init(jump_prob.prob, alg;
callback = CallbackSet(jump_prob.jump_callback, callback),
Expand Down
10 changes: 5 additions & 5 deletions src/variable_rate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ function extend_u0(prob, Njumps, rng)
return u0
end

function extend_problem(prob::DiffEqBase.AbstractDiscreteProblem, jumps; rng = DEFAULT_RNG)
function extend_problem(prob::SciMLBase.AbstractDiscreteProblem, jumps; rng = DEFAULT_RNG)
error("General `VariableRateJump`s require a continuous problem, like an ODE/SDE/DDE/DAE problem. To use a `DiscreteProblem` bounded `VariableRateJump`s must be used. See the JumpProcesses docs.")
end

function extend_problem(prob::DiffEqBase.AbstractODEProblem, jumps; rng = DEFAULT_RNG)
function extend_problem(prob::SciMLBase.AbstractODEProblem, jumps; rng = DEFAULT_RNG)
_f = SciMLBase.unwrapped_f(prob.f)

if isinplace(prob)
Expand All @@ -103,7 +103,7 @@ function extend_problem(prob::DiffEqBase.AbstractODEProblem, jumps; rng = DEFAUL
remake(prob; f, u0)
end

function extend_problem(prob::DiffEqBase.AbstractSDEProblem, jumps; rng = DEFAULT_RNG)
function extend_problem(prob::SciMLBase.AbstractSDEProblem, jumps; rng = DEFAULT_RNG)
_f = SciMLBase.unwrapped_f(prob.f)

if isinplace(prob)
Expand Down Expand Up @@ -139,7 +139,7 @@ function extend_problem(prob::DiffEqBase.AbstractSDEProblem, jumps; rng = DEFAUL
remake(prob; f, g = jump_g, u0)
end

function extend_problem(prob::DiffEqBase.AbstractDDEProblem, jumps; rng = DEFAULT_RNG)
function extend_problem(prob::SciMLBase.AbstractDDEProblem, jumps; rng = DEFAULT_RNG)
_f = SciMLBase.unwrapped_f(prob.f)

if isinplace(prob)
Expand All @@ -166,7 +166,7 @@ function extend_problem(prob::DiffEqBase.AbstractDDEProblem, jumps; rng = DEFAUL
end

# Not sure if the DAE one is correct: Should be a residual of sorts
function extend_problem(prob::DiffEqBase.AbstractDAEProblem, jumps; rng = DEFAULT_RNG)
function extend_problem(prob::SciMLBase.AbstractDAEProblem, jumps; rng = DEFAULT_RNG)
_f = SciMLBase.unwrapped_f(prob.f)

if isinplace(prob)
Expand Down
Loading
Loading