LineSearches.jl
LineSearches.jl copied to clipboard
AssertionError raised at runtime
This line https://github.com/JuliaNLSolvers/LineSearches.jl/blob/62ffafe6f4dd68032e42b11c31b8e4e24c4c9ae4/src/hagerzhang.jl#L503
is raising an AssertionError
in my code.
AssertionError: isfinite(phi_d) && isfinite(gphi)
Stacktrace:
[1] bisect!(ϕdϕ::LineSearches.var"#ϕdϕ#6"{Optim.ManifoldObjective{OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Vector{Float64}, Vector{Float64}}, alphas::Vector{Float64}, values::Vector{Float64}, slopes::Vector{Float64}, ia::Int64, ib::Int64, phi_lim::Float64, display::Int64)
@ LineSearches ~/.julia/packages/LineSearches/Ki4c5/src/hagerzhang.jl:503
[2] (::LineSearches.HagerZhang{Float64, Base.RefValue{Bool}})(ϕ::Function, ϕdϕ::LineSearches.var"#ϕdϕ#6"{Optim.ManifoldObjective{OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}}, Vector{Float64}, Vector{Float64}, Vector{Float64}}, c::Float64, phi_0::Float64, dphi_0::Float64)
@ LineSearches ~/.julia/packages/LineSearches/Ki4c5/src/hagerzhang.jl:201
[3] HagerZhang
@ ~/.julia/packages/LineSearches/Ki4c5/src/hagerzhang.jl:101 [inlined]
[4] perform_linesearch!(state::Optim.BFGSState{Vector{Float64}, Matrix{Float64}, Float64, Vector{Float64}}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, d::Optim.ManifoldObjective{OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}})
@ Optim ~/.julia/packages/Optim/uwNqi/src/utilities/perform_linesearch.jl:59
[5] update_state!(d::OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, state::Optim.BFGSState{Vector{Float64}, Matrix{Float64}, Float64, Vector{Float64}}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat})
@ Optim ~/.julia/packages/Optim/uwNqi/src/multivariate/solvers/first_order/bfgs.jl:129
[6] optimize(d::OnceDifferentiable{Float64, Vector{Float64}, Vector{Float64}}, initial_x::Vector{Float64}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, Nothing}, state::Optim.BFGSState{Vector{Float64}, Matrix{Float64}, Float64, Vector{Float64}})
@ Optim ~/.julia/packages/Optim/uwNqi/src/multivariate/optimize/optimize.jl:57
[7] optimize
@ ~/.julia/packages/Optim/uwNqi/src/multivariate/optimize/optimize.jl:35 [inlined]
[8] optimize(f::Function, g::Function, initial_x::Vector{Float64}, method::BFGS{LineSearches.InitialStatic{Float64}, LineSearches.HagerZhang{Float64, Base.RefValue{Bool}}, Nothing, Nothing, Flat}, options::Optim.Options{Float64, Nothing}; inplace::Bool, autodiff::Symbol)
@ Optim ~/.julia/packages/Optim/uwNqi/src/multivariate/optimize/interface.jl:155
The Julia docs state
An assert might be disabled at various optimization levels. Assert should therefore only be used as a debugging tool and not used for authentication verification (e.g., verifying passwords), nor should side effects needed for the function to work correctly be used inside of asserts.
I find this a useful convention so that assertion statements help to reason statically about the behavior of code. If LineSearches.jl needs a macro for runtime validation, perhaps a different macro could be used?
This is a fair comment. We should not fail hard here.
I don't currently have an opinion about whether an error should be thrown versus another strategy. Just that if an error is thrown I'd rather it not be AssertionError
because I like to be able to interpret @assert(p)
statically as "p is always true" eg as here.
I don't currently have an opinion about whether an error should be thrown versus another strategy. Just that if an error is thrown I'd rather it not be
AssertionError
because I like to be able to interpret@assert(p)
statically as "p is always true" eg as here.
Fair, I understand the distinction. I still agree that an assertion is not appropriate here.
Has this changed? I am still getting this error. How can one get around this? I am optimizing a function using Oprim package, which uses LineSearch.jl for the linesearch.