Skip to content

Commit 24d1be6

Browse files
committed
Made linesearch_nan_max_iterations and linesearch_nan_factor part of the Options.
1 parent 6505b6e commit 24d1be6

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/base/options.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ const EXTENDED_TRACE::Bool = false
101101
const SHOW_EVERY::Int = 1
102102
const VERBOSITY::Int = 1
103103

104+
const LINESEARCH_NAN_MAX_ITERATIONS = 10
105+
const LINESEARCH_NAN_FACTOR = 0.5
106+
104107
"""
105108
Options
106109
@@ -129,6 +132,8 @@ Configurable options with defaults (values 0 and NaN indicate unlimited):
129132
- `extended_trace = $(EXTENDED_TRACE)`,
130133
- `show_every = $(SHOW_EVERY)`,
131134
- `verbosity = $(VERBOSITY)`
135+
- `linesearch_nan_max_iterations = $(LINESEARCH_NAN_MAX_ITERATIONS)`
136+
- `linesearch_nan_factor = $(LINESEARCH_NAN_FACTOR)`
132137
133138
Some of the constants are defined by the functions [`default_tolerance`](@ref) and [`absolute_tolerance`](@ref).
134139
"""
@@ -155,6 +160,8 @@ struct Options{T}
155160
extended_trace::Bool
156161
show_every::Int
157162
verbosity::Int
163+
linesearch_nan_max_iterations::Int
164+
linesearch_nan_factor::T
158165
end
159166

160167
function Options(T = Float64;
@@ -179,7 +186,9 @@ function Options(T = Float64;
179186
store_trace::Bool = STORE_TRACE,
180187
extended_trace::Bool = EXTENDED_TRACE,
181188
show_every::Integer = SHOW_EVERY,
182-
verbosity::Integer = VERBOSITY)
189+
verbosity::Integer = VERBOSITY,
190+
linesearch_nan_max_iterations::Integer = LINESEARCH_NAN_MAX_ITERATIONS,
191+
linesearch_nan_factor::AbstractFloat = LINESEARCH_NAN_FACTOR)
183192

184193
show_every = show_every > 0 ? show_every : 1
185194

@@ -204,7 +213,9 @@ function Options(T = Float64;
204213
store_trace,
205214
extended_trace,
206215
show_every,
207-
verbosity)
216+
verbosity,
217+
linesearch_nan_max_iterations,
218+
linesearch_nan_factor)
208219
end
209220

210221
function Base.show(io::IO, o::SimpleSolvers.Options)

src/nonlinear/nonlinear_solver.jl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
using Printf
22

3-
const LINESEARCH_NAN_MAX_ITERATIONS = 10
4-
const LINESEARCH_NAN_FACTOR = 0.5
5-
63
"""
74
NonlinearSolver
85
@@ -128,12 +125,12 @@ function solver_step!(x::AbstractVector{T}, s::NonlinearSolver{T}, state::Nonlin
128125
# The following loop checks if the RHS contains any NaNs.
129126
# If so, the direction vector is reduced by a factor of LINESEARCH_NAN_FACTOR.
130127
update!(state, x, value!(value(state), nonlinearproblem(s), x, params), iteration_number(s))
131-
for _ in 1:LINESEARCH_NAN_MAX_ITERATIONS
128+
for _ in 1:linesearch(s).config.linesearch_nan_max_iterations
132129
solution(cache(s)) .= solution(state) .+ direction(cache(s))
133130
value!(value(cache(s)), nonlinearproblem(s), solution(cache(s)), params)
134131
if any(isnan, value(cache(s)))
135132
(s.config.verbosity 2 && @warn "NaN detected in nonlinear solver. Reducing length of direction vector.")
136-
direction(cache(s)) .*= T(LINESEARCH_NAN_FACTOR)
133+
direction(cache(s)) .*= T(linesearch(s).config.linesearch_nan_factor)
137134
else
138135
break
139136
end

0 commit comments

Comments
 (0)