Skip to content

Commit 77bf33d

Browse files
fix utility tests
1 parent cf5a126 commit 77bf33d

File tree

3 files changed

+24
-32
lines changed

3 files changed

+24
-32
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ FiniteDiff = "2"
4141
ForwardDiff = "0.10.3"
4242
MuladdMacro = "0.2.1"
4343
NLsolve = "4"
44-
OrdinaryDiffEq = "6.2"
44+
OrdinaryDiffEq = "6.4"
4545
RandomNumbers = "1.5.3"
4646
RecursiveArrayTools = "2"
4747
Reexport = "0.2, 1.0"

src/algorithms.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ struct ImplicitEM{CS,AD,F,F2,P,FDT,ST,CJ,T2,Controller} <: StochasticDiffEqNewto
635635
symplectic::Bool
636636
end
637637
ImplicitEM(;chunk_size=0,autodiff=true,diff_type=Val{:central},
638-
standardtag = Val{true}(),concrete_jac = Val{true}(),
638+
standardtag = Val{true}(),concrete_jac = nothing,
639639
precs = OrdinaryDiffEq.DEFAULT_PRECS,
640640
linsolve=nothing,nlsolve=NLNewton(),
641641
extrapolant=:constant,
@@ -670,7 +670,7 @@ struct ImplicitEulerHeun{CS,AD,F,P,FDT,ST,CJ,N,T2,Controller} <: StochasticDiffE
670670
symplectic::Bool
671671
end
672672
ImplicitEulerHeun(;chunk_size=0,autodiff=true,diff_type=Val{:central},
673-
standardtag = Val{true}(),concrete_jac = Val{true}(),
673+
standardtag = Val{true}(),concrete_jac = nothing,
674674
precs = OrdinaryDiffEq.DEFAULT_PRECS,
675675
linsolve=nothing,nlsolve=NLNewton(),
676676
extrapolant=:constant,
@@ -706,7 +706,7 @@ struct ImplicitRKMil{CS,AD,F,P,FDT,ST,CJ,N,T2,Controller,interpretation} <: Stoc
706706
symplectic::Bool
707707
end
708708
ImplicitRKMil(;chunk_size=0,autodiff=true,diff_type=Val{:central},
709-
standardtag = Val{true}(),concrete_jac = Val{true}(),
709+
standardtag = Val{true}(),concrete_jac = nothing,
710710
precs = OrdinaryDiffEq.DEFAULT_PRECS,
711711
linsolve=nothing,nlsolve=NLNewton(),
712712
extrapolant=:constant,
@@ -741,7 +741,7 @@ struct ISSEM{CS,AD,F,P,FDT,ST,CJ,N,T2,Controller} <: StochasticDiffEqNewtonAdapt
741741
symplectic::Bool
742742
end
743743
ISSEM(;chunk_size=0,autodiff=true,diff_type=Val{:central},
744-
standardtag = Val{true}(),concrete_jac = Val{true}(),
744+
standardtag = Val{true}(),concrete_jac = nothing,
745745
precs = OrdinaryDiffEq.DEFAULT_PRECS,
746746
linsolve=nothing,nlsolve=NLNewton(),
747747
extrapolant=:constant,
@@ -776,7 +776,7 @@ struct ISSEulerHeun{CS,AD,F,P,FDT,ST,CJ,N,T2,Controller} <: StochasticDiffEqNewt
776776
symplectic::Bool
777777
end
778778
ISSEulerHeun(;chunk_size=0,autodiff=true,diff_type=Val{:central},
779-
standardtag = Val{true}(),concrete_jac = Val{true}(),
779+
standardtag = Val{true}(),concrete_jac = nothing,
780780
precs = OrdinaryDiffEq.DEFAULT_PRECS,
781781
linsolve=nothing,nlsolve=NLNewton(),
782782
extrapolant=:constant,
@@ -808,7 +808,7 @@ struct SKenCarp{CS,AD,F,P,FDT,ST,CJ,N,T2,Controller} <: StochasticDiffEqNewtonAd
808808
end
809809

810810
SKenCarp(;chunk_size=0,autodiff=true,diff_type=Val{:central},
811-
standardtag = Val{true}(),concrete_jac = Val{true}(),
811+
standardtag = Val{true}(),concrete_jac = nothing,
812812
precs = OrdinaryDiffEq.DEFAULT_PRECS,
813813
linsolve=nothing,nlsolve=NLNewton(),
814814
smooth_est=true,extrapolant=:min_correct,

test/utility_tests.jl

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
using StochasticDiffEq, LinearAlgebra, SparseArrays, Random, Test, DiffEqOperators
1+
using StochasticDiffEq, LinearAlgebra, SparseArrays, Random, LinearSolve, Test
22
using StochasticDiffEq.OrdinaryDiffEq: WOperator, set_gamma!, calc_W!
33

44
@testset "Derivative Utilities" begin
5-
@testset "WOperator" begin
6-
Random.seed!(123)
7-
y = zeros(2); b = rand(2)
8-
mm = rand(2, 2)
9-
for _J in [rand(2, 2), Diagonal(rand(2))]
10-
_Ws = [-mm + 2.0 * _J, -mm/2.0 + _J]
11-
for inplace in (true, false), (_W, W_transform) in zip(_Ws, [false, true])
12-
W = WOperator{inplace}(mm, 1.0, DiffEqArrayOperator(_J), b, transform=W_transform)
13-
set_gamma!(W, 2.0)
14-
@test convert(AbstractMatrix,W) _W
15-
@test W * b _W * b
16-
mul!(y, W, b); @test y _W * b
17-
end
18-
end
19-
end
20-
215
@testset "calc_W!" begin
226
A = [-1.0 0.0; 0.0 -0.5]; σ = [0.9 0.0; 0.0 0.8]
237
mm = [2.0 0.0; 0.0 1.0]
248
u0 = [1.0, 1.0]; tmp = zeros(2)
25-
tspan = (0.0,1.0); dt = 0.01
26-
concrete_W = -mm + dt * A
9+
tspan = (0.0,1.0); dt = 0.01; dtgamma = 0.5dt
10+
concrete_W = -mm + dtgamma * A
2711

2812
# Out-of-place
2913
_f = (u,p,t) -> A*u; _g = (u,p,t) -> σ*u
@@ -33,7 +17,7 @@ using StochasticDiffEq.OrdinaryDiffEq: WOperator, set_gamma!, calc_W!
3317
prob = SDEProblem(fun, _g, u0, tspan)
3418
integrator = init(prob, ImplicitEM(theta=1); adaptive=false, dt=dt)
3519
W = integrator.cache.nlsolver.cache.W
36-
calc_W!(W, integrator, integrator.cache.nlsolver, integrator.cache, dt, false)
20+
calc_W!(W, integrator, integrator.cache.nlsolver, integrator.cache, dtgamma, false)
3721
@test convert(AbstractMatrix, W) concrete_W
3822
@test W \ u0 concrete_W \ u0
3923

@@ -45,9 +29,17 @@ using StochasticDiffEq.OrdinaryDiffEq: WOperator, set_gamma!, calc_W!
4529
prob = SDEProblem(fun, _g, u0, tspan)
4630
integrator = init(prob, ImplicitEM(theta=1); adaptive=false, dt=dt)
4731
W = integrator.cache.nlsolver.cache.W
48-
calc_W!(W, integrator, integrator.cache.nlsolver, integrator.cache, dt, false)
49-
@test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) concrete_W
50-
ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0); @test tmp concrete_W \ u0
32+
calc_W!(W, integrator, integrator.cache.nlsolver, integrator.cache, dtgamma, false)
33+
34+
# Did not update because it's an array operator
35+
# We don't want to build Jacobians when we have operators!
36+
@test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) != concrete_W
37+
ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0); @test tmp != concrete_W \ u0
38+
39+
# But jacobian2W! will update the cache
40+
StochasticDiffEq.OrdinaryDiffEq.jacobian2W!(integrator.cache.nlsolver.cache.W._concrete_form, mm, dtgamma, integrator.cache.nlsolver.cache.W.J.A, false)
41+
@test convert(AbstractMatrix, integrator.cache.nlsolver.cache.W) == concrete_W
42+
ldiv!(tmp, lu!(integrator.cache.nlsolver.cache.W), u0); @test tmp == concrete_W \ u0
5143
end
5244

5345
@testset "Implicit solver with lazy W" begin
@@ -69,7 +61,7 @@ using StochasticDiffEq.OrdinaryDiffEq: WOperator, set_gamma!, calc_W!
6961
Random.seed!(0); sol2 = solve(prob2, Alg(theta=1); adaptive=false, dt=0.01)
7062
@test sol1(1.0) sol2(1.0) rtol=1e-4
7163
Random.seed!(0); sol1_ip = solve(prob1_ip, Alg(theta=1); adaptive=false, dt=0.01)
72-
Random.seed!(0); sol2_ip = solve(prob2_ip, Alg(theta=1,linsolve=LinSolveFactorize(lu)); adaptive=false, dt=0.01)
64+
Random.seed!(0); sol2_ip = solve(prob2_ip, Alg(theta=1); adaptive=false, dt=0.01)
7365
@test sol1_ip(1.0) sol2_ip(1.0) rtol=1e-4
7466
end
7567

@@ -85,7 +77,7 @@ using StochasticDiffEq.OrdinaryDiffEq: WOperator, set_gamma!, calc_W!
8577
Random.seed!(0); sol2 = solve(prob2, SKenCarp(); adaptive=false, dt=0.01)
8678
@test sol1(1.0) sol2(1.0) rtol=1e-4
8779
Random.seed!(0); sol1_ip = solve(prob1_ip, SKenCarp(); adaptive=false, dt=0.01)
88-
Random.seed!(0); sol2_ip = solve(prob2_ip, SKenCarp(linsolve=LinSolveFactorize(lu)); adaptive=false, dt=0.01)
80+
Random.seed!(0); sol2_ip = solve(prob2_ip, SKenCarp(); adaptive=false, dt=0.01)
8981
@test sol1_ip(1.0) sol2_ip(1.0) rtol=1e-3
9082
end
9183
end

0 commit comments

Comments
 (0)