Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ function tests()
readdir(rootdir),
)
for dir in dirs
subdirs = readdir(joinpath(rootdir, dir))
subdirs = filter(y -> isdir(joinpath(rootdir, dir, y)), readdir(joinpath(rootdir, dir)))
for subdir in subdirs
prefix = joinpath(rootdir, dir, subdir, subdir)
prefix = joinpath(rootdir, dir, subdir, "index")
println("Verifying files in $dir/$subdir")
for suffix in [".jmd", ".html", ".ipynb", ".jl"]
spc = " "^(6 - length(suffix))
print(" $subdir$suffix$spc exists…… ")
@assert isfile(prefix * suffix)
println("✓")
end
# Only require the source markdown and Project.toml to be present
print(" index.jmd exists…… ")
@assert isfile(prefix * ".jmd")
println("✓")

print(" Project.toml exists…… ")
@assert isfile(joinpath(rootdir, dir, subdir, "Project.toml"))
println("✓")
end
end
end
Expand Down
37 changes: 29 additions & 8 deletions tutorials/advanced-jsosolvers/index.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ tags: ["solvers", "krylov", "benchmark", "least squares"]
author: "Tangi Migot"
---

# Comparing subsolvers for nonlinear least squares JSOSolvers solvers
# Comparing subsolvers for nonlinear least squares in JSOSolvers

This tutorial showcases some advanced features of solvers in JSOSolvers.

```julia
using JSOSolvers
```

We benchmark different subsolvers used in the solvers TRUNK for unconstrained nonlinear least squares problems.
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.

```julia
Expand All @@ -38,27 +38,48 @@ For this task, several solvers are available.
JSOSolvers.trunkls_allowed_subsolvers
```

This benchmark could also be followed for the solver TRON where the following subsolver are available.
This benchmark could also be followed for the solver TRON where the following subsolvers are available.

```julia
JSOSolvers.tronls_allowed_subsolvers
```

These linear least squares solvers are implemented in the package [Krylov.jl](https://github.com/JuliaSmoothOptimizers/Krylov.jl).
For detailed descriptions of each subsolver's algorithm and when to use it, see the [Krylov.jl documentation](https://jso.dev/Krylov.jl/stable/).

```julia
using Krylov
```

For example, to call TRUNK with an explicit subsolver and tolerances:

```julia
stats = trunk(nls; subsolver = :cgls)
```

We define a dictionary of the different solvers that will be benchmarked.
We consider here four variants of TRUNK using the different subsolvers.

The same subsolver selection pattern applies to TRON’s least-squares specialization:

```julia
stats_tron = tron(nls; subsolver = :lsmr, rtol = RTOL, atol = ATOL, max_time = max_time)
```

```julia
solvers = Dict(
:trunk_cgls => nlp -> trunk(nlp; subsolver = :cgls),
:trunk_crls => nlp -> trunk(nlp; subsolver = :crls),
:trunk_lsqr => nlp -> trunk(nlp; subsolver = :lsqr),
:trunk_lsmr => nlp -> trunk(nlp; subsolver = :lsmr)
)
```

```julia
RTOL = 1e-6; ATOL = 1e-8; max_time = 60.0
solvers = Dict(
:trunk_cgls => model -> trunk(model, subsolver_type = CglsSolver),
:trunk_crls => model -> trunk(model, subsolver_type = CrlsSolver),
:trunk_lsqr => model -> trunk(model, subsolver_type = LsqrSolver),
:trunk_lsmr => model -> trunk(model, subsolver_type = LsmrSolver)
:trunkls_lsmr => nlp -> trunk(nlp; rtol = RTOL, atol = ATOL, subsolver = :lsmr, max_time = max_time),
:trunkls_cg => nlp -> trunk(nlp; rtol = RTOL, atol = ATOL, subsolver = :cg, max_time = max_time),
)
```

Expand Down Expand Up @@ -91,5 +112,5 @@ profile_solvers(stats, costs, costnames)
```

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.
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.
Loading