Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unbounded objective tests #268

Merged
merged 5 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you work in Float64, this isn’t an especially large number in absolute value. Float64 can represent values up to about 1.0e+308. It would be better to use floatmax() here. Effectively, when f0 < -floatmax(Float64), it means that f0 == Inf. So you could declare unboundedness either if f0 == Inf or f0 < floatmax(eltype(x)) / 2 (for example).

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
tmigot marked this conversation as resolved.
Show resolved Hide resolved
@test stats.objective < -one(T)/eps(T)
end
end

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