Skip to content

Commit 211d935

Browse files
committed
Run NLLS tests only in ≥ 1.10-
1 parent f59ff23 commit 211d935

File tree

4 files changed

+117
-109
lines changed

4 files changed

+117
-109
lines changed

src/solve/mirk.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -303,31 +303,31 @@ function __construct_nlproblem(cache::MIRKCache{iip}, y, loss_bc::BC, loss_collo
303303
jac_prototype = vcat(init_jacobian(cache_bc), init_jacobian(cache_collocation))
304304

305305
jac = if iip
306-
(J, u, p) -> __mirk_mpoint_jacobian!(J, u, p, jac_alg.bc_diffmode,
306+
(J, u, p) -> __mirk_mpoint_jacobian!(J, u, jac_alg.bc_diffmode,
307307
jac_alg.nonbc_diffmode, cache_bc, cache_collocation, loss_bcₚ,
308-
loss_collocationₚ, resid_bc, resid_collocation, cache.M, L)
308+
loss_collocationₚ, resid_bc, resid_collocation, L)
309309
else
310-
(u, p) -> __mirk_mpoint_jacobian(u, p, jac_prototype, jac_alg.bc_diffmode,
310+
(u, p) -> __mirk_mpoint_jacobian(jac_prototype, u, jac_alg.bc_diffmode,
311311
jac_alg.nonbc_diffmode, cache_bc, cache_collocation, loss_bcₚ,
312-
loss_collocationₚ, cache.M, L)
312+
loss_collocationₚ, L)
313313
end
314314

315315
nlf = NonlinearFunction{iip}(loss; resid_prototype = vcat(resid_bc, resid_collocation),
316316
jac, jac_prototype)
317317
return (L == cache.M ? NonlinearProblem : NonlinearLeastSquaresProblem)(nlf, y, cache.p)
318318
end
319319

320-
function __mirk_mpoint_jacobian!(J, x, p, bc_diffmode, nonbc_diffmode, bc_diffcache,
320+
function __mirk_mpoint_jacobian!(J, x, bc_diffmode, nonbc_diffmode, bc_diffcache,
321321
nonbc_diffcache, loss_bc::BC, loss_collocation::C, resid_bc, resid_collocation,
322-
M::Int, L::Int) where {BC, C}
322+
L::Int) where {BC, C}
323323
sparse_jacobian!(@view(J[1:L, :]), bc_diffmode, bc_diffcache, loss_bc, resid_bc, x)
324324
sparse_jacobian!(@view(J[(L + 1):end, :]), nonbc_diffmode, nonbc_diffcache,
325325
loss_collocation, resid_collocation, x)
326326
return nothing
327327
end
328328

329-
function __mirk_mpoint_jacobian(x, p, J, bc_diffmode, nonbc_diffmode, bc_diffcache,
330-
nonbc_diffcache, loss_bc::BC, loss_collocation::C, M::Int, L::Int) where {BC, C}
329+
function __mirk_mpoint_jacobian(J, x, bc_diffmode, nonbc_diffmode, bc_diffcache,
330+
nonbc_diffcache, loss_bc::BC, loss_collocation::C, L::Int) where {BC, C}
331331
sparse_jacobian!(@view(J[1:L, :]), bc_diffmode, bc_diffcache, loss_bc, x)
332332
sparse_jacobian!(@view(J[(L + 1):end, :]), nonbc_diffmode, nonbc_diffcache,
333333
loss_collocation, x)
@@ -358,10 +358,10 @@ function __construct_nlproblem(cache::MIRKCache{iip}, y, loss_bc::BC, loss_collo
358358
jac_prototype = init_jacobian(diffcache)
359359

360360
jac = if iip
361-
(J, u, p) -> __mirk_2point_jacobian!(J, u, p, jac_alg.diffmode, diffcache, lossₚ,
361+
(J, u, p) -> __mirk_2point_jacobian!(J, u, jac_alg.diffmode, diffcache, lossₚ,
362362
resid)
363363
else
364-
(u, p) -> __mirk_2point_jacobian(u, p, jac_prototype, jac_alg.diffmode, diffcache,
364+
(u, p) -> __mirk_2point_jacobian(u, jac_prototype, jac_alg.diffmode, diffcache,
365365
lossₚ)
366366
end
367367

@@ -370,12 +370,12 @@ function __construct_nlproblem(cache::MIRKCache{iip}, y, loss_bc::BC, loss_collo
370370
return (L == cache.M ? NonlinearProblem : NonlinearLeastSquaresProblem)(nlf, y, cache.p)
371371
end
372372

373-
function __mirk_2point_jacobian!(J, x, p, diffmode, diffcache, loss_fn::L, resid) where {L}
373+
function __mirk_2point_jacobian!(J, x, diffmode, diffcache, loss_fn::L, resid) where {L}
374374
sparse_jacobian!(J, diffmode, diffcache, loss_fn, resid, x)
375375
return J
376376
end
377377

378-
function __mirk_2point_jacobian(x, p, J, diffmode, diffcache, loss_fn::L) where {L}
378+
function __mirk_2point_jacobian(x, J, diffmode, diffcache, loss_fn::L) where {L}
379379
sparse_jacobian!(J, diffmode, diffcache, loss_fn, x)
380380
return J
381381
end

test/runtests.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ const GROUP = uppercase(get(ENV, "GROUP", "ALL"))
1414
@time @safetestset "Orbital" begin
1515
include("shooting/orbital.jl")
1616
end
17+
if VERSION v"1.10-"
18+
@time @safetestset "Shooting NLLS Tests" begin
19+
include("shooting/nonlinear_least_squares.jl")
20+
end
21+
end
1722
end
1823
end
1924

@@ -31,8 +36,10 @@ const GROUP = uppercase(get(ENV, "GROUP", "ALL"))
3136
@time @safetestset "Interpolation Tests" begin
3237
include("mirk/interpolation_test.jl")
3338
end
34-
@time @safetestset "MIRK Nonlinear Least Squares Tests" begin
35-
include("mirk/nonlinear_least_squares.jl")
39+
if VERSION v"1.10-"
40+
@time @safetestset "MIRK NLLS Tests" begin
41+
include("mirk/nonlinear_least_squares.jl")
42+
end
3643
end
3744
end
3845
end
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
using BoundaryValueDiffEq, LinearAlgebra, LinearSolve, OrdinaryDiffEq, Test
2+
3+
@testset "Overconstrained BVP" begin
4+
SOLVERS = [
5+
Shooting(Tsit5(); nlsolve = LevenbergMarquardt()),
6+
Shooting(Tsit5(); nlsolve = GaussNewton()),
7+
MultipleShooting(10, Tsit5(); nlsolve = LevenbergMarquardt()),
8+
MultipleShooting(10, Tsit5(); nlsolve = GaussNewton())]
9+
10+
# OOP MP-BVP
11+
f1(u, p, t) = [u[2], -u[1]]
12+
13+
function bc1(sol, p, t)
14+
t₁, t₂ = extrema(t)
15+
solₜ₁ = sol(t₁)
16+
solₜ₂ = sol(t₂)
17+
solₜ₃ = sol((t₁ + t₂) / 2)
18+
# We know that this overconstrained system has a solution
19+
return [solₜ₁[1], solₜ₂[1] - 1, solₜ₃[1] - 0.51735, solₜ₃[2] + 1.92533]
20+
end
21+
22+
tspan = (0.0, 100.0)
23+
u0 = [0.0, 1.0]
24+
25+
bvp1 = BVProblem(BVPFunction{false}(f1, bc1; bcresid_prototype = zeros(4)), u0, tspan)
26+
27+
for solver in SOLVERS
28+
@time sol = solve(bvp1, solver;
29+
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
30+
verbose = false)
31+
@test norm(bc1(sol, nothing, sol.t)) < 1e-4
32+
end
33+
34+
# IIP MP-BVP
35+
function f1!(du, u, p, t)
36+
du[1] = u[2]
37+
du[2] = -u[1]
38+
return nothing
39+
end
40+
41+
function bc1!(resid, sol, p, t)
42+
(t₁, t₂) = extrema(t)
43+
solₜ₁ = sol(t₁)
44+
solₜ₂ = sol(t₂)
45+
solₜ₃ = sol((t₁ + t₂) / 2)
46+
# We know that this overconstrained system has a solution
47+
resid[1] = solₜ₁[1]
48+
resid[2] = solₜ₂[1] - 1
49+
resid[3] = solₜ₃[1] - 0.51735
50+
resid[4] = solₜ₃[2] + 1.92533
51+
return nothing
52+
end
53+
54+
bvp2 = BVProblem(BVPFunction{true}(f1!, bc1!; bcresid_prototype = zeros(4)), u0, tspan)
55+
56+
for solver in SOLVERS
57+
@time sol = solve(bvp2, solver;
58+
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
59+
verbose = false)
60+
resid_f = Array{Float64}(undef, 4)
61+
bc1!(resid_f, sol, nothing, sol.t)
62+
@test norm(resid_f) < 1e-4
63+
end
64+
65+
# OOP TP-BVP
66+
bc1a(ua, p) = [ua[1]]
67+
bc1b(ub, p) = [ub[1] - 1, ub[2] + 1.729109]
68+
69+
bvp3 = TwoPointBVProblem(BVPFunction{false}(f1, (bc1a, bc1b); twopoint = Val(true),
70+
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan)
71+
72+
for solver in SOLVERS
73+
@time sol = solve(bvp3, solver;
74+
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
75+
verbose = false)
76+
@test norm(vcat(bc1a(sol(0.0), nothing), bc1b(sol(100.0), nothing))) < 1e-4
77+
end
78+
79+
# IIP TP-BVP
80+
bc1a!(resid, ua, p) = (resid[1] = ua[1])
81+
bc1b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109)
82+
83+
bvp4 = TwoPointBVProblem(BVPFunction{true}(f1!, (bc1a!, bc1b!); twopoint = Val(true),
84+
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan)
85+
86+
for solver in SOLVERS
87+
@time sol = solve(bvp4, solver;
88+
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
89+
verbose = false)
90+
resida = Array{Float64}(undef, 1)
91+
residb = Array{Float64}(undef, 2)
92+
bc1a!(resida, sol(0.0), nothing)
93+
bc1b!(residb, sol(100.0), nothing)
94+
@test norm(vcat(resida, residb)) < 1e-4
95+
end
96+
end

test/shooting/shooting_tests.jl

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -80,101 +80,6 @@ using BoundaryValueDiffEq, LinearAlgebra, LinearSolve, OrdinaryDiffEq, Test
8080
end
8181
end
8282

83-
@testset "Overconstrained BVP" begin
84-
SOLVERS = [
85-
Shooting(Tsit5(); nlsolve = LevenbergMarquardt()),
86-
Shooting(Tsit5(); nlsolve = GaussNewton()),
87-
MultipleShooting(10, Tsit5(); nlsolve = LevenbergMarquardt()),
88-
MultipleShooting(10, Tsit5(); nlsolve = GaussNewton())]
89-
90-
# OOP MP-BVP
91-
f1(u, p, t) = [u[2], -u[1]]
92-
93-
function bc1(sol, p, t)
94-
t₁, t₂ = extrema(t)
95-
solₜ₁ = sol(t₁)
96-
solₜ₂ = sol(t₂)
97-
solₜ₃ = sol((t₁ + t₂) / 2)
98-
# We know that this overconstrained system has a solution
99-
return [solₜ₁[1], solₜ₂[1] - 1, solₜ₃[1] - 0.51735, solₜ₃[2] + 1.92533]
100-
end
101-
102-
tspan = (0.0, 100.0)
103-
u0 = [0.0, 1.0]
104-
105-
bvp1 = BVProblem(BVPFunction{false}(f1, bc1; bcresid_prototype = zeros(4)), u0, tspan)
106-
107-
for solver in SOLVERS
108-
@time sol = solve(bvp1, solver;
109-
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
110-
verbose = false)
111-
@test norm(bc1(sol, nothing, sol.t)) < 1e-4
112-
end
113-
114-
# IIP MP-BVP
115-
function f1!(du, u, p, t)
116-
du[1] = u[2]
117-
du[2] = -u[1]
118-
return nothing
119-
end
120-
121-
function bc1!(resid, sol, p, t)
122-
(t₁, t₂) = extrema(t)
123-
solₜ₁ = sol(t₁)
124-
solₜ₂ = sol(t₂)
125-
solₜ₃ = sol((t₁ + t₂) / 2)
126-
# We know that this overconstrained system has a solution
127-
resid[1] = solₜ₁[1]
128-
resid[2] = solₜ₂[1] - 1
129-
resid[3] = solₜ₃[1] - 0.51735
130-
resid[4] = solₜ₃[2] + 1.92533
131-
return nothing
132-
end
133-
134-
bvp2 = BVProblem(BVPFunction{true}(f1!, bc1!; bcresid_prototype = zeros(4)), u0, tspan)
135-
136-
for solver in SOLVERS
137-
@time sol = solve(bvp2, solver;
138-
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
139-
verbose = false)
140-
resid_f = Array{Float64}(undef, 4)
141-
bc1!(resid_f, sol, nothing, sol.t)
142-
@test norm(resid_f) < 1e-4
143-
end
144-
145-
# OOP TP-BVP
146-
bc1a(ua, p) = [ua[1]]
147-
bc1b(ub, p) = [ub[1] - 1, ub[2] + 1.729109]
148-
149-
bvp3 = TwoPointBVProblem(BVPFunction{false}(f1, (bc1a, bc1b); twopoint = Val(true),
150-
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan)
151-
152-
for solver in SOLVERS
153-
@time sol = solve(bvp3, solver;
154-
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
155-
verbose = false)
156-
@test norm(vcat(bc1a(sol(0.0), nothing), bc1b(sol(100.0), nothing))) < 1e-4
157-
end
158-
159-
# IIP TP-BVP
160-
bc1a!(resid, ua, p) = (resid[1] = ua[1])
161-
bc1b!(resid, ub, p) = (resid[1] = ub[1] - 1; resid[2] = ub[2] + 1.729109)
162-
163-
bvp4 = TwoPointBVProblem(BVPFunction{true}(f1!, (bc1a!, bc1b!); twopoint = Val(true),
164-
bcresid_prototype = (zeros(1), zeros(2))), u0, tspan)
165-
166-
for solver in SOLVERS
167-
@time sol = solve(bvp4, solver;
168-
nlsolve_kwargs = (; abstol = 1e-8, reltol = 1e-8, maxiters = 1000),
169-
verbose = false)
170-
resida = Array{Float64}(undef, 1)
171-
residb = Array{Float64}(undef, 2)
172-
bc1a!(resida, sol(0.0), nothing)
173-
bc1b!(residb, sol(100.0), nothing)
174-
@test norm(vcat(resida, residb)) < 1e-4
175-
end
176-
end
177-
17883
@testset "Shooting with Complex Values" begin
17984
# Test for complex values
18085
function f1!(du, u, p, t)

0 commit comments

Comments
 (0)