Skip to content

Commit

Permalink
Use atol and rtol (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmigot authored Feb 20, 2023
1 parent a649416 commit 584cc98
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
3 changes: 2 additions & 1 deletion docs/src/benchmark.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ solvers = Dict(
),
:cannoles => nlp -> cannoles(
nlp,
ϵtol = 1e-5,
atol = 0.0,
rtol = 1e-5,
),
)
Expand Down
5 changes: 3 additions & 2 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ Find below a list of the main options of `cannoles`.
```
| Parameters | Type | Default | Description |
| -------------------- | ------------- | --------------- | -------------------------------------------------- |
| ϵtol | AbstractFloat | √eps(T) | tolerance. |
| atol | AbstractFloat | √eps(T) | absolute tolerance. |
| rtol | AbstractFloat | √eps(T) | relative tolerance. |
| unbounded_threshold | AbstractFloat | -1e5 | below this threshold the problem is unbounded. |
| max_eval | Integer | 100000 | evaluation limit, e.g. `neval_residual(nls) + neval_cons(nls) > max_eval` |
| max_time | AbstractFloat | 30. | maximum number of seconds. |
Expand Down Expand Up @@ -48,7 +49,7 @@ using CaNNOLeS, ADNLPModels
# Rosenbrock
nls = ADNLSModel(x -> [x[1] - 1; 10 * (x[2] - x[1]^2)], [-1.2; 1.0], 2)
stats = cannoles(nls, ϵtol = 1e-5, x = ones(2))
stats = cannoles(nls, atol = 1e-5, x = ones(2))
```

```@example ex1
Expand Down
7 changes: 5 additions & 2 deletions src/CaNNOLeS.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ or even pre-allocate the output:
- `max_eval::Real = 100000`: maximum number of evaluations computed by `neval_residual(nls) + neval_cons(nls)`;
- `max_time::Float64 = 30.0`: maximum time limit in seconds;
- `max_inner::Int = 10000`: maximum number of inner iterations;
- `ϵtol::Real = √eps(T)`: stopping tolerance;
- `atol::T = √eps(T)`: absolute tolerance;
- `rtol::T = √eps(T)`: relative tolerance: the algorithm uses `ϵtol := atol + rtol * ‖∇F(x⁰)ᵀF(x⁰) - ∇c(x⁰)ᵀλ⁰‖`;
- `Fatol::T = √eps(T)`: absolute tolerance on the residual;
- `Frtol::T = eps(T)`: relative tolerance on the residual, the algorithm stops when ‖F(xᵏ)‖ ≤ Fatol + Frtol * ‖F(x⁰)‖ and ‖c(xᵏ)‖∞ ≤ √ϵtol;
- `verbose::Int = 0`: if > 0, display iteration details every `verbose` iteration;
Expand Down Expand Up @@ -391,7 +392,8 @@ function SolverCore.solve!(
max_eval::Real = 100000,
max_time::Real = 30.0,
max_inner::Int = 10000,
ϵtol::Real = eps(T),
atol::T = eps(T),
rtol::T = eps(T),
Fatol::Real = eps(T),
Frtol::Real = eps(T),
verbose::Integer = 0,
Expand Down Expand Up @@ -488,6 +490,7 @@ function SolverCore.solve!(

smax = T(100.0)
ϵF = Fatol + Frtol * 2 * fx # fx = 0.5‖F(x)‖²
ϵtol= atol + rtol * normdual
ϵc = sqrt(ϵtol)

# Small residual
Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,14 @@ end
)
stats = GenericExecutionStats(nls)
solver = CaNNOLeSSolver(nls, linsolve = :ldlfactorizations)
solve!(solver, nls, stats, ϵtol = 1e-15, Fatol = 1e-6, Frtol = 0.0)
solve!(solver, nls, stats, atol = 1e-15, Fatol = 1e-6, Frtol = 0.0)
@test stats.status_reliable && stats.status == :small_residual
@test stats.objective_reliable && isapprox(stats.objective, 0, atol = 1e-6)

reset!(nls)
stats = GenericExecutionStats(nls)
solver = CaNNOLeSSolver(nls)
solve!(solver, nls, stats, x = [0.99999, 0.99999], ϵtol = 1e-15, Fatol = 1e-6, Frtol = 0.0)
solve!(solver, nls, stats, x = [0.99999, 0.99999], atol = 1e-15, Fatol = 1e-6, Frtol = 0.0)
@test stats.status_reliable && stats.status == :small_residual
@test stats.objective_reliable && isapprox(stats.objective, 0, atol = 1e-6)
end
Expand Down

0 comments on commit 584cc98

Please sign in to comment.