From 43545118ac8c7de684627908080f6749baf10faa Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Thu, 31 Oct 2024 10:00:04 -0400 Subject: [PATCH] test: centralize the 23 test problem testing --- Project.toml | 2 +- .../test/core/23_test_problems_tests.jl | 106 ----------------- test/23_test_problems_tests.jl | 109 +++++++++++------- 3 files changed, 71 insertions(+), 146 deletions(-) delete mode 100644 lib/SimpleNonlinearSolve/test/core/23_test_problems_tests.jl diff --git a/Project.toml b/Project.toml index bd31721c1..b827985cf 100644 --- a/Project.toml +++ b/Project.toml @@ -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" diff --git a/lib/SimpleNonlinearSolve/test/core/23_test_problems_tests.jl b/lib/SimpleNonlinearSolve/test/core/23_test_problems_tests.jl deleted file mode 100644 index 6dd85b94b..000000000 --- a/lib/SimpleNonlinearSolve/test/core/23_test_problems_tests.jl +++ /dev/null @@ -1,106 +0,0 @@ -@testsnippet RobustnessTestSnippet begin - using NonlinearProblemLibrary, NonlinearSolveBase, LinearAlgebra, ADTypes - - problems = NonlinearProblemLibrary.problems - dicts = NonlinearProblemLibrary.dicts - - function test_on_library( - problems, dicts, alg_ops, broken_tests, ϵ = 1e-4; skip_tests = nothing) - for (idx, (problem, dict)) in enumerate(zip(problems, dicts)) - 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; - termination_condition = AbsNormTerminationMode(norm)) - problem(res, sol.u, nothing) - - skip = skip_tests !== nothing && idx in skip_tests[alg] - if skip - @test_skip norm(res) ≤ ϵ - continue - end - broken = idx in broken_tests[alg] ? true : false - @test norm(res)≤ϵ broken=broken - catch e - @error e - broken = idx in broken_tests[alg] ? true : false - if broken - @test false broken=true - else - @test 1 == 2 - end - end - end - end - end - end -end - -@testitem "23 Test Problems: SimpleNewtonRaphson" setup=[RobustnessTestSnippet] tags=[:core] begin - alg_ops = (SimpleNewtonRaphson(; autodiff = AutoForwardDiff()),) - - broken_tests = Dict(alg => Int[] for alg in alg_ops) - broken_tests[alg_ops[1]] = [] - - test_on_library(problems, dicts, alg_ops, broken_tests) -end - -@testitem "23 Test Problems: SimpleHalley" setup=[RobustnessTestSnippet] 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: SimpleTrustRegion" setup=[RobustnessTestSnippet] tags=[:core] begin - alg_ops = ( - SimpleTrustRegion(; autodiff = AutoForwardDiff()), - SimpleTrustRegion(; nlsolve_update_rule = Val(true), autodiff = AutoForwardDiff()) - ) - - broken_tests = Dict(alg => Int[] for alg in alg_ops) - broken_tests[alg_ops[1]] = [3, 15, 16, 21] - broken_tests[alg_ops[2]] = [15, 16] - - test_on_library(problems, dicts, alg_ops, broken_tests) -end - -@testitem "23 Test Problems: SimpleDFSane" setup=[RobustnessTestSnippet] tags=[:core] begin - alg_ops = (SimpleDFSane(),) - - broken_tests = Dict(alg => Int[] for alg in alg_ops) - if Sys.isapple() - broken_tests[alg_ops[1]] = [1, 2, 3, 5, 6, 21] - else - broken_tests[alg_ops[1]] = [1, 2, 3, 4, 5, 6, 11, 21] - end - - test_on_library(problems, dicts, alg_ops, broken_tests) -end - -@testitem "23 Test Problems: SimpleBroyden" setup=[RobustnessTestSnippet] tags=[:core] begin - alg_ops = (SimpleBroyden(),) - - broken_tests = Dict(alg => Int[] for alg in alg_ops) - broken_tests[alg_ops[1]] = [1, 5, 11] - - test_on_library(problems, dicts, alg_ops, broken_tests) -end - -@testitem "23 Test Problems: SimpleKlement" setup=[RobustnessTestSnippet] tags=[:core] begin - alg_ops = (SimpleKlement(),) - - broken_tests = Dict(alg => Int[] for alg in alg_ops) - broken_tests[alg_ops[1]] = [1, 2, 4, 5, 11, 12, 22] - - test_on_library(problems, dicts, alg_ops, broken_tests) -end diff --git a/test/23_test_problems_tests.jl b/test/23_test_problems_tests.jl index d740a87c2..2285a52a9 100644 --- a/test/23_test_problems_tests.jl +++ b/test/23_test_problems_tests.jl @@ -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 @@ -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) @@ -50,8 +48,11 @@ 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] @@ -59,14 +60,29 @@ end 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) @@ -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 = ( @@ -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(),)