|
1 | | -<!doctype html> <html lang= en class= has-navbar-fixed-top > <meta charset= UTF-8 > <meta name= viewport content=" width=device-width, initial-scale=1" > <link rel= stylesheet href=" /libs/highlight/github.min.css" > <link rel= stylesheet href=" /css/styles.css" > <style> html { font-size: 17px;} . franklin-content { position: relative; padding-left: 8%; padding-right: 5%; line-height: 1.35em;} @media ( min-width: 940px) { . franklin-content { width: 100%; margin-left: auto; margin-right: auto;} } @media ( max-width: 768px) { . franklin-content { padding-left: 6%; padding-right: 6%;} } </style> <link rel= icon href=" /assets/favicon.png" > <title>Comparing subsolvers for NLS solvers </title> <script src=" /libs/highlight/highlight.pack.js" ></script> <script src=" https://unpkg.com/clipboard@2/dist/clipboard.min.js" ></script> <script type= module src=" https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js" ></script> <script nomodule src=" https://unpkg.com/[email protected]/dist/ionicons/ionicons.js" ></script> <script> hljs.getLanguage('julia').keywords.custom = 'obj grad hess AbstractNLPModel'; </script> <nav class=" navbar is-primary is-fixed-top" role= navigation aria-label=" main navigation" > <div class= navbar-brand > <a class= navbar-item href="" > <img src=" /assets/jso.png" > </a> <a role= button class= navbar-burger aria-label= menu aria-expanded= false data-target= navbarBasicExample > <span aria-hidden= true ></span> <span aria-hidden= true ></span> <span aria-hidden= true ></span> </a> </div> <div id= navbarBasicExample class= navbar-menu > <div class= navbar-start > <a class= navbar-item href=" /" > Home </a> <a class= navbar-item href=" /news-and-blogposts/" > News and Blogposts </a> <a class= navbar-item href=" /tutorials/" > Tutorials </a> <div class=" navbar-item has-dropdown is-hoverable" > <a class= navbar-link href=" /ecosystems/index.html" > Ecosystems </a> <div class= navbar-dropdown > <a class= navbar-item href=" /ecosystems/linear-algebra/" > Linear Algebra </a> <a class= navbar-item href=" /ecosystems/models/" > Models </a> <a class= navbar-item href=" /ecosystems/solvers/" > Solvers </a> </div> </div> <a class= navbar-item href=" /references/" > References </a> <a class= navbar-item href=" /contributing/" > Contributing </a> </div> <div class= navbar-end > <a class=" navbar-item icon-text" href=" https://github.com/JuliaSmoothOptimizers/juliasmoothoptimizers.github.io/issues" > <span class= icon > <ion-icon size= large name= logo-github ></ion-icon> </span> <span>Report an issue </span> </a> </div> </div> </nav> <section class= section > <div class= container > <div class= content > <div class= franklin-content ><h1 id= title ><a href=" #title" class= header-anchor >Comparing subsolvers for NLS solvers </a></h1></p> <p><div class= author >by Tangi Migot </div> <p><a href=" https://jso.dev/OptimizationProblems.jl/stable/" ><img src=" https://img.shields.io/badge/OptimizationProblems-0.7.3-8b0000?style=flat-square&labelColor=cb3c33" alt=" OptimizationProblems 0.7.3" /></a> <a href=" https://jso.dev/SolverBenchmark.jl/stable/" ><img src=" https://img.shields.io/badge/SolverBenchmark-0.6.0-006400?style=flat-square&labelColor=389826" alt=" SolverBenchmark 0.6.0" /></a> <img src=" https://img.shields.io/badge/Plots-1.39.0-000?style=flat-square&labelColor=999" alt=" Plots 1.39.0" /> <a href=" https://jso.dev/ADNLPModels.jl/stable/" ><img src=" https://img.shields.io/badge/ADNLPModels-0.7.0-8b0000?style=flat-square&labelColor=cb3c33" alt=" ADNLPModels 0.7.0" /></a> <a href=" https://jso.dev/Krylov.jl/stable/" ><img src=" https://img.shields.io/badge/Krylov-0.9.5-4b0082?style=flat-square&labelColor=9558b2" alt=" Krylov 0.9.5" /></a> <a href=" https://jso.dev/JSOSolvers.jl/stable/" ><img src=" https://img.shields.io/badge/JSOSolvers-0.11.0-006400?style=flat-square&labelColor=389826" alt=" JSOSolvers 0.11.0" /></a></p> <h1 id= comparing_subsolvers_for_nonlinear_least_squares_jsosolvers_solvers ><a href=" #comparing_subsolvers_for_nonlinear_least_squares_jsosolvers_solvers" class= header-anchor >Comparing subsolvers for nonlinear least squares JSOSolvers solvers </a></h1> <p>This tutorial showcases some advanced features of solvers in JSOSolvers. </p> <pre><code class= language-julia >using JSOSolvers </code></pre> |
2 | | -<p>We benchmark different subsolvers used in the solvers TRUNK for unconstrained nonlinear least squares problems. The first step is to select a set of problems that are nonlinear least squares.</p> |
| 1 | +<!doctype html> <html lang= en class= has-navbar-fixed-top > <meta charset= UTF-8 > <meta name= viewport content=" width=device-width, initial-scale=1" > <link rel= stylesheet href=" /libs/highlight/github.min.css" > <link rel= stylesheet href=" /css/styles.css" > <style> html { font-size: 17px;} . franklin-content { position: relative; padding-left: 8%; padding-right: 5%; line-height: 1.35em;} @media ( min-width: 940px) { . franklin-content { width: 100%; margin-left: auto; margin-right: auto;} } @media ( max-width: 768px) { . franklin-content { padding-left: 6%; padding-right: 6%;} } </style> <link rel= icon href=" /assets/favicon.png" > <title>Comparing subsolvers for NLS solvers </title> <script src=" /libs/highlight/highlight.pack.js" ></script> <script src=" https://unpkg.com/clipboard@2/dist/clipboard.min.js" ></script> <script type= module src=" https://unpkg.com/[email protected]/dist/ionicons/ionicons.esm.js" ></script> <script nomodule src=" https://unpkg.com/[email protected]/dist/ionicons/ionicons.js" ></script> <script> hljs.getLanguage('julia').keywords.custom = 'obj grad hess AbstractNLPModel'; </script> <nav class=" navbar is-primary is-fixed-top" role= navigation aria-label=" main navigation" > <div class= navbar-brand > <a class= navbar-item href="" > <img src=" /assets/jso.png" > </a> <a role= button class= navbar-burger aria-label= menu aria-expanded= false data-target= navbarBasicExample > <span aria-hidden= true ></span> <span aria-hidden= true ></span> <span aria-hidden= true ></span> </a> </div> <div id= navbarBasicExample class= navbar-menu > <div class= navbar-start > <a class= navbar-item href=" /" > Home </a> <a class= navbar-item href=" /news-and-blogposts/" > News and Blogposts </a> <a class= navbar-item href=" /tutorials/" > Tutorials </a> <div class=" navbar-item has-dropdown is-hoverable" > <a class= navbar-link href=" /ecosystems/index.html" > Ecosystems </a> <div class= navbar-dropdown > <a class= navbar-item href=" /ecosystems/linear-algebra/" > Linear Algebra </a> <a class= navbar-item href=" /ecosystems/models/" > Models </a> <a class= navbar-item href=" /ecosystems/solvers/" > Solvers </a> </div> </div> <a class= navbar-item href=" /references/" > References </a> <a class= navbar-item href=" /contributing/" > Contributing </a> </div> <div class= navbar-end > <a class=" navbar-item icon-text" href=" https://github.com/JuliaSmoothOptimizers/juliasmoothoptimizers.github.io/issues" > <span class= icon > <ion-icon size= large name= logo-github ></ion-icon> </span> <span>Report an issue </span> </a> </div> </div> </nav> <section class= section > <div class= container > <div class= content > <div class= franklin-content ><h1 id= title ><a href=" #title" class= header-anchor >Comparing subsolvers for NLS solvers </a></h1></p> <p><div class= author >by Tangi Migot </div> <p><a href=" https://jso.dev/OptimizationProblems.jl/stable/" ><img src=" https://img.shields.io/badge/OptimizationProblems-0.7.4-8b0000?style=flat-square&labelColor=cb3c33" alt=" OptimizationProblems 0.7.4" /></a> <a href=" https://jso.dev/SolverBenchmark.jl/stable/" ><img src=" https://img.shields.io/badge/SolverBenchmark-0.6.2-006400?style=flat-square&labelColor=389826" alt=" SolverBenchmark 0.6.2" /></a> <img src=" https://img.shields.io/badge/Plots-1.41.1-000?style=flat-square&labelColor=999" alt=" Plots 1.41.1" /> <a href=" https://jso.dev/ADNLPModels.jl/stable/" ><img src=" https://img.shields.io/badge/ADNLPModels-0.7.2-8b0000?style=flat-square&labelColor=cb3c33" alt=" ADNLPModels 0.7.2" /></a> <a href=" https://jso.dev/Krylov.jl/stable/" ><img src=" https://img.shields.io/badge/Krylov-0.10.2-4b0082?style=flat-square&labelColor=9558b2" alt=" Krylov 0.10.2" /></a> <a href=" https://jso.dev/JSOSolvers.jl/stable/" ><img src=" https://img.shields.io/badge/JSOSolvers-0.14.3-006400?style=flat-square&labelColor=389826" alt=" JSOSolvers 0.14.3" /></a></p> <h1 id= comparing_subsolvers_for_nonlinear_least_squares_in_jsosolvers ><a href=" #comparing_subsolvers_for_nonlinear_least_squares_in_jsosolvers" class= header-anchor >Comparing subsolvers for nonlinear least squares in JSOSolvers </a></h1> <p>This tutorial showcases some advanced features of solvers in JSOSolvers. </p> <pre><code class= language-julia >using JSOSolvers </code></pre> |
| 2 | +<p>We benchmark different subsolvers used in the solver TRUNK for unconstrained nonlinear least squares problems. The first step is to select a set of problems that are nonlinear least squares.</p> |
3 | 3 | <pre><code class=language-julia >using ADNLPModels |
4 | 4 | using OptimizationProblems |
5 | 5 | using OptimizationProblems.ADNLPProblems |
6 | 6 | df = OptimizationProblems.meta |
7 | | -names = df[(df.objtype .== :least_squares) .& (df.contype .== :unconstrained), :name] |
8 | | -ad_problems = (eval(Meta.parse(problem))(use_nls = true) for problem ∈ names)</code></pre> |
9 | | -<pre><code class=language-plaintext >Base.Generator{Vector{String}, Main.var"##WeaveSandBox#292".var"#1#2"}(Main.var"##WeaveSandBox#292".var"#1#2"(), ["arglina", "arglinb", "bard", "bdqrtic", "beale", "bennett5", "boxbod", "brownal", "br |
| 7 | +problem_names = df[(df.objtype .== :least_squares) .& (df.contype .== :unconstrained), :name] |
| 8 | +ad_problems = (eval(Meta.parse(problem))(use_nls = true) for problem ∈ problem_names)</code></pre> |
| 9 | +<pre><code class=language-plaintext >Base.Generator{Vector{String}, Main.var"##WeaveSandBox#277".var"#2#3"}(Main.var"##WeaveSandBox#277".var"#2#3"(), ["arglina", "arglinb", "bard", "bdqrtic", "beale", "bennett5", "boxbod", "brownal", "br |
10 | 10 | ownbs", "brownden" … "power", "rat42", "rat43", "rozman1", "sbrybnd", "spmsrtls", "thurber", "tquartic", "vibrbeam", "watson"])</code></pre> |
11 | 11 | <p>These problems are <a href="https://github.com/JuliaSmoothOptimizers/ADNLPModels.jl"><code>ADNLSModel</code></a> so derivatives are generated using automatic differentiation.</p> |
12 | 12 | <pre><code class=language-julia >nls = first(ad_problems) |
13 | 13 | typeof(nls)</code></pre> |
14 | 14 | <pre><code class=language-plaintext >ADNLPModels.ADNLSModel{Float64, Vector{Float64}, Vector{Int64}}</code></pre> |
15 | 15 | <p>The solvers TRON and TRUNK are trust-region based methods that compute a search direction by means of solving iteratively a linear least squares problem. For this task, several solvers are available.</p> |
16 | 16 | <pre><code class=language-julia >JSOSolvers.trunkls_allowed_subsolvers</code></pre> |
17 | | -<pre><code class=language-plaintext >4-element Vector{UnionAll}: |
18 | | - Krylov.CglsSolver |
19 | | - Krylov.CrlsSolver |
20 | | - Krylov.LsqrSolver |
21 | | - Krylov.LsmrSolver</code></pre> |
22 | | -<p>This benchmark could also be followed for the solver TRON where the following subsolver are available.</p> |
| 17 | +<pre><code class=language-plaintext >(:cgls, :crls, :lsqr, :lsmr)</code></pre> |
| 18 | +<p>This benchmark could also be followed for the solver TRON where the following subsolvers are available.</p> |
23 | 19 | <pre><code class=language-julia >JSOSolvers.tronls_allowed_subsolvers</code></pre> |
24 | | -<pre><code class=language-plaintext >4-element Vector{UnionAll}: |
25 | | - Krylov.CglsSolver |
26 | | - Krylov.CrlsSolver |
27 | | - Krylov.LsqrSolver |
28 | | - Krylov.LsmrSolver</code></pre> |
29 | | -<p>These linear least squares solvers are implemented in the package <a href="https://github.com/JuliaSmoothOptimizers/Krylov.jl">Krylov.jl</a>.</p> |
30 | | -<pre><code class=language-julia >using Krylov</code></pre> |
| 20 | +<pre><code class=language-plaintext >(:cgls, :crls, :lsqr, :lsmr)</code></pre> |
| 21 | +<p>These linear least squares solvers are implemented in the package <a href="https://github.com/JuliaSmoothOptimizers/Krylov.jl">Krylov.jl</a>. For detailed descriptions of each subsolver's algorithm and when to use it, see the <a href="https://jso.dev/Krylov.jl/stable/">Krylov.jl documentation</a>.</p> |
31 | 22 | <p>We define a dictionary of the different solvers that will be benchmarked. We consider here four variants of TRUNK using the different subsolvers.</p> |
| 23 | +<p>For example, to call TRUNK with an explicit subsolver:</p> |
| 24 | +<pre><code class=language-julia >stats = trunk(nls, subsolver = :cgls)</code></pre> |
| 25 | +<pre><code class=language-plaintext >"Execution stats: first-order stationary"</code></pre> |
| 26 | +<p>The same subsolver selection pattern applies to TRON's least-squares specialization:</p> |
| 27 | +<pre><code class=language-julia >stats_tron = tron(nls, subsolver = :lsmr)</code></pre> |
| 28 | +<pre><code class=language-plaintext >"Execution stats: first-order stationary"</code></pre> |
| 29 | +<p>Now we define the solver dictionary for benchmarking:</p> |
32 | 30 | <pre><code class=language-julia >solvers = Dict( |
33 | | - :trunk_cgls => model -> trunk(model, subsolver_type = CglsSolver), |
34 | | - :trunk_crls => model -> trunk(model, subsolver_type = CrlsSolver), |
35 | | - :trunk_lsqr => model -> trunk(model, subsolver_type = LsqrSolver), |
36 | | - :trunk_lsmr => model -> trunk(model, subsolver_type = LsmrSolver) |
| 31 | + :trunk_cgls => model -> trunk(model, subsolver = :cgls), |
| 32 | + :trunk_crls => model -> trunk(model, subsolver = :crls), |
| 33 | + :trunk_lsqr => model -> trunk(model, subsolver = :lsqr), |
| 34 | + :trunk_lsmr => model -> trunk(model, subsolver = :lsmr) |
37 | 35 | )</code></pre> |
38 | 36 | <pre><code class=language-plaintext >Dict{Symbol, Function} with 4 entries: |
39 | | - :trunk_lsqr => #5 |
40 | | - :trunk_cgls => #3 |
41 | | - :trunk_crls => #4 |
42 | | - :trunk_lsmr => #6</code></pre> |
| 37 | + :trunk_lsqr => #12 |
| 38 | + :trunk_cgls => #8 |
| 39 | + :trunk_crls => #10 |
| 40 | + :trunk_lsmr => #14</code></pre> |
43 | 41 | <p>Using <a href="https://github.com/JuliaSmoothOptimizers/SolverBenchmark.jl"><code>SolverBenchmark.jl</code></a> functionalities, the solvers are executed over all the test problems.</p> |
44 | 42 | <pre><code class=language-julia >using SolverBenchmark |
45 | 43 | stats = bmark_solvers(solvers, ad_problems)</code></pre> |
46 | 44 | <pre><code class=language-plaintext >Dict{Symbol, DataFrames.DataFrame} with 4 entries: |
47 | | - :trunk_lsqr => 66×39 DataFrame… |
48 | | - :trunk_cgls => 66×39 DataFrame… |
49 | | - :trunk_crls => 66×39 DataFrame… |
50 | | - :trunk_lsmr => 66×39 DataFrame…</code></pre> |
| 45 | + :trunk_lsqr => 66×40 DataFrame… |
| 46 | + :trunk_cgls => 66×40 DataFrame… |
| 47 | + :trunk_crls => 66×40 DataFrame… |
| 48 | + :trunk_lsmr => 66×40 DataFrame…</code></pre> |
51 | 49 | <p>The result is stored in a dictionary of <code>DataFrame</code> that can be used to analyze the results.</p> |
52 | 50 | <pre><code class=language-julia >first_order(df) = df.status .== :first_order |
53 | 51 | unbounded(df) = df.status .== :unbounded |
54 | 52 | solved(df) = first_order(df) .| unbounded(df) |
55 | 53 |
|
56 | 54 | costnames = ["time"] |
57 | 55 | costs = [df -> .!solved(df) .* Inf .+ df.elapsed_time]</code></pre> |
58 | | -<pre><code class=language-plaintext >1-element Vector{Main.var"##WeaveSandBox#292".var"#11#12"}: |
59 | | - #11 (generic function with 1 method)</code></pre> |
| 56 | +<pre><code class=language-plaintext >1-element Vector{Main.var"##WeaveSandBox#277".var"#17#18"}: |
| 57 | + #17 (generic function with 1 method)</code></pre> |
60 | 58 | <p>We compare the four variants based on their execution time. More advanced comparisons could include the number of evaluations of the objective, gradient, or Hessian-vector products.</p> |
61 | 59 | <pre><code class=language-julia >using Plots |
62 | 60 | gr() |
63 | 61 |
|
64 | 62 | profile_solvers(stats, costs, costnames)</code></pre> |
65 | | -<p><img src="figures/index_10_1.png" alt="" /></p> |
66 | | -<p>The CRLS and CGLS variants are the ones solving more problems, and even though the difference is rather small the CGLS variant is consistently faster which seems to indicate that it is the most appropriate subsolver for TRUNK. The size of the problems were rather small here, so this should be confirmed on larger instance. Moreover, the results may vary depending on the origin of the test problems.</p> |
| 63 | +<p><img src="figures/index_11_1.png" alt="" /></p> |
| 64 | +<p>The CRLS and CGLS variants are the ones solving more problems, and even though the difference is rather small the CGLS variant is consistently faster which seems to indicate that it is the most appropriate subsolver for TRUNK. The size of the problems was rather small here, so this should be confirmed on larger instances. Moreover, the results may vary depending on the origin of the test problems.</p> |
67 | 65 | </div> |
68 | 66 | </div> |
69 | 67 | </div> |
|
0 commit comments