|
73 | 73 | diffeq = (alg = SRA(), abstol = 1.0e-3, reltol = 1.0e-3, verbose = false) |
74 | 74 | ) |
75 | 75 | @test lorenz_SRA.integ.alg isa SRA |
76 | | - @test lorenz_SRA.integ.opts.verbose == false |
| 76 | + # SciML moved from Bool verbose to a `DEVerbosity` struct of per-toggle verbosities. |
| 77 | + @test nameof(typeof(lorenz_SRA.integ.opts.verbose.linear_verbosity)) == :None |
77 | 78 |
|
78 | 79 | # also test SDEproblem creation |
79 | 80 | prob = lorenz_SRA.integ.sol.prob |
80 | 81 |
|
81 | 82 | ds = CoupledSDEs(prob, (alg = SRA(), abstol = 0.0, reltol = 1.0e-3, verbose = false)) |
82 | 83 |
|
83 | 84 | @test ds.integ.alg isa SRA |
84 | | - @test ds.integ.opts.verbose == false |
| 85 | + @test nameof(typeof(ds.integ.opts.verbose.linear_verbosity)) == :None |
85 | 86 |
|
86 | 87 | @test_throws ArgumentError CoupledSDEs(prob; diffeq = (alg = SRA(),)) |
87 | 88 |
|
|
104 | 105 | corr = CoupledSDEs(f, zeros(2); covariance = [1 0.3; 0.3 1]) |
105 | 106 | corr_alt = CoupledSDEs(f, zeros(2); g = g, noise_prototype = zeros(2, 2)) |
106 | 107 | @test corr.noise_type == corr_alt.noise_type |
107 | | - @test all(corr.integ.g(zeros(2), (), 0.0) .== corr_alt.integ.g(zeros(2), (), 0.0)) |
| 108 | + @test all( |
| 109 | + DynamicalSystemsBase.referrenced_sciml_prob(corr).g(zeros(2), (), 0.0) .== |
| 110 | + DynamicalSystemsBase.referrenced_sciml_prob(corr_alt).g(zeros(2), (), 0.0) |
| 111 | + ) |
108 | 112 | end |
109 | 113 |
|
110 | 114 | @testset "ArgumentError" begin |
|
202 | 206 | # Different explicit seed → different trajectory |
203 | 207 | reinit!(ds; seed = UInt64(43)); step!(ds, 1.0); uc = copy(current_state(ds)) |
204 | 208 | @test ua != uc |
| 209 | +# Regression test for https://github.com/JuliaDynamics/DynamicalSystemsBase.jl/issues/251: |
| 210 | +# the auto-generated diffusion closure used to recompute its (constant) output on every |
| 211 | +# call, allocating ~1 KB per `step!` and dominating long integrations. The closure must |
| 212 | +# now return a precomputed constant with no allocations. |
| 213 | +@testset "auto-diffusion closure is allocation-free (#251)" begin |
| 214 | + f_oop(u, p, t) = SVector{2}(0.0, 0.0) |
| 215 | + f_iip(du, u, p, t) = (du .= 0; nothing) |
| 216 | + Γ = [1.0 0.3; 0.3 1.0] |
| 217 | + |
| 218 | + function call_oop(g, n) |
| 219 | + s = SVector(0.1, 0.2) |
| 220 | + out = SVector(0.0, 0.0) |
| 221 | + for _ in 1:n |
| 222 | + out = g(s, nothing, 0.0) |
| 223 | + end |
| 224 | + return out |
| 225 | + end |
| 226 | + function call_iip!(g, du, n) |
| 227 | + u = [0.0, 0.0] |
| 228 | + for _ in 1:n |
| 229 | + g(du, u, nothing, 0.0) |
| 230 | + end |
| 231 | + return du |
| 232 | + end |
| 233 | + |
| 234 | + @testset "OOP diagonal" begin |
| 235 | + ds = CoupledSDEs(f_oop, SVector(0.0, 0.0); noise_strength = 2.5) |
| 236 | + g = ds.integ.sol.prob.f.g |
| 237 | + @test g(SVector(0.0, 0.0), nothing, 0.0) === g(SVector(1.0, 1.0), nothing, 5.0) |
| 238 | + @test g(SVector(0.0, 0.0), nothing, 0.0) == SVector(2.5, 2.5) |
| 239 | + call_oop(g, 10) # warmup |
| 240 | + @test (@allocated call_oop(g, 10_000)) < 100 |
| 241 | + end |
| 242 | + |
| 243 | + @testset "OOP non-diagonal" begin |
| 244 | + ds = CoupledSDEs(f_oop, SVector(0.0, 0.0); covariance = Γ, noise_strength = 1.5) |
| 245 | + g = ds.integ.sol.prob.f.g |
| 246 | + @test g(SVector(0.0, 0.0), nothing, 0.0) === g(SVector(1.0, 1.0), nothing, 5.0) |
| 247 | + @test g(SVector(0.0, 0.0), nothing, 0.0) ≈ 1.5 .* sqrt(Γ) |
| 248 | + call_oop(g, 10) |
| 249 | + @test (@allocated call_oop(g, 10_000)) < 100 |
| 250 | + end |
| 251 | + |
| 252 | + @testset "IIP diagonal" begin |
| 253 | + ds = CoupledSDEs(f_iip, [0.0, 0.0]; noise_strength = 2.5) |
| 254 | + g = ds.integ.sol.prob.f.g |
| 255 | + du = zeros(2) |
| 256 | + g(du, [0.0, 0.0], nothing, 0.0) |
| 257 | + @test du == [2.5, 2.5] |
| 258 | + call_iip!(g, du, 10) |
| 259 | + @test (@allocated call_iip!(g, du, 10_000)) < 100 |
| 260 | + end |
| 261 | + |
| 262 | + @testset "IIP non-diagonal" begin |
| 263 | + ds = CoupledSDEs(f_iip, [0.0, 0.0]; covariance = Γ, noise_strength = 1.5) |
| 264 | + g = ds.integ.sol.prob.f.g |
| 265 | + DU = zeros(2, 2) |
| 266 | + g(DU, [0.0, 0.0], nothing, 0.0) |
| 267 | + @test DU ≈ 1.5 .* sqrt(Γ) |
| 268 | + function call_iip_mat!(g, DU, n) |
| 269 | + u = [0.0, 0.0] |
| 270 | + for _ in 1:n |
| 271 | + g(DU, u, nothing, 0.0) |
| 272 | + end |
| 273 | + return DU |
| 274 | + end |
| 275 | + call_iip_mat!(g, DU, 10) |
| 276 | + @test (@allocated call_iip_mat!(g, DU, 10_000)) < 100 |
205 | 277 | end |
206 | 278 | end |
0 commit comments