Skip to content

Commit 9bdc61c

Browse files
committed
test: 23 test problems
1 parent 36294b1 commit 9bdc61c

File tree

4 files changed

+116
-11
lines changed

4 files changed

+116
-11
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
@testsnippet RobustnessTestSnippet begin
2+
using NonlinearProblemLibrary, NonlinearSolveBase, LinearAlgebra
3+
4+
problems = NonlinearProblemLibrary.problems
5+
dicts = NonlinearProblemLibrary.dicts
6+
7+
function test_on_library(
8+
problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; skip_tests = nothing)
9+
for (idx, (problem, dict)) in enumerate(zip(problems, dicts))
10+
x = dict["start"]
11+
res = similar(x)
12+
nlprob = NonlinearProblem(problem, copy(x))
13+
@testset "$idx: $(dict["title"])" begin
14+
for alg in alg_ops
15+
try
16+
sol = solve(nlprob, alg;
17+
termination_condition = AbsNormTerminationMode(norm))
18+
problem(res, sol.u, nothing)
19+
20+
skip = skip_tests !== nothing && idx in skip_tests[alg]
21+
if skip
22+
@test_skip norm(res) ϵ
23+
continue
24+
end
25+
broken = idx in broken_tests[alg] ? true : false
26+
@test norm(res)ϵ broken=broken
27+
catch e
28+
@error e
29+
broken = idx in broken_tests[alg] ? true : false
30+
if broken
31+
@test false broken=true
32+
else
33+
@test 1 == 2
34+
end
35+
end
36+
end
37+
end
38+
end
39+
end
40+
end
41+
42+
@testitem "23 Test Problems: SimpleNewtonRaphson" setup=[RobustnessTestSnippet] tags=[:core] begin
43+
alg_ops = (SimpleNewtonRaphson(),)
44+
45+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
46+
broken_tests[alg_ops[1]] = []
47+
48+
test_on_library(problems, dicts, alg_ops, broken_tests)
49+
end
50+
51+
@testitem "23 Test Problems: SimpleHalley" setup=[RobustnessTestSnippet] tags=[:core] begin
52+
alg_ops = (SimpleHalley(),)
53+
54+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
55+
if Sys.isapple()
56+
broken_tests[alg_ops[1]] = [1, 5, 11, 15, 16, 18]
57+
else
58+
broken_tests[alg_ops[1]] = [1, 5, 15, 16, 18]
59+
end
60+
61+
test_on_library(problems, dicts, alg_ops, broken_tests)
62+
end
63+
64+
@testitem "23 Test Problems: SimpleTrustRegion" setup=[RobustnessTestSnippet] tags=[:core] begin
65+
alg_ops = (SimpleTrustRegion(), SimpleTrustRegion(; nlsolve_update_rule = Val(true)))
66+
67+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
68+
broken_tests[alg_ops[1]] = [3, 15, 16, 21]
69+
broken_tests[alg_ops[2]] = [15, 16]
70+
71+
test_on_library(problems, dicts, alg_ops, broken_tests)
72+
end
73+
74+
@testitem "23 Test Problems: SimpleDFSane" setup=[RobustnessTestSnippet] tags=[:core] begin
75+
alg_ops = (SimpleDFSane(),)
76+
77+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
78+
if Sys.isapple()
79+
broken_tests[alg_ops[1]] = [1, 2, 3, 5, 6, 21]
80+
else
81+
broken_tests[alg_ops[1]] = [1, 2, 3, 4, 5, 6, 11, 21]
82+
end
83+
84+
test_on_library(problems, dicts, alg_ops, broken_tests)
85+
end
86+
87+
@testitem "23 Test Problems: SimpleBroyden" setup=[RobustnessTestSnippet] tags=[:core] begin
88+
alg_ops = (SimpleBroyden(),)
89+
90+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
91+
broken_tests[alg_ops[1]] = [1, 5, 11]
92+
93+
test_on_library(problems, dicts, alg_ops, broken_tests)
94+
end
95+
96+
@testitem "23 Test Problems: SimpleKlement" setup=[RobustnessTestSnippet] tags=[:core] begin
97+
alg_ops = (SimpleKlement(),)
98+
99+
broken_tests = Dict(alg => Int[] for alg in alg_ops)
100+
broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 12, 22]
101+
102+
test_on_library(problems, dicts, alg_ops, broken_tests)
103+
end

lib/SimpleNonlinearSolve/test/core/exotic_type_tests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
prob_oop_bf = NonlinearProblem{false}(fn_oop, u0, BigFloat(2))
1010

1111
@testset "$(nameof(typeof(alg)))" for alg in (
12-
SimpleNewtonRaphson(),
12+
SimpleNewtonRaphson(; autodiff = AutoForwardDiff()),
1313
SimpleBroyden(),
1414
SimpleKlement(),
1515
SimpleDFSane(),
16-
SimpleTrustRegion(),
16+
SimpleTrustRegion(; autodiff = AutoForwardDiff()),
1717
SimpleLimitedMemoryBroyden(),
18-
SimpleHalley()
18+
SimpleHalley(; autodiff = AutoForwardDiff())
1919
)
2020
sol = solve(prob_oop_bf, alg)
2121
@test maximum(abs, sol.resid) < 1e-6

lib/SimpleNonlinearSolve/test/core/forward_diff_tests.jl

Whitespace-only changes.

lib/SimpleNonlinearSolve/test/gpu/cuda_tests.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
f!(du, u, p) = (du .= u .* u .- 2)
99

1010
@testset "$(nameof(typeof(alg)))" for alg in (
11-
SimpleNewtonRaphson(),
11+
SimpleNewtonRaphson(; autodiff = AutoForwardDiff()),
1212
SimpleDFSane(),
13-
SimpleTrustRegion(),
14-
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
13+
SimpleTrustRegion(; autodiff = AutoForwardDiff()),
14+
SimpleTrustRegion(;
15+
nlsolve_update_rule = Val(true), autodiff = AutoForwardDiff()),
1516
SimpleBroyden(),
1617
SimpleLimitedMemoryBroyden(),
1718
SimpleKlement(),
18-
SimpleHalley(),
19+
SimpleHalley(; autodiff = AutoForwardDiff()),
1920
SimpleBroyden(; linesearch = Val(true)),
2021
SimpleLimitedMemoryBroyden(; linesearch = Val(true))
2122
)
@@ -63,14 +64,15 @@ end
6364
prob = convert(ImmutableNonlinearProblem, NonlinearProblem{false}(f, u0, 2.0f0))
6465

6566
@testset "$(nameof(typeof(alg)))" for alg in (
66-
SimpleNewtonRaphson(),
67+
SimpleNewtonRaphson(; autodiff = AutoForwardDiff()),
6768
SimpleDFSane(),
68-
SimpleTrustRegion(),
69-
SimpleTrustRegion(; nlsolve_update_rule = Val(true)),
69+
SimpleTrustRegion(; autodiff = AutoForwardDiff()),
70+
SimpleTrustRegion(;
71+
nlsolve_update_rule = Val(true), autodiff = AutoForwardDiff()),
7072
SimpleBroyden(),
7173
SimpleLimitedMemoryBroyden(),
7274
SimpleKlement(),
73-
SimpleHalley(),
75+
SimpleHalley(; autodiff = AutoForwardDiff()),
7476
SimpleBroyden(; linesearch = Val(true)),
7577
SimpleLimitedMemoryBroyden(; linesearch = Val(true))
7678
)

0 commit comments

Comments
 (0)