Skip to content

Commit

Permalink
test: centralize the 23 test problem testing
Browse files Browse the repository at this point in the history
  • Loading branch information
avik-pal committed Oct 31, 2024
1 parent a7a5f1e commit 4354511
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 146 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ NonlinearSolveFirstOrder = "1"
NonlinearSolveQuasiNewton = "1"
NonlinearSolveSpectralMethods = "1"
OrdinaryDiffEqTsit5 = "1.1.0"
PETSc = "0.2"
PETSc = "0.3"
Pkg = "1.10"
PrecompileTools = "1.2"
Preferences = "1.4"
Expand Down
106 changes: 0 additions & 106 deletions lib/SimpleNonlinearSolve/test/core/23_test_problems_tests.jl

This file was deleted.

109 changes: 70 additions & 39 deletions test/23_test_problems_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,25 @@ function test_on_library(
x = dict["start"]
res = similar(x)
nlprob = NonlinearProblem(problem, copy(x))
@testset "$idx: $(dict["title"])" begin
for alg in alg_ops
try
sol = solve(nlprob, alg; maxiters = 10000)
problem(res, sol.u, nothing)

skip = skip_tests !== nothing && idx in skip_tests[alg]
if skip
@test_skip norm(res, Inf) ϵ
continue
end
broken = idx in broken_tests[alg] ? true : false
@test norm(res, Inf)ϵ broken=broken
catch err
@error err
broken = idx in broken_tests[alg] ? true : false
if broken
@test false broken=true
else
@test 1 == 2
end
@testset "$idx: $(dict["title"]) | alg #$(alg_id)" for (alg_id, alg) in enumerate(alg_ops)
try
sol = solve(nlprob, alg; maxiters = 10000)
problem(res, sol.u, nothing)

skip = skip_tests !== nothing && idx in skip_tests[alg]
if skip
@test_skip norm(res, Inf) ϵ
continue
end
broken = idx in broken_tests[alg] ? true : false
@test norm(res, Inf)ϵ broken=broken
catch err
@error err
broken = idx in broken_tests[alg] ? true : false
if broken
@test false broken=true
else
@test 1 == 2
end
end
end
Expand All @@ -40,7 +38,7 @@ end
export test_on_library, problems, dicts
end

@testitem "PolyAlgorithms" setup=[RobustnessTesting] tags=[:core] begin
@testitem "23 Test Problems: PolyAlgorithms" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (RobustMultiNewton(), FastShortcutNonlinearPolyalg())

broken_tests = Dict(alg => Int[] for alg in alg_ops)
Expand All @@ -50,23 +48,41 @@ end
test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "NewtonRaphson" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (NewtonRaphson(),)
@testitem "23 Test Problems: NewtonRaphson" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (
NewtonRaphson(),
SimpleNewtonRaphson()
)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
broken_tests[alg_ops[1]] = [1]

test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "TrustRegion" setup=[RobustnessTesting] tags=[:core] begin
@testitem "23 Test Problems: Halley" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (SimpleHalley(; autodiff = AutoForwardDiff()),)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
if Sys.isapple()
broken_tests[alg_ops[1]] = [1, 5, 11, 15, 16, 18]
else
broken_tests[alg_ops[1]] = [1, 5, 15, 16, 18]
end

test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "23 Test Problems: TrustRegion" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Simple),
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Fan),
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Hei),
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Yuan),
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Bastin),
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.NLsolve)
TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.NLsolve),
SimpleTrustRegion(),
SimpleTrustRegion(; nlsolve_update_rule = Val(true))
)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
Expand All @@ -76,11 +92,13 @@ end
broken_tests[alg_ops[4]] = [8, 11, 21]
broken_tests[alg_ops[5]] = [21]
broken_tests[alg_ops[6]] = [11, 21]
broken_tests[alg_ops[7]] = [3, 15, 16, 21]
broken_tests[alg_ops[8]] = [15, 16]

test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "LevenbergMarquardt" setup=[RobustnessTesting] tags=[:core] begin
@testitem "23 Test Problems: LevenbergMarquardt" setup=[RobustnessTesting] tags=[:core] begin
using LinearSolve

alg_ops = (
Expand All @@ -97,50 +115,63 @@ end
test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "DFSane" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (DFSane(),)
@testitem "23 Test Problems: DFSane" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (
DFSane(),
SimpleDFSane()
)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
broken_tests[alg_ops[1]] = [1, 2, 3, 5, 21]
if Sys.isapple()
broken_tests[alg_ops[2]] = [1, 2, 3, 5, 6, 21]
else
broken_tests[alg_ops[2]] = [1, 2, 3, 5, 6, 11, 21]
end

test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "Broyden" setup=[RobustnessTesting] tags=[:core] retries=3 begin
@testitem "23 Test Problems: Broyden" setup=[RobustnessTesting] tags=[:core] retries=3 begin
alg_ops = (
Broyden(),
Broyden(; init_jacobian = Val(:true_jacobian)),
Broyden(; update_rule = Val(:bad_broyden)),
Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden))
Broyden(; init_jacobian = Val(:true_jacobian), update_rule = Val(:bad_broyden)),
SimpleBroyden()
)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
broken_tests[alg_ops[4]] = [5, 6, 8, 11]
if Sys.isapple()
broken_tests[alg_ops[1]] = [1, 5, 11]
broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
broken_tests[alg_ops[3]] = [1, 5, 6, 9, 11]
broken_tests[alg_ops[4]] = [5, 6, 8, 11, 16]
else
broken_tests[alg_ops[1]] = [1, 5, 11, 15]
broken_tests[alg_ops[2]] = [1, 5, 8, 11, 18]
broken_tests[alg_ops[3]] = [1, 5, 9, 11]
broken_tests[alg_ops[4]] = [5, 6, 8, 11]
broken_tests[alg_ops[3]] = [1, 5, 9, 11, 16]
end
broken_tests[alg_ops[5]] = [1, 5, 11]

test_on_library(problems, dicts, alg_ops, broken_tests, Sys.isapple() ? 1e-3 : 1e-4)
end

@testitem "Klement" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (Klement(), Klement(; init_jacobian = Val(:true_jacobian_diagonal)))
@testitem "23 Test Problems: Klement" setup=[RobustnessTesting] tags=[:core] begin
alg_ops = (
Klement(),
Klement(; init_jacobian = Val(:true_jacobian_diagonal)),
SimpleKlement()
)

broken_tests = Dict(alg => Int[] for alg in alg_ops)
broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 18, 22]
broken_tests[alg_ops[2]] = [2, 4, 5, 7, 18, 22]
broken_tests[alg_ops[3]] = [1, 2, 4, 5, 11, 22]

test_on_library(problems, dicts, alg_ops, broken_tests)
end

@testitem "PseudoTransient" setup=[RobustnessTesting] tags=[:core] begin
@testitem "23 Test Problems: PseudoTransient" setup=[RobustnessTesting] tags=[:core] begin
# PT relies on the root being a stable equilibrium for convergence, so it won't work on
# most problems
alg_ops = (PseudoTransient(),)
Expand Down

0 comments on commit 4354511

Please sign in to comment.