Skip to content

Commit 48419a7

Browse files
solve allocation issue with keyword args for the subsolver while keeping it flexible
1 parent 14a511a commit 48419a7

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/R2N.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ mutable struct R2NSolver{
2727
subsolver::ST
2828
subpb::PB
2929
substats::GenericExecutionStats{T, V, V, T}
30+
subkwargs::Dict{Symbol, Real}
3031
end
3132

3233
function R2NSolver(
@@ -70,6 +71,7 @@ function R2NSolver(
7071
subpb = RegularizedNLPModel(sub_nlp, ψ)
7172
substats = RegularizedExecutionStats(subpb)
7273
subsolver = subsolver(subpb)
74+
subkwargs = Dict{Symbol, Real}()
7375

7476
return R2NSolver{T, typeof(ψ), V, typeof(subsolver), typeof(subpb)}(
7577
xk,
@@ -90,6 +92,7 @@ function R2NSolver(
9092
subsolver,
9193
subpb,
9294
substats,
95+
subkwargs
9396
)
9497
end
9598

@@ -136,6 +139,7 @@ For advanced usage, first define a solver "R2NSolver" to preallocate the memory
136139
- `η2::T = T(0.9)`: very successful iteration threshold;
137140
- `γ::T = T(3)`: regularization parameter multiplier, σ := σ/γ when the iteration is very successful and σ := σγ when the iteration is unsuccessful;
138141
- `θ::T = 1/(1 + eps(T)^(1 / 5))`: is the model decrease fraction with respect to the decrease of the Cauchy model;
142+
- `sub_kwargs::Dict{Symbol}`: a dictionary containing the keyword arguments to be sent to the subsolver. The solver will fail if invalid keyword arguments are provided to the subsolver;
139143
- `compute_opnorm::Bool = false`: whether the operator norm of Bₖ should be computed at each iteration. If false, a Rayleigh quotient is computed instead. The first option causes the solver to converge in fewer iterations but the computational cost per iteration is larger;
140144
- `m_monotone::Int = 1`: monotonicity parameter. By default, R2N is monotone but the non-monotone variant will be used if `m_monotone > 1`;
141145
@@ -219,6 +223,7 @@ function SolverCore.solve!(
219223
γ::T = T(3),
220224
β::T = 1 / eps(T),
221225
θ::T = 1/(1 + eps(T)^(1 / 5)),
226+
sub_kwargs::Dict{Symbol, Real} = solver.subkwargs,
222227
compute_opnorm::Bool = false,
223228
) where {T, V, G}
224229
reset!(stats)
@@ -362,10 +367,11 @@ function SolverCore.solve!(
362367
solver.subpb.model.σ = σk
363368
isa(solver.subsolver, R2DHSolver) && (solver.subsolver.D.d[1] = 1/ν₁)
364369
if isa(solver.subsolver, R2Solver) #FIXME
365-
solve!(solver.subsolver, solver.subpb, solver.substats; x = s1, atol = sub_atol, ν = ν₁)
370+
sub_kwargs[] = ν₁
366371
else
367-
solve!(solver.subsolver, solver.subpb, solver.substats; x = s1, atol = sub_atol, σk = σk)
372+
sub_kwargs[:σk] = σk
368373
end
374+
solve!(solver.subsolver, solver.subpb, solver.substats; x = s1, atol = sub_atol, sub_kwargs...)
369375

370376

371377
s .= solver.substats.solution

0 commit comments

Comments
 (0)