Skip to content

Commit

Permalink
Add unbounded objective tests (#268)
Browse files Browse the repository at this point in the history
* add unbounded below obj test. Fix unbounded test in fomo.

* add unbounded below obj test. Fix unbounded test in fomo.

* standardize fomo :unbounded condition,
add objective value test in unbounded tests.

* rename: fk -> f0
  • Loading branch information
d-monnet authored Apr 9, 2024
1 parent f6374fe commit cfffe18
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/fomo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,8 @@ function SolverCore.solve!(
d = use_momentum ? solver.d : solver.g # g = d if no momentum
p = use_momentum ? solver.p : nothing # not used if no momentum
set_iter!(stats, 0)
set_objective!(stats, obj(nlp, x))
f0 = obj(nlp, x)
set_objective!(stats, f0)

grad!(nlp, x, ∇fk)
norm_∇fk = norm(∇fk)
Expand All @@ -288,6 +289,9 @@ function SolverCore.solve!(
solver.α = init_alpha(norm_∇fk, step_backend)

# Stopping criterion:
fmin = min(-one(T), f0) / eps(T)
unbounded = f0 < fmin

ϵ = atol + rtol * norm_∇fk
optimal = norm_∇fk ϵ
step_param_name = is_r2 ? "σ" : "Δ"
Expand Down Expand Up @@ -321,6 +325,7 @@ function SolverCore.solve!(
nlp,
elapsed_time = stats.elapsed_time,
optimal = optimal,
unbounded = unbounded,
max_eval = max_eval,
iter = stats.iter,
max_iter = max_iter,
Expand All @@ -346,10 +351,7 @@ function SolverCore.solve!(
step_underflow = x == c # step addition underfow on every dimensions, should happen before solver.α == 0
ΔTk = ((oneT - βmax) * norm_∇fk^2 + βmax * mdot∇f) * λk # = dot(d,∇fk) * λk with momentum, ‖∇fk‖²λk without momentum
fck = obj(nlp, c)
if fck == -Inf
set_status!(stats, :unbounded)
break
end
unbounded = fck < fmin
ρk = (stats.objective - fck) / ΔTk
# Update regularization parameters
if ρk >= η2
Expand Down Expand Up @@ -406,6 +408,7 @@ function SolverCore.solve!(
nlp,
elapsed_time = stats.elapsed_time,
optimal = optimal,
unbounded = unbounded,
max_eval = max_eval,
iter = stats.iter,
max_iter = max_iter,
Expand Down
13 changes: 13 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ end
end
end

@testset "Test unbounded below" begin
@testset "$fun" for fun in (R2, fomo, lbfgs, tron, trunk)
T = Float64
x0 = [T(0)]
f(x) = -exp(x[1])
nlp = ADNLPModel(f, x0)

stats = eval(fun)(nlp)
@test stats.status == :unbounded
@test stats.objective < -one(T)/eps(T)
end
end

include("restart.jl")
include("callback.jl")
include("consistency.jl")
Expand Down

0 comments on commit cfffe18

Please sign in to comment.