Skip to content

Specify reset! SolverCore and NLPModels #291

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

Merged
merged 1 commit into from
Apr 2, 2025
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
6 changes: 3 additions & 3 deletions src/fomo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ function SolverCore.reset!(solver::FomoSolver{T}) where {T}
solver
end

SolverCore.reset!(solver::FomoSolver, ::AbstractNLPModel) = reset!(solver)
SolverCore.reset!(solver::FomoSolver, ::AbstractNLPModel) = SolverCore.reset!(solver)

"""
fo(nlp; kwargs...)
Expand Down Expand Up @@ -407,7 +407,7 @@ function SolverCore.reset!(solver::FoSolver{T}) where {T}
solver
end

SolverCore.reset!(solver::FoSolver, ::AbstractNLPModel) = reset!(solver)
SolverCore.reset!(solver::FoSolver, ::AbstractNLPModel) = SolverCore.reset!(solver)

function SolverCore.solve!(
solver::Union{FoSolver, FomoSolver},
Expand Down Expand Up @@ -440,7 +440,7 @@ function SolverCore.solve!(
use_momentum = typeof(solver) <: FomoSolver
is_r2 = typeof(step_backend) <: r2_step

reset!(stats)
SolverCore.reset!(stats)
start_time = time()
set_time!(stats, 0.0)

Expand Down
8 changes: 4 additions & 4 deletions src/lbfgs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ function LBFGSSolver(nlp::M; kwargs...) where {T, V, M <: AbstractNLPModel{T, V}
end

function SolverCore.reset!(solver::LBFGSSolver)
reset!(solver.H)
LinearOperators.reset!(solver.H)
end

function SolverCore.reset!(solver::LBFGSSolver, nlp::AbstractNLPModel)
reset!(solver.H)
LinearOperators.reset!(solver.H)
solver.h = LineModel(nlp, solver.x, solver.d)
solver
end
Expand Down Expand Up @@ -169,7 +169,7 @@ function SolverCore.solve!(
error("lbfgs should only be called for unconstrained problems. Try tron instead")
end

reset!(stats)
SolverCore.reset!(stats)
start_time = time()
set_time!(stats, 0.0)

Expand All @@ -187,7 +187,7 @@ function SolverCore.solve!(
d = solver.d
h = solver.h
H = solver.H
reset!(H)
LinearOperators.reset!(H)

f, ∇f = objgrad!(nlp, x, ∇f)

Expand Down
2 changes: 1 addition & 1 deletion src/tron.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ function SolverCore.solve!(
μ₁ = value(solver.params.μ₁)
σ = value(solver.params.σ)

reset!(stats)
SolverCore.reset!(stats)
ℓ = nlp.meta.lvar
u = nlp.meta.uvar
n = nlp.meta.nvar
Expand Down
4 changes: 2 additions & 2 deletions src/tronls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ end
function SolverCore.reset!(solver::TronSolverNLS, nlp::AbstractNLPModel)
solver.A = jac_op_residual!(nlp, solver.xc, solver.Av, solver.Atv)
solver.AZ = solver.A * solver.ls_op
reset!(solver)
SolverCore.reset!(solver)
solver
end

Expand Down Expand Up @@ -285,7 +285,7 @@ function SolverCore.solve!(
μ₁ = value(solver.params.μ₁)
σ = value(solver.params.σ)

reset!(stats)
SolverCore.reset!(stats)
ℓ = nlp.meta.lvar
u = nlp.meta.uvar
n = nlp.meta.nvar
Expand Down
2 changes: 1 addition & 1 deletion src/trunk.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function SolverCore.solve!(
monotone = value(solver.params.monotone)
nm_itmax = value(solver.params.nm_itmax)

reset!(stats)
SolverCore.reset!(stats)
start_time = time()
set_time!(stats, 0.0)

Expand Down
2 changes: 1 addition & 1 deletion src/trunkls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function SolverCore.solve!(
monotone = value(solver.params.monotone)
nm_itmax = value(solver.params.nm_itmax)

reset!(stats)
SolverCore.reset!(stats)
start_time = time()
set_time!(stats, 0.0)

Expand Down
8 changes: 4 additions & 4 deletions test/allocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ if Sys.isunix()
end
with_logger(NullLogger()) do
SolverCore.solve!(solver, nlp, stats)
reset!(solver)
reset!(nlp)
SolverCore.reset!(solver)
NLPModels.reset!(nlp)
al = @wrappedallocs SolverCore.solve!(solver, nlp, stats)
@test al == 0
end
Expand All @@ -65,8 +65,8 @@ if Sys.isunix()
stats = GenericExecutionStats(nlp)
with_logger(NullLogger()) do
SolverCore.solve!(solver, nlp, stats)
reset!(solver)
reset!(nlp)
SolverCore.reset!(solver)
NLPModels.reset!(nlp)
al = @wrappedallocs SolverCore.solve!(solver, nlp, stats)
@test al == 0
end
Expand Down
8 changes: 4 additions & 4 deletions test/consistency.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ function consistency()

@testset "NLP with $mtd" for mtd in [trunk, lbfgs, tron, R2, fomo]
with_logger(NullLogger()) do
reset!(unlp)
NLPModels.reset!(unlp)
stats = mtd(unlp; args...)
@test stats isa GenericExecutionStats
@test stats.status == :first_order
reset!(unlp)
NLPModels.reset!(unlp)
stats = mtd(unlp; max_eval = 1)
@test stats.status == :max_eval
slow_nlp = ADNLPModel(x -> begin
Expand All @@ -30,7 +30,7 @@ function consistency()

@testset "Quasi-Newton NLP with $mtd" for mtd in [trunk, lbfgs, tron, R2, fomo]
with_logger(NullLogger()) do
reset!(qnlp)
NLPModels.reset!(qnlp)
stats = mtd(qnlp; args...)
@test stats isa GenericExecutionStats
@test stats.status == :first_order
Expand All @@ -42,7 +42,7 @@ function consistency()
stats = mtd(unls; args...)
@test stats isa GenericExecutionStats
@test stats.status == :first_order
reset!(unls)
NLPModels.reset!(unls)
stats = mtd(unls; max_eval = 1)
@test stats.status == :max_eval
slow_nls = ADNLSModel(x -> begin
Expand Down
4 changes: 2 additions & 2 deletions test/solvers/tronls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@test isapprox(stats.objective, 0, atol = 1e-6)
@test neval_jac_residual(model) == 0
stline = statsline(stats, [:objective, :dual_feas, :elapsed_time, :iter, :status])
reset!(model)
NLPModels.reset!(model)
end

@test_throws ErrorException tron(model, subsolver = :minres)
Expand All @@ -33,6 +33,6 @@ end
@test isapprox(stats.objective, 0, atol = 1e-6)
@test neval_jac_residual(model) == 0
stline = statsline(stats, [:objective, :dual_feas, :elapsed_time, :iter, :status])
reset!(model)
NLPModels.reset!(model)
end
end
4 changes: 2 additions & 2 deletions test/solvers/trunkls.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@test isapprox(stats.objective, 0, atol = 1e-6)
@test neval_jac_residual(model) == 0
stline = statsline(stats, [:objective, :dual_feas, :elapsed_time, :iter, :status])
reset!(model)
NLPModels.reset!(model)
end

@test_throws ErrorException trunk(model, subsolver_type = MinresSolver)
Expand All @@ -35,6 +35,6 @@ end
@test isapprox(stats.objective, 0, atol = 1e-6)
@test neval_jac_residual(model) == 0
stline = statsline(stats, [:objective, :dual_feas, :elapsed_time, :iter, :status])
reset!(model)
NLPModels.reset!(model)
end
end