Skip to content

Commit

Permalink
Merge pull request #1096 from prbzrg/clear-12
Browse files Browse the repository at this point in the history
Remove Deps:  `StochasticDiffEq` and `OrdinaryDiffEq`
  • Loading branch information
ChrisRackauckas authored Sep 2, 2024
2 parents c86f85f + 93dfba9 commit 6996fd5
Show file tree
Hide file tree
Showing 10 changed files with 45 additions and 36 deletions.
7 changes: 3 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ GPUArraysCore = "46192b85-c4d5-4398-a991-12ede77f4527"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae"
Markdown = "d6f4376e-aef5-505a-96c1-9c027394607a"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
PreallocationTools = "d236fae5-4411-538c-8e31-a6e3d9e00b46"
QuadGK = "1fd47b50-473d-5c70-9696-f719f8f3bcdc"
Expand All @@ -40,7 +39,6 @@ SparseDiffTools = "47a9eef4-7e08-11e9-0b38-333d64bd3804"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
StaticArraysCore = "1e83bf80-4336-4d27-bf5d-d5a4f845583c"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
SymbolicIndexingInterface = "2efcf032-c050-4f8e-a9bb-153293bab1f5"
Tracker = "9f7883ad-71c0-57eb-9f7f-b5c9e6d3789c"
TruncatedStacktraces = "781d530d-4396-4725-bb49-402e4bee1e77"
Expand Down Expand Up @@ -99,7 +97,7 @@ StaticArrays = "1.8.0"
StaticArraysCore = "1.4"
Statistics = "1.10"
SteadyStateDiffEq = "2.0.1"
StochasticDiffEq = "6.63.2"
StochasticDiffEq = "6.69"
SymbolicIndexingInterface = "0.3.26"
Test = "1.10"
Tracker = "0.2.30"
Expand All @@ -120,6 +118,7 @@ NLsolve = "2774e3e8-f4cf-5e23-947b-6d7e65073b56"
NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec"
Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba"
OptimizationOptimisers = "42dfb2eb-d2b4-4451-abcd-913932933ac1"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Expand All @@ -128,4 +127,4 @@ StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"]
test = ["AlgebraicMultigrid", "Aqua", "Calculus", "ComponentArrays", "DelayDiffEq", "Distributed", "Lux", "ModelingToolkit", "NLsolve", "NonlinearSolve", "Optimization", "OptimizationOptimisers", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "SparseArrays", "SteadyStateDiffEq", "StochasticDiffEq", "Test"]
1 change: 0 additions & 1 deletion src/SciMLSensitivity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ using Adapt
using LinearSolve
using Parameters: @unpack
import Accessors: @reset
using StochasticDiffEq
import DiffEqNoiseProcess
import RandomNumbers: Xorshifts
using Random
Expand Down
12 changes: 6 additions & 6 deletions src/adjoint_common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
paramjac_config = tape
end
elseif noiseterm &&
(!StochasticDiffEq.is_diagonal_noise(prob) || isnoisemixing(sensealg))
(!SciMLBase.is_diagonal_noise(prob) || isnoisemixing(sensealg))
tape = nothing
paramjac_config = tape
else
Expand Down Expand Up @@ -256,7 +256,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
if isinplace
for i in 1:m
function noisetape(indx)
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
ReverseDiff.GradientTape((y, _p, [_t])) do u, p, t
du1 = p !== nothing && p !== DiffEqBase.NullParameters() ?
similar(p, size(u)) : similar(u)
Expand All @@ -283,7 +283,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
else
for i in 1:m
function noisetapeoop(indx)
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
ReverseDiff.GradientTape((y, _p, [_t])) do u, p, t
unwrappedf(u, p, first(t))[indx]
end
Expand All @@ -303,7 +303,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
end
elseif autojacvec isa Bool
if isinplace
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
pf = DiffEqBase.ParamJacobianWrapper(unwrappedf, _t, y)
if isnoisemixing(sensealg)
uf = DiffEqBase.UJacobianWrapper(unwrappedf, _t, p)
Expand All @@ -321,7 +321,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
paramjac_noise_config = build_param_jac_config(
sensealg, pf, y, SciMLStructures.replace(Tunable(), p, tunables))
else
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
pf = ParamGradientWrapper(unwrappedf, _t, y)
if isnoisemixing(sensealg)
uf = DiffEqBase.UDerivativeWrapper(unwrappedf, _t, p)
Expand All @@ -333,7 +333,7 @@ function adjointdiffcache(g::G, sensealg, discrete, sol, dgdu::DG1, dgdp::DG2, f
paramjac_noise_config = nothing
jac_noise_config = nothing
end
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
pJ = similar(u0, numindvar, numparams)
if isnoisemixing(sensealg)
J = similar(u0, numindvar, numindvar)
Expand Down
11 changes: 6 additions & 5 deletions src/backsolve_adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function (S::ODEBacksolveSensitivityFunction)(du, u, p, t)
if S.noiseterm
if length(u) == length(du)
vecjacobian!(dλ, y, λ, p, t, S, dgrad = dgrad, dy = dy)
elseif length(u) != length(du) && StochasticDiffEq.is_diagonal_noise(prob) &&
elseif length(u) != length(du) && SciMLBase.is_diagonal_noise(prob) &&
!isnoisemixing(S.sensealg)
vecjacobian!(dλ, y, λ, p, t, S, dy = dy)
jacNoise!(λ, y, p, t, S, dgrad = dgrad)
Expand Down Expand Up @@ -82,7 +82,7 @@ function split_states(du, u, t, S::ODEBacksolveSensitivityFunction; update = tru
dgrad = @view du[(idx + 1):(end - idx)]
dy = @view du[(end - idx + 1):end]

elseif length(u) != length(du) && StochasticDiffEq.is_diagonal_noise(prob) &&
elseif length(u) != length(du) && SciMLBase.is_diagonal_noise(prob) &&
!isnoisemixing(S.sensealg)
# Diffusion term, diagonal noise, length(du) = u*m
idx1 = [length(u) * (i - 1) + i for i in 1:idx] # for diagonal indices of [1:idx,1:idx]
Expand All @@ -92,7 +92,7 @@ function split_states(du, u, t, S::ODEBacksolveSensitivityFunction; update = tru
dgrad = @view du[(idx + 1):(end - idx), 1:idx]
dy = @view du[idx2]

elseif length(u) != length(du) && StochasticDiffEq.is_diagonal_noise(prob) &&
elseif length(u) != length(du) && SciMLBase.is_diagonal_noise(prob) &&
isnoisemixing(S.sensealg)
# Diffusion term, diagonal noise, (as above but can handle mixing noise terms)
idx2 = [(length(u) + 1) * i - idx for i in 1:idx] # for diagonal indices of [end-idx+1:end,1:idx]
Expand Down Expand Up @@ -288,7 +288,8 @@ end
len = length(u0) + numparams
λ = one(eltype(u0)) .* similar(tunables, len)

if StochasticDiffEq.alg_interpretation(sol.alg) == :Stratonovich
if SciMLBase.alg_interpretation(sol.alg) ==
SciMLBase.AlgorithmInterpretation.Stratonovich
sense_drift = ODEBacksolveSensitivityFunction(g, sensealg, discrete, sol,
dgdu_continuous, dgdp_continuous,
sol.prob.f, alg)
Expand Down Expand Up @@ -344,7 +345,7 @@ end
_sol = deepcopy(sol)
backwardnoise = reverse(_sol.W)

if StochasticDiffEq.is_diagonal_noise(sol.prob) && sol.W.u[end] isa Number
if SciMLBase.is_diagonal_noise(sol.prob) && sol.W.u[end] isa Number
# scalar noise case
noise_matrix = nothing
else
Expand Down
14 changes: 7 additions & 7 deletions src/derivative_wrappers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::Bool, dgrad, dλ,
end
end

if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
pJt = transpose(λ) .* transpose(pJ)
recursive_copyto!(dgrad, pJt)
else
Expand All @@ -796,7 +796,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::Bool, dgrad, dλ,
end

if!== nothing &&
(isnoisemixing(sensealg) || !StochasticDiffEq.is_diagonal_noise(prob))
(isnoisemixing(sensealg) || !SciMLBase.is_diagonal_noise(prob))
@unpack J, uf, f_cache, jac_noise_config = S.diffcache
if dy !== nothing
if inplace_sensitivity(S)
Expand All @@ -813,7 +813,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::Bool, dgrad, dλ,
if dy !== nothing
ForwardDiff.jacobian!(J, uf, dy, y)
else
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
dy = similar(y)
else
dy = similar(prob.noise_rate_prototype)
Expand All @@ -832,7 +832,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::Bool, dgrad, dλ,
# jacobian!(J, uf, y, nothing, sensealg, nothing)
end

if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
Jt = transpose(λ) .* transpose(J)
recursive_copyto!(dλ, Jt)
else
Expand Down Expand Up @@ -866,7 +866,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::ReverseDiffVJP, dgrad, dλ,
ReverseDiff.value!(tp, p)
ReverseDiff.value!(tt, [t])
ReverseDiff.forward_pass!(tapei)
if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
ReverseDiff.increment_deriv!(output, λ[i])
else
ReverseDiff.increment_deriv!(output, λ)
Expand All @@ -881,7 +881,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::ReverseDiffVJP, dgrad, dλ,
end
ReverseDiff.pull_value!(output)

if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
!== nothing && (dλ[:, i] .= vec(ReverseDiff.deriv(tu)))
dy !== nothing && (dy[i] = ReverseDiff.value(output))
else
Expand Down Expand Up @@ -909,7 +909,7 @@ function _jacNoise!(λ, y, p, t, S::TS, isnoise::ZygoteVJP, dgrad, dλ,
noise_rate_prototype = prob.noise_rate_prototype
m = noise_rate_prototype === nothing ? length(y) : size(noise_rate_prototype)[2]

if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
if VERSION < v"1.9" # pre "stack" function
for i in 1:m
if inplace_sensitivity(S)
Expand Down
6 changes: 3 additions & 3 deletions src/interpolating_adjoint.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function (S::ODEInterpolatingAdjointSensitivityFunction)(du, u, p, t)
if S.noiseterm
if length(u) == length(du)
vecjacobian!(dλ, y, λ, p, t, S, dgrad = dgrad)
elseif length(u) != length(du) && StochasticDiffEq.is_diagonal_noise(prob) &&
elseif length(u) != length(du) && SciMLBase.is_diagonal_noise(prob) &&
!isnoisemixing(S.sensealg)
vecjacobian!(dλ, y, λ, p, t, S)
jacNoise!(λ, y, p, t, S, dgrad = dgrad)
Expand Down Expand Up @@ -245,7 +245,7 @@ function split_states(du, u, t, S::TS;
= @view du[1:idx]
dgrad = @view du[(idx + 1):end]

elseif length(u) != length(du) && StochasticDiffEq.is_diagonal_noise(prob) &&
elseif length(u) != length(du) && SciMLBase.is_diagonal_noise(prob) &&
!isnoisemixing(S.sensealg)
idx1 = [length(u) * (i - 1) + i for i in 1:idx] # for diagonal indices of [1:idx,1:idx]

Expand Down Expand Up @@ -519,7 +519,7 @@ end
_sol = deepcopy(sol)
backwardnoise = reverse(_sol.W)

if StochasticDiffEq.is_diagonal_noise(sol.prob) && sol.W.u[end] isa Number
if SciMLBase.is_diagonal_noise(sol.prob) && sol.W.u[end] isa Number
# scalar noise case
noise_matrix = nothing
else
Expand Down
2 changes: 1 addition & 1 deletion src/sde_tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ end
function StochasticTransformedFunction(sol, f, g, corfunc_analytical = nothing)
@unpack prob = sol

if StochasticDiffEq.is_diagonal_noise(prob)
if SciMLBase.is_diagonal_noise(prob)
gtmp = copy(sol.u[end])
else
gtmp = similar(prob.p, size(prob.noise_rate_prototype))
Expand Down
3 changes: 2 additions & 1 deletion test/sde_scalar_ito.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ probStrat = SDEProblem(SDEFunction(fStrat, σ),
)

# solve Strat sense
solStrat = solve(probStrat, RKMil(interpretation = :Stratonovich), dt = dt,
solStrat = solve(probStrat,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich), dt = dt,
adaptive = false, save_noise = true, saveat = dt)

# check that forward solution agrees
Expand Down
21 changes: 15 additions & 6 deletions test/sde_stratonovich.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ p2 = [1.01, 0.87]
Random.seed!(seed)
tmp_prob = remake(prob_oop_sde, u0 = eltype(p).(prob_oop_sde.u0), p = p,
tspan = eltype(p).(prob_oop_sde.tspan))
sol = solve(tmp_prob, RKMil(interpretation = :Stratonovich), dt = tend / 10000,
sol = solve(tmp_prob,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich),
dt = tend / 10000,
adaptive = false, sensealg = DiffEqBase.SensitivityADPassThrough(),
saveat = tarray)
A = convert(Array, sol)
Expand All @@ -109,7 +111,8 @@ end

Random.seed!(seed)
prob_oop_sde2 = SDEProblem(f_oop_linear, σ_oop_linear, u₀, trange, p2)
sol_oop_sde2 = solve(prob_oop_sde2, RKMil(interpretation = :Stratonovich), dt = dt1,
sol_oop_sde2 = solve(prob_oop_sde2,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich), dt = dt1,
adaptive = false, save_noise = true)

res_sde_u02, res_sde_p2 = adjoint_sensitivities(sol_oop_sde2, EulerHeun(), t = tarray,
Expand Down Expand Up @@ -158,7 +161,9 @@ end
tmp_prob = remake(prob_oop_sde2, u0 = eltype(p).(prob_oop_sde2.u0), p = p,
tspan = eltype(p).(prob_oop_sde2.tspan) #,abstol=abstol, reltol=reltol
)
sol = solve(tmp_prob, RKMil(interpretation = :Stratonovich), dt = dt1,
sol = solve(tmp_prob,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich),
dt = dt1,
adaptive = false, sensealg = DiffEqBase.SensitivityADPassThrough(),
saveat = tarray)
A = convert(Array, sol)
Expand Down Expand Up @@ -326,7 +331,9 @@ end
function GSDE3(u)
Random.seed!(seed)
tmp_prob = remake(prob_oop_sde2, u0 = u)
sol = solve(tmp_prob, RKMil(interpretation = :Stratonovich), dt = dt1,
sol = solve(tmp_prob,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich),
dt = dt1,
adaptive = false, saveat = tarray)
A = convert(Array, sol)
res = g(A, nothing, nothing)
Expand Down Expand Up @@ -545,7 +552,9 @@ end
Random.seed!(seed)
tmp_prob = remake(prob_oop_sde, u0 = eltype(p).(prob_oop_sde.u0), p = p,
tspan = eltype(p).(prob_oop_sde.tspan))
sol = solve(tmp_prob, RKMil(interpretation = :Stratonovich), dt = 5e-4,
sol = solve(tmp_prob,
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich),
dt = 5e-4,
adaptive = false, sensealg = DiffEqBase.SensitivityADPassThrough(),
saveat = tarray)
A = convert(Array, sol)
Expand All @@ -556,7 +565,7 @@ end
Random.seed!(seed)
res_sde_trackeru0, res_sde_trackerp = Zygote.gradient(
(u0, p) -> sum(Array(solve(prob_oop_sde,
RKMil(interpretation = :Stratonovich),
RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich),
dt = 5e-4,
adaptive = false,
u0 = u0,
Expand Down
4 changes: 2 additions & 2 deletions test/sde_transformation_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ prob_strat = SDEProblem{false}(
tspan,
p)
Random.seed!(seed)
sol_strat = solve(prob_strat, RKMil(interpretation = :Stratonovich), adaptive = false,
sol_strat = solve(prob_strat, RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich), adaptive = false,
dt = 0.0001, save_noise = true)
prob_strat1 = SDEProblem{false}(
SDEFunction((u, p, t) -> transformed_function(u, p, t) .+
Expand All @@ -56,7 +56,7 @@ prob_strat1 = SDEProblem{false}(
tspan,
p)
Random.seed!(seed)
sol_strat1 = solve(prob_strat1, RKMil(interpretation = :Stratonovich), adaptive = false,
sol_strat1 = solve(prob_strat1, RKMil(interpretation = SciMLBase.AlgorithmInterpretation.Stratonovich), adaptive = false,
dt = 0.0001, save_noise = true)

# Test if we recover Ito solution in Stratonovich sense
Expand Down

0 comments on commit 6996fd5

Please sign in to comment.