|
| 1 | +using NonlinearSolve, LinearAlgebra, NonlinearProblemLibrary, Test |
| 2 | + |
| 3 | +problems = NonlinearProblemLibrary.problems |
| 4 | +dicts = NonlinearProblemLibrary.dicts |
| 5 | + |
| 6 | +function test_on_library(problems, dicts, alg_ops, broken_tests, ϵ = 1e-5) |
| 7 | + for (idx, (problem, dict)) in enumerate(zip(problems, dicts)) |
| 8 | + x = dict["start"] |
| 9 | + res = similar(x) |
| 10 | + nlprob = NonlinearProblem(problem, x) |
| 11 | + @testset "$(dict["title"])" begin |
| 12 | + for alg in alg_ops |
| 13 | + sol = solve(nlprob, alg, abstol = 1e-15, reltol = 1e-15) |
| 14 | + problem(res, sol.u, nothing) |
| 15 | + broken = idx in broken_tests[alg] ? true : false |
| 16 | + @test norm(res)≤ϵ broken=broken |
| 17 | + end |
| 18 | + end |
| 19 | + end |
| 20 | +end |
| 21 | + |
| 22 | +# NewtonRaphson |
| 23 | +@testset "NewtonRaphson test problem library" begin |
| 24 | + alg_ops = (NewtonRaphson(),) |
| 25 | + |
| 26 | + # dictionary with indices of test problems where method does not converge to small residual |
| 27 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 28 | + broken_tests[alg_ops[1]] = [1, 6] |
| 29 | + |
| 30 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 31 | +end |
| 32 | + |
| 33 | +@testset "TrustRegion test problem library" begin |
| 34 | + alg_ops = (TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Simple), |
| 35 | + TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Fan), |
| 36 | + TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Hei), |
| 37 | + TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Yuan), |
| 38 | + TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.Bastin), |
| 39 | + TrustRegion(; radius_update_scheme = RadiusUpdateSchemes.NLsolve)) |
| 40 | + |
| 41 | + # dictionary with indices of test problems where method does not converge to small residual |
| 42 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 43 | + broken_tests[alg_ops[1]] = [6, 11, 21] |
| 44 | + broken_tests[alg_ops[2]] = [6, 11, 21] |
| 45 | + broken_tests[alg_ops[3]] = [1, 6, 11, 12, 15, 16, 21] |
| 46 | + broken_tests[alg_ops[4]] = [1, 6, 8, 11, 15, 16, 21, 22] |
| 47 | + broken_tests[alg_ops[5]] = [6, 21] |
| 48 | + broken_tests[alg_ops[6]] = [6, 21] |
| 49 | + |
| 50 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 51 | +end |
| 52 | + |
| 53 | +@testset "TrustRegion test problem library" begin |
| 54 | + alg_ops = (LevenbergMarquardt(), LevenbergMarquardt(; α_geodesic = 0.5)) |
| 55 | + |
| 56 | + # dictionary with indices of test problems where method does not converge to small residual |
| 57 | + broken_tests = Dict(alg => Int[] for alg in alg_ops) |
| 58 | + broken_tests[alg_ops[1]] = [3, 6, 11, 17, 21] |
| 59 | + broken_tests[alg_ops[2]] = [3, 6, 11, 21] |
| 60 | + |
| 61 | + test_on_library(problems, dicts, alg_ops, broken_tests) |
| 62 | +end |
0 commit comments