Skip to content

Commit 47376e9

Browse files
🤖 Format .jl files (#67)
Co-authored-by: tmigot <[email protected]>
1 parent 76702c4 commit 47376e9

17 files changed

+876
-921
lines changed

docs/make.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ using Printf
55
using AdaptiveRegularization
66

77
pages = [
8-
"Introduction" => "index.md",
9-
"Tutorial" => "benchmark.md",
10-
"Do it yourself" => "doityourself.md",
11-
"Reference" => "reference.md",
8+
"Introduction" => "index.md",
9+
"Tutorial" => "benchmark.md",
10+
"Do it yourself" => "doityourself.md",
11+
"Reference" => "reference.md",
1212
]
1313

1414
makedocs(
15-
sitename = "AdaptiveRegularization.jl",
16-
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
17-
modules = [AdaptiveRegularization],
18-
pages = pages,
15+
sitename = "AdaptiveRegularization.jl",
16+
format = Documenter.HTML(prettyurls = get(ENV, "CI", nothing) == "true"),
17+
modules = [AdaptiveRegularization],
18+
pages = pages,
1919
)
2020

2121
deploydocs(
22-
repo = "github.com/JuliaSmoothOptimizers/AdaptiveRegularization.jl.git",
23-
push_preview = true,
24-
devbranch = "main",
22+
repo = "github.com/JuliaSmoothOptimizers/AdaptiveRegularization.jl.git",
23+
push_preview = true,
24+
devbranch = "main",
2525
)

src/AdaptiveRegularization.jl

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ include("./utils/utils.jl")
1414
include("./utils/increase_decrease.jl")
1515

1616
path = joinpath(dirname(@__FILE__), "SolveModel")
17-
files = filter(x -> x[(end-2):end] == ".jl", readdir(path))
17+
files = filter(x -> x[(end - 2):end] == ".jl", readdir(path))
1818
for file in files
19-
include("SolveModel/" * file)
19+
include("SolveModel/" * file)
2020
end
2121

2222
path = joinpath(dirname(@__FILE__), "PreProcess")
23-
files = filter(x -> x[(end-2):end] == ".jl", readdir(path))
23+
files = filter(x -> x[(end - 2):end] == ".jl", readdir(path))
2424
for file in files
25-
include("PreProcess/" * file)
25+
include("PreProcess/" * file)
2626
end
2727

2828
include("main.jl")
@@ -88,39 +88,34 @@ stats = TRARC(nlp)
8888
"""
8989
function TRARC end
9090

91-
function TRARC(nlp::AbstractNLPModel{T,S}; kwargs...) where {T,S}
92-
nlpstop = NLPStopping(nlp; optimality_check = (pb, state) -> norm(state.gx), kwargs...)
93-
nlpstop = TRARC(nlpstop; kwargs...)
94-
return stopping_to_stats(nlpstop)
91+
function TRARC(nlp::AbstractNLPModel{T, S}; kwargs...) where {T, S}
92+
nlpstop = NLPStopping(nlp; optimality_check = (pb, state) -> norm(state.gx), kwargs...)
93+
nlpstop = TRARC(nlpstop; kwargs...)
94+
return stopping_to_stats(nlpstop)
9595
end
9696

9797
for fun in union(keys(solvers_const), keys(solvers_nls_const))
98-
99-
ht, pt, sm, ka = merge(solvers_const, solvers_nls_const)[fun]
100-
@eval begin
101-
function $fun(nlpstop::NLPStopping; kwargs...)
102-
kw_list = Dict{Symbol,Any}()
103-
if $ka != ()
104-
for t in $ka
105-
push!(kw_list, t)
106-
end
107-
end
108-
merge!(kw_list, Dict(kwargs))
109-
TRARC(nlpstop; hess_type = $ht, pdata_type = $pt, solve_model = $sm, kw_list...)
98+
ht, pt, sm, ka = merge(solvers_const, solvers_nls_const)[fun]
99+
@eval begin
100+
function $fun(nlpstop::NLPStopping; kwargs...)
101+
kw_list = Dict{Symbol, Any}()
102+
if $ka != ()
103+
for t in $ka
104+
push!(kw_list, t)
110105
end
106+
end
107+
merge!(kw_list, Dict(kwargs))
108+
TRARC(nlpstop; hess_type = $ht, pdata_type = $pt, solve_model = $sm, kw_list...)
111109
end
112-
@eval begin
113-
function $fun(nlp::AbstractNLPModel{T,S}; kwargs...) where {T,S}
114-
nlpstop = NLPStopping(
115-
nlp;
116-
optimality_check = (pb, state) -> norm(state.gx),
117-
kwargs...,
118-
)
119-
nlpstop = $fun(nlpstop; kwargs...)
120-
return stopping_to_stats(nlpstop)
121-
end
110+
end
111+
@eval begin
112+
function $fun(nlp::AbstractNLPModel{T, S}; kwargs...) where {T, S}
113+
nlpstop = NLPStopping(nlp; optimality_check = (pb, state) -> norm(state.gx), kwargs...)
114+
nlpstop = $fun(nlpstop; kwargs...)
115+
return stopping_to_stats(nlpstop)
122116
end
123-
@eval export $fun
117+
end
118+
@eval export $fun
124119
end
125120

126121
end # module

src/PreProcess/PreProcessKARC.jl

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
11
function preprocess(PData::PDataKARC, Hop, g, gNorm2, calls, max_calls, α)
2-
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
3-
nshifts = PData.nshifts
4-
shifts = PData.shifts
2+
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
3+
nshifts = PData.nshifts
4+
shifts = PData.shifts
55

6-
n = length(g)
7-
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
8-
atol = PData.cgatol(ζ, ξ, maxtol, mintol, gNorm2)
9-
rtol = PData.cgrtol(ζ, ξ, maxtol, mintol, gNorm2)
6+
n = length(g)
7+
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
8+
atol = PData.cgatol(ζ, ξ, maxtol, mintol, gNorm2)
9+
rtol = PData.cgrtol(ζ, ξ, maxtol, mintol, gNorm2)
1010

11-
nshifts = length(shifts)
12-
cb = (slv) -> begin
13-
for i = 1:length(shifts)
14-
if !slv.not_cv[i] && (norm(slv.x[i]) / shifts[i] - α > 0)
15-
return true
16-
end
17-
end
18-
return false
11+
nshifts = length(shifts)
12+
cb = (slv) -> begin
13+
for i = 1:length(shifts)
14+
if !slv.not_cv[i] && (norm(slv.x[i]) / shifts[i] - α > 0)
15+
return true
16+
end
1917
end
20-
solver = PData.solver
21-
cg_lanczos_shift!(
22-
solver,
23-
Hop,
24-
g,
25-
shifts,
26-
itmax = min(max_calls - sum(calls), 2 * n),
27-
atol = atol,
28-
rtol = rtol,
29-
verbose = 0,
30-
check_curvature = true,
31-
callback = cb,
32-
)
18+
return false
19+
end
20+
solver = PData.solver
21+
cg_lanczos_shift!(
22+
solver,
23+
Hop,
24+
g,
25+
shifts,
26+
itmax = min(max_calls - sum(calls), 2 * n),
27+
atol = atol,
28+
rtol = rtol,
29+
verbose = 0,
30+
check_curvature = true,
31+
callback = cb,
32+
)
3333

34-
PData.indmin = 0
35-
PData.positives .= solver.converged
36-
for i = 1:nshifts
37-
PData.xShift[i] .= .-solver.x[i]
38-
PData.norm_dirs[i] = norm(solver.x[i]) # Get it from cg_lanczos?
39-
end
40-
PData.shifts .= shifts
41-
PData.nshifts = nshifts
42-
PData.OK = sum(solver.converged) != 0 # at least one system was solved
34+
PData.indmin = 0
35+
PData.positives .= solver.converged
36+
for i = 1:nshifts
37+
PData.xShift[i] .= .-solver.x[i]
38+
PData.norm_dirs[i] = norm(solver.x[i]) # Get it from cg_lanczos?
39+
end
40+
PData.shifts .= shifts
41+
PData.nshifts = nshifts
42+
PData.OK = sum(solver.converged) != 0 # at least one system was solved
4343

44-
return PData
44+
return PData
4545
end

src/PreProcess/PreProcessTRK.jl

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
function preprocess(PData::PDataTRK, Hop, g, gNorm2, calls, max_calls, α)
2-
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
3-
nshifts = PData.nshifts
4-
shifts = PData.shifts
2+
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
3+
nshifts = PData.nshifts
4+
shifts = PData.shifts
55

6-
n = length(g)
7-
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
8-
cgatol = PData.cgatol(ζ, ξ, maxtol, mintol, gNorm2)
9-
cgrtol = PData.cgrtol(ζ, ξ, maxtol, mintol, gNorm2)
6+
n = length(g)
7+
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
8+
cgatol = PData.cgatol(ζ, ξ, maxtol, mintol, gNorm2)
9+
cgrtol = PData.cgrtol(ζ, ξ, maxtol, mintol, gNorm2)
1010

11-
nshifts = length(shifts)
12-
solver = PData.solver
11+
nshifts = length(shifts)
12+
solver = PData.solver
1313

14-
cb = (slv) -> begin
15-
if slv.converged[1]
16-
return norm(slv.x[1]) α
17-
else
18-
for i = 1:length(shifts)
19-
if !slv.not_cv[i] && (norm(slv.x[i]) - α > 0)
20-
return true
21-
end
22-
end
14+
cb = (slv) -> begin
15+
if slv.converged[1]
16+
return norm(slv.x[1]) α
17+
else
18+
for i = 1:length(shifts)
19+
if !slv.not_cv[i] && (norm(slv.x[i]) - α > 0)
20+
return true
2321
end
24-
return false
22+
end
2523
end
26-
cg_lanczos_shift!(
27-
solver,
28-
Hop,
29-
g,
30-
shifts,
31-
itmax = min(max_calls - sum(calls), 2 * n),
32-
atol = cgatol,
33-
rtol = cgrtol,
34-
verbose = 0,
35-
check_curvature = true,
36-
callback = cb,
37-
)
24+
return false
25+
end
26+
cg_lanczos_shift!(
27+
solver,
28+
Hop,
29+
g,
30+
shifts,
31+
itmax = min(max_calls - sum(calls), 2 * n),
32+
atol = cgatol,
33+
rtol = cgrtol,
34+
verbose = 0,
35+
check_curvature = true,
36+
callback = cb,
37+
)
3838

39-
PData.indmin = 0
40-
PData.positives .= solver.converged
41-
for i = 1:nshifts
42-
@. PData.xShift[i] = -solver.x[i]
43-
PData.norm_dirs[i] = norm(solver.x[i]) # Get it from cg_lanczos?
44-
end
45-
PData.shifts .= shifts
46-
PData.nshifts = nshifts
47-
PData.OK = sum(solver.converged) != 0 # at least one system was solved
39+
PData.indmin = 0
40+
PData.positives .= solver.converged
41+
for i = 1:nshifts
42+
@. PData.xShift[i] = -solver.x[i]
43+
PData.norm_dirs[i] = norm(solver.x[i]) # Get it from cg_lanczos?
44+
end
45+
PData.shifts .= shifts
46+
PData.nshifts = nshifts
47+
PData.OK = sum(solver.converged) != 0 # at least one system was solved
4848

49-
return PData
49+
return PData
5050
end

src/SolveModel/SolveModelKARC.jl

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
function solve_modelKARC(X::PDataKARC, H, g, gNorm2, calls, max_calls, α::T) where {T}
2-
# target value should be close to satisfy αλ=||d||
3-
start = findfirst(X.positives)
4-
if isnothing(start)
5-
start = 1
6-
end
7-
if VERSION < v"1.7.0"
8-
positives = collect(start:length(X.positives))
9-
target = [(abs* X.shifts[i] - X.norm_dirs[i])) for i in positives]
10-
else
11-
positives = start:length(X.positives)
12-
target = ((abs* X.shifts[i] - X.norm_dirs[i])) for i in positives)
13-
end
2+
# target value should be close to satisfy αλ=||d||
3+
start = findfirst(X.positives)
4+
if isnothing(start)
5+
start = 1
6+
end
7+
if VERSION < v"1.7.0"
8+
positives = collect(start:length(X.positives))
9+
target = [(abs* X.shifts[i] - X.norm_dirs[i])) for i in positives]
10+
else
11+
positives = start:length(X.positives)
12+
target = ((abs* X.shifts[i] - X.norm_dirs[i])) for i in positives)
13+
end
1414

15-
# pick the closest shift to the target within positive definite H+λI
16-
indmin = argmin(target)
17-
X.indmin = start + indmin - 1
18-
p_imin = X.indmin
19-
X.d .= X.xShift[p_imin]
20-
X.λ = X.shifts[p_imin]
15+
# pick the closest shift to the target within positive definite H+λI
16+
indmin = argmin(target)
17+
X.indmin = start + indmin - 1
18+
p_imin = X.indmin
19+
X.d .= X.xShift[p_imin]
20+
X.λ = X.shifts[p_imin]
2121

22-
return X.d, X.λ
22+
return X.d, X.λ
2323
end
Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,29 @@
1-
function solve_modelNLSST_TR(
2-
PData::PDataNLSST,
3-
Jx,
4-
Fx,
5-
norm_∇f,
6-
calls,
7-
max_calls,
8-
δ::T,
9-
) where {T}
10-
# cas particulier Steihaug-Toint
11-
# ϵ = sqrt(eps(T)) # * 100.0 # old
12-
# cgtol = max(ϵ, min(cgtol, 9 * cgtol / 10, 0.01 * norm(g)^(1.0 + PData.ζ))) # old
1+
function solve_modelNLSST_TR(PData::PDataNLSST, Jx, Fx, norm_∇f, calls, max_calls, δ::T) where {T}
2+
# cas particulier Steihaug-Toint
3+
# ϵ = sqrt(eps(T)) # * 100.0 # old
4+
# cgtol = max(ϵ, min(cgtol, 9 * cgtol / 10, 0.01 * norm(g)^(1.0 + PData.ζ))) # old
135

14-
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
15-
n = length(Fx)
16-
# precision = max(1e-12, min(0.5, (norm_∇f^ζ)))
17-
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
18-
cgatol = PData.cgatol(ζ, ξ, maxtol, mintol, norm_∇f)
19-
cgrtol = PData.cgrtol(ζ, ξ, maxtol, mintol, norm_∇f)
6+
ζ, ξ, maxtol, mintol = PData.ζ, PData.ξ, PData.maxtol, PData.mintol
7+
n = length(Fx)
8+
# precision = max(1e-12, min(0.5, (norm_∇f^ζ)))
9+
# Tolerance used in Assumption 2.6b in the paper ( ξ > 0, 0 < ζ ≤ 1 )
10+
cgatol = PData.cgatol(ζ, ξ, maxtol, mintol, norm_∇f)
11+
cgrtol = PData.cgrtol(ζ, ξ, maxtol, mintol, norm_∇f)
2012

21-
solver = PData.solver
22-
Krylov.solve!(
23-
solver,
24-
Jx,
25-
Fx,
26-
atol = cgatol,
27-
rtol = cgrtol,
28-
radius = δ,
29-
itmax = min(max_calls - sum(calls), max(2 * n, 50)),
30-
verbose = 0,
31-
)
13+
solver = PData.solver
14+
Krylov.solve!(
15+
solver,
16+
Jx,
17+
Fx,
18+
atol = cgatol,
19+
rtol = cgrtol,
20+
radius = δ,
21+
itmax = min(max_calls - sum(calls), max(2 * n, 50)),
22+
verbose = 0,
23+
)
3224

33-
@. PData.d = -solver.x
34-
PData.OK = solver.stats.solved
25+
@. PData.d = -solver.x
26+
PData.OK = solver.stats.solved
3527

36-
return PData.d, PData.λ
28+
return PData.d, PData.λ
3729
end

0 commit comments

Comments
 (0)