From f6ac521e16f5db979c4269790ee1041bb7605d3d Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 25 Sep 2023 10:29:49 -0400 Subject: [PATCH 1/3] add new methods --- .../NonlinearProblem/nonlinear_solver_23_tests.jmd | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd index e70bbfd94..b8a1fc38a 100644 --- a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd +++ b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd @@ -25,13 +25,17 @@ solvers = [ Dict(:alg=>NewtonRaphson()), Dict(:alg=>LevenbergMarquardt()), Dict(:alg=>CMINPACK(method=:hybr)), Dict(:alg=>CMINPACK(method=:lm)), - Dict(:alg=>NLSolveJL())] + Dict(:alg=>NLSolveJL(method=:newton)), + Dict(:alg=>NLSolveJL()), + Dict(:alg=>NLSolveJL(method=:anderson))] solvernames = ["Newton Raphson"; "Newton Trust Region"; "Levenberg-Marquardt"; "Modified Powell (CMINPACK)"; "Levenberg-Marquardt (CMINPACK)"; - "Newton Trust Region (NLSolveJL)"]; + "Newton Raphson (NLSolveJL)"; + "Newton Trust Region (NLSolveJL)"; + "Anderson acceleration (NLSolveJL)"]; ``` Sets tolerances. ```julia @@ -55,12 +59,12 @@ function check_solver(prob, solver, solvername) try true_sol = solve(prob.prob, solver[:alg]; abstol=1e-18, reltol=1e-18, maxiters=10000000) if !SciMLBase.successful_retcode(true_sol.retcode) - Base.printstyled("[Warn] Solver $solvername returned retcode $(true_sol.retcode)."; color=:red) + Base.printstyled("[Warn] Solver $solvername returned retcode $(true_sol.retcode).\n"; color=:red) return false end WorkPrecisionSet(prob.prob, [1e-4, 1e-12], [1e-4, 1e-12], [solver]; names=[solvername], numruns=20, appxsol=true_sol, error_estimate=:l2, maxiters=10000000) catch e - Base.printstyled("[Warn] Solver $solvername threw an error: $e."; color=:red) + Base.printstyled("[Warn] Solver $solvername threw an error: $e.\n"; color=:red) return false end return true From 79e75577dcfe2dae330886b18c4effffa1a880af Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 25 Sep 2023 10:32:28 -0400 Subject: [PATCH 2/3] add KINSOL --- benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd index b8a1fc38a..84bd37216 100644 --- a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd +++ b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd @@ -9,7 +9,9 @@ These benchmarks comapres the runtime and error for a range of nonlinear solvers - NonlinearSolve.jl's Levenberg-Marquardt method (`LevenbergMarquardt()`). - MINPACK's [Modified Powell](https://docs.sciml.ai/NonlinearSolve/stable/api/minpack/#NonlinearSolveMINPACK.CMINPACK) method (`CMINPACK(method=:hybr)`). - MINPACK's [Levenberg-Marquardt](https://docs.sciml.ai/NonlinearSolve/stable/api/minpack/#NonlinearSolveMINPACK.CMINPACK) method (`CMINPACK(method=:lm)`). +- NLSolveJL's [Newton Raphson](https://docs.sciml.ai/NonlinearSolve/stable/api/nlsolve/#Solver-API) (`NLSolveJL(method=:newton)`). - NLSolveJL's [Newton trust region](https://docs.sciml.ai/NonlinearSolve/stable/api/nlsolve/#Solver-API) (`NLSolveJL()`). +- NLSolveJL's [Anderson acceleration](https://docs.sciml.ai/NonlinearSolve/stable/api/nlsolve/#Solver-API) (`NLSolveJL(method=:anderson)`). - Sundials's [Newton-Krylov](https://docs.sciml.ai/NonlinearSolve/stable/api/sundials/#Solver-API) method (`KINSOL()`). # Setup @@ -27,7 +29,8 @@ solvers = [ Dict(:alg=>NewtonRaphson()), Dict(:alg=>CMINPACK(method=:lm)), Dict(:alg=>NLSolveJL(method=:newton)), Dict(:alg=>NLSolveJL()), - Dict(:alg=>NLSolveJL(method=:anderson))] + Dict(:alg=>NLSolveJL(method=:anderson)), + Dict(:alg=>KINSOL())] solvernames = ["Newton Raphson"; "Newton Trust Region"; "Levenberg-Marquardt"; @@ -35,7 +38,8 @@ solvernames = ["Newton Raphson"; "Levenberg-Marquardt (CMINPACK)"; "Newton Raphson (NLSolveJL)"; "Newton Trust Region (NLSolveJL)"; - "Anderson acceleration (NLSolveJL)"]; + "Anderson acceleration (NLSolveJL)"; + "Newton-Krylov (Sundials)"]; ``` Sets tolerances. ```julia From 222baf6e20a9524c30925c74123765afb432a931 Mon Sep 17 00:00:00 2001 From: Torkel Date: Mon, 25 Sep 2023 20:11:33 -0400 Subject: [PATCH 3/3] plot fix and better plots options --- benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd index 84bd37216..8484b519b 100644 --- a/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd +++ b/benchmarks/NonlinearProblem/nonlinear_solver_23_tests.jmd @@ -49,8 +49,8 @@ reltols = 1.0 ./ 10.0 .^ (4:12); Set plotting defaults. ```julia default(framestyle=:box,legend=:topleft,gridwidth=2, guidefontsize=12, legendfontsize=9, lw=2) -colors = [1 2 3 4 5 6 7] -markershapes = [:circle :rect :heptagon :cross :xcross :utriangle :star5]; +markershapes = [:rect, :pentagon, :hexagon, :utriangle, :dtriangle, :star4, :star5, :star7, :circle] +colors = [:darkslategray1, :royalblue1, :blue3, :coral2, :red3, :olivedrab1, :green2, :forestgreen, :darkgoldenrod1]; ``` Function for determening which solvers can solve a given problem. ```julia