@@ -7,7 +7,7 @@ mutable struct R2NSolver{
77 G <: ShiftedProximableFunction ,
88 V <: AbstractVector{T} ,
99 ST <: AbstractOptimizationSolver ,
10- PB <: AbstractRegularizedNLPModel
10+ PB <: AbstractRegularizedNLPModel ,
1111} <: AbstractOptimizationSolver
1212 xk:: V
1313 ∇fk:: V
@@ -28,7 +28,11 @@ mutable struct R2NSolver{
2828 substats:: GenericExecutionStats{T, V, V, T}
2929end
3030
31- function R2NSolver (reg_nlp:: AbstractRegularizedNLPModel{T, V} ; subsolver = R2Solver, m_monotone:: Int = 1 ) where {T, V}
31+ function R2NSolver (
32+ reg_nlp:: AbstractRegularizedNLPModel{T, V} ;
33+ subsolver = R2Solver,
34+ m_monotone:: Int = 1 ,
35+ ) where {T, V}
3236 x0 = reg_nlp. model. meta. x0
3337 l_bound = reg_nlp. model. meta. lvar
3438 u_bound = reg_nlp. model. meta. uvar
@@ -53,15 +57,12 @@ function R2NSolver(reg_nlp::AbstractRegularizedNLPModel{T, V}; subsolver = R2Sol
5357 end
5458 m_fh_hist = fill (T (- Inf ), m_monotone - 1 )
5559
56- ψ = has_bnds ? shifted (reg_nlp. h, xk, l_bound_m_x, u_bound_m_x, reg_nlp. selected) : shifted (reg_nlp. h, xk)
60+ ψ =
61+ has_bnds ? shifted (reg_nlp. h, xk, l_bound_m_x, u_bound_m_x, reg_nlp. selected) :
62+ shifted (reg_nlp. h, xk)
5763
5864 Bk = hess_op (reg_nlp. model, x0)
59- sub_nlp = R2NModel (
60- Bk,
61- ∇fk,
62- T (1 ),
63- x0
64- )
65+ sub_nlp = R2NModel (Bk, ∇fk, T (1 ), x0)
6566 subpb = RegularizedNLPModel (sub_nlp, ψ)
6667 substats = RegularizedExecutionStats (subpb)
6768 subsolver = subsolver (subpb)
@@ -83,10 +84,9 @@ function R2NSolver(reg_nlp::AbstractRegularizedNLPModel{T, V}; subsolver = R2Sol
8384 m_fh_hist,
8485 subsolver,
8586 subpb,
86- substats
87+ substats,
8788 )
8889end
89-
9090
9191"""
9292 R2N(reg_nlp; kwargs…)
@@ -212,9 +212,9 @@ function SolverCore.solve!(
212212 ν:: T = eps (T)^ (1 / 5 ),
213213 γ:: T = T (3 ),
214214 β:: T = 1 / eps (T),
215- θ:: T = 1 / (1 + eps (T)^ (1 / 5 )),
216- kwargs...
217- ) where {T, V, G}
215+ θ:: T = 1 / (1 + eps (T)^ (1 / 5 )),
216+ kwargs... ,
217+ ) where {T, V, G}
218218 reset! (stats)
219219
220220 # Retrieve workspace
@@ -263,7 +263,7 @@ function SolverCore.solve!(
263263 @info log_header (
264264 [:outer , :inner , :fx , :hx , :xi , :ρ , :σ , :normx , :norms , :normB , :arrow ],
265265 [Int, Int, T, T, T, T, T, T, T, T, Char],
266- hdr_override = Dict {Symbol, String} (
266+ hdr_override = Dict {Symbol, String} (
267267 :fx => " f(x)" ,
268268 :hx => " h(x)" ,
269269 :xi => " √(ξ1/ν)" ,
@@ -294,7 +294,7 @@ function SolverCore.solve!(
294294
295295 ν₁ = θ / (λmax + σk)
296296 ν_sub = ν₁
297-
297+
298298 sqrt_ξ1_νInv = one (T)
299299
300300 @. mν∇fk = - ν₁ * ∇fk
@@ -305,7 +305,7 @@ function SolverCore.solve!(
305305 set_objective! (stats, fk + hk)
306306 set_solver_specific! (stats, :smooth_obj , fk)
307307 set_solver_specific! (stats, :nonsmooth_obj , hk)
308- m_monotone > 1 && (m_fh_hist[stats. iter% (m_monotone - 1 ) + 1 ] = fk + hk)
308+ m_monotone > 1 && (m_fh_hist[stats. iter % (m_monotone - 1 ) + 1 ] = fk + hk)
309309
310310 φ1 = let ∇fk = ∇fk
311311 d -> dot (∇fk, d)
@@ -328,7 +328,7 @@ function SolverCore.solve!(
328328 (ξ1 < 0 && sqrt_ξ1_νInv > neg_tol) &&
329329 error (" R2N: prox-gradient step should produce a decrease but ξ1 = $(ξ1) " )
330330 atol += rtol * sqrt_ξ1_νInv # make stopping test absolute and relative
331-
331+
332332 set_status! (
333333 stats,
334334 get_status (
@@ -348,20 +348,19 @@ function SolverCore.solve!(
348348 done = stats. status != :unknown
349349
350350 while ! done
351+ sub_atol = stats. iter == 0 ? 1.0e-3 : min (sqrt_ξ1_νInv ^ (1.5 ), sqrt_ξ1_νInv * 1e-3 )
351352
352- sub_atol = stats. iter == 0 ? 1.0e-3 : min (sqrt_ξ1_νInv ^ (1.5 ) , sqrt_ξ1_νInv * 1e-3 )
353-
354353 solver. subpb. model. σ = σk
355354 isa (solver. subsolver, R2DHSolver) && (solver. subsolver. D. d[1 ] = 1 / ν₁)
356355 ν_sub = isa (solver. subsolver, R2DHSolver) ? 1 / σk : ν₁
357356 solve! (
358- solver. subsolver,
359- solver. subpb,
357+ solver. subsolver,
358+ solver. subpb,
360359 solver. substats;
361360 x = s1,
362361 atol = sub_atol,
363362 ν = ν_sub,
364- kwargs...
363+ kwargs... ,
365364 )
366365
367366 s .= solver. substats. solution
@@ -424,7 +423,7 @@ function SolverCore.solve!(
424423 push! (nlp, s, ∇fk⁻)
425424 end
426425 solver. subpb. model. B = hess_op (nlp, xk)
427-
426+
428427 λmax, found_λ = opnorm (solver. subpb. model. B)
429428 found_λ || error (" operator norm computation failed" )
430429
@@ -438,25 +437,25 @@ function SolverCore.solve!(
438437 if ρk < η1 || ρk == Inf
439438 σk = σk * γ
440439 end
441-
440+
442441 ν₁ = θ / (λmax + σk)
443- m_monotone > 1 && (m_fh_hist[stats. iter% (m_monotone - 1 ) + 1 ] = fk + hk)
442+ m_monotone > 1 && (m_fh_hist[stats. iter % (m_monotone - 1 ) + 1 ] = fk + hk)
444443
445444 set_objective! (stats, fk + hk)
446445 set_solver_specific! (stats, :smooth_obj , fk)
447446 set_solver_specific! (stats, :nonsmooth_obj , hk)
448447 set_iter! (stats, stats. iter + 1 )
449448 set_time! (stats, time () - start_time)
450449
451- @. mν∇fk = - ν₁ * ∇fk
450+ @. mν∇fk = - ν₁ * ∇fk
452451 prox! (s1, ψ, mν∇fk, ν₁)
453452 mks = mk1 (s1)
454453
455454 ξ1 = hk - mks + max (1 , abs (hk)) * 10 * eps ()
456455
457456 sqrt_ξ1_νInv = ξ1 ≥ 0 ? sqrt (ξ1 / ν₁) : sqrt (- ξ1 / ν₁)
458457 solved = (ξ1 < 0 && sqrt_ξ1_νInv ≤ neg_tol) || (ξ1 ≥ 0 && sqrt_ξ1_νInv ≤ atol)
459-
458+
460459 (ξ1 < 0 && sqrt_ξ1_νInv > neg_tol) &&
461460 error (" R2N: prox-gradient step should produce a decrease but ξ1 = $(ξ1) " )
462461 set_status! (
@@ -501,4 +500,4 @@ function SolverCore.solve!(
501500 set_solution! (stats, xk)
502501 set_residuals! (stats, zero (eltype (xk)), sqrt_ξ1_νInv)
503502 return stats
504- end
503+ end
0 commit comments