Skip to content

Commit

Permalink
add RegularizedExecutionStats
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxenceGollier committed Dec 31, 2024
1 parent 1c94830 commit b5cbdc9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/R2_alg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ For advanced usage, first define a solver "R2Solver" to preallocate the memory u
solver = R2Solver(reg_nlp)
solve!(solver, reg_nlp)
stats = GenericExecutionStats(reg_nlp)
stats = RegularizedExecutionStats(reg_nlp)
solver = R2Solver(reg_nlp)
solve!(solver, reg_nlp, stats)
Expand Down Expand Up @@ -292,7 +292,7 @@ function R2(reg_nlp::AbstractRegularizedNLPModel; kwargs...)
kwargs_dict = Dict(kwargs...)
max_iter = pop!(kwargs_dict, :max_iter, 10000)
solver = R2Solver(reg_nlp, max_iter = max_iter)
stats = GenericExecutionStats(reg_nlp.model) # TODO: change this to `stats = GenericExecutionStats(reg_nlp)` when FHist etc. is ruled out.
stats = GenericExecutionStats(reg_nlp.model) # TODO: change this to `stats = RegularizedExecutionStats(reg_nlp)` when FHist etc. is ruled out.
cb = pop!(
kwargs_dict,
:callback,
Expand Down
5 changes: 2 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export GenericExecutionStats
export RegularizedExecutionStats

import SolverCore.GenericExecutionStats

Expand Down Expand Up @@ -32,9 +32,8 @@ Construct a GenericExecutionStats object from an AbstractRegularizedNLPModel.
More specifically, construct a GenericExecutionStats on the NLPModel of reg_nlp and add three solver_specific entries namely :smooth_obj, :nonsmooth_obj and :xi.
This is useful for reducing the number of allocations when calling solve!(..., reg_nlp, stats) and should be used by default.
Warning: This should *not* be used when adding other solver_specific entries that do not have the current scalar type.
For instance, when one adds the history of the objective value as a solver_specific entry (which has Vector{T} type), this will cause an error and `GenericExecutionStats(reg_nlp.model)` should be used instead.
"""
function GenericExecutionStats(reg_nlp :: AbstractRegularizedNLPModel{T, V}) where{T, V}
function RegularizedExecutionStats(reg_nlp :: AbstractRegularizedNLPModel{T, V}) where{T, V}
stats = GenericExecutionStats(reg_nlp.model, solver_specific = Dict{Symbol, T}())
set_solver_specific!(stats, :smooth_obj, T(Inf))
set_solver_specific!(stats, :nonsmooth_obj, T(Inf))
Expand Down
2 changes: 1 addition & 1 deletion test/test_allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end
for solver (:R2Solver,)
reg_nlp = RegularizedNLPModel(bpdn, h)
solver = eval(solver)(reg_nlp)
stats = GenericExecutionStats(reg_nlp)
stats = RegularizedExecutionStats(reg_nlp)
@test @wrappedallocs(solve!(solver, reg_nlp, stats)) == 0
end
end
Expand Down

0 comments on commit b5cbdc9

Please sign in to comment.