# Optimization Error:

**URL:** <https://discourse.julialang.org/t/optimization-error/77358>\
**Category:** Optimization (Mathematical)\
**Tags:** optim\
**Created:** [March 3, 2022, 1:46pm UTC](https://discourse.julialang.org/t/optimization-error/77358 "2022-03-03T13:46:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eriklw](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@Eriklw](https://discourse.julialang.org/u/Eriklw)\
**Post date:** [March 3, 2022, 1:46pm UTC](https://discourse.julialang.org/t/optimization-error/77358/1 "2022-03-03T13:46:03Z")

</div>

I am minimizing a function with the Optim package. I am supplying a gradient (that is calculated using AD). I am using the LBFGS() option. However the following error keeps occuring:

```julia
AssertionError: isfinite(phi_c) && isfinite(dphi_c)

Stacktrace:
  [1] secant2!(ϕdϕ::LineSearches.var"#ϕdϕ#6"{Optim.ManifoldObjective{OnceDifferentiable{Float64, Array{Float64, 5}, Array{Float64, 5}}}, Array{Float64, 5}, Array{Float64, 5}, Array{Float64, 5}}, alphas::Vector{Float64}, values::Vector{Float64}, slopes::Vector{Float64}, ia::Int64, ib::Int64, phi_lim::Float64, delta::Float64, sigma::Float64, display::Int64)
    @ LineSearches C:\Users\weerd\.julia\packages\LineSearches\Ki4c5\src\hagerzhang.jl:369
  [2] (::HagerZhang{Float64, Base.RefValue{Bool}})(ϕ::Function, ϕdϕ::LineSearches.var"#ϕdϕ#6"{Optim.ManifoldObjective{OnceDifferentiable{Float64, Array{Float64, 5}, Array{Float64, 5}}}, Array{Float64, 5}, Array{Float64, 5}, Array{Float64, 5}}, c::Float64, phi_0::Float64, dphi_0::Float64)
    @ LineSearches C:\Users\weerd\.julia\packages\LineSearches\Ki4c5\src\hagerzhang.jl:269
  [3] HagerZhang
    @ C:\Users\weerd\.julia\packages\LineSearches\Ki4c5\src\hagerzhang.jl:101 [inlined]
  [4] perform_linesearch!(state::Optim.LBFGSState{Array{Float64, 5}, Vector{Array{Float64, 5}}, Vector{Array{Float64, 5}}, Float64, Array{Float64, 5}}, method::LBFGS{Nothing, InitialStatic{Float64}, HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, d::Optim.ManifoldObjective{OnceDifferentiable{Float64, Array{Float64, 5}, Array{Float64, 5}}})
    @ Optim C:\Users\weerd\.julia\packages\Optim\LScFu\src\utilities\perform_linesearch.jl:59
  [5] update_state!(d::OnceDifferentiable{Float64, Array{Float64, 5}, Array{Float64, 5}}, state::Optim.LBFGSState{Array{Float64, 5}, Vector{Array{Float64, 5}}, Vector{Array{Float64, 5}}, Float64, Array{Float64, 5}}, method::LBFGS{Nothing, InitialStatic{Float64}, HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"})
    @ Optim C:\Users\weerd\.julia\packages\Optim\LScFu\src\multivariate\solvers\first_order\l_bfgs.jl:204
  [6] optimize(d::OnceDifferentiable{Float64, Array{Float64, 5}, Array{Float64, 5}}, initial_x::Array{Float64, 5}, method::LBFGS{Nothing, InitialStatic{Float64}, HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}, state::Optim.LBFGSState{Array{Float64, 5}, Vector{Array{Float64, 5}}, Vector{Array{Float64, 5}}, Float64, Array{Float64, 5}})
    @ Optim C:\Users\weerd\.julia\packages\Optim\LScFu\src\multivariate\optimize\optimize.jl:54
  [7] optimize
    @ C:\Users\weerd\.julia\packages\Optim\LScFu\src\multivariate\optimize\optimize.jl:36 [inlined]
  [8] optimize(f::Function, g::Function, initial_x::Array{Float64, 5}, method::LBFGS{Nothing, InitialStatic{Float64}, HagerZhang{Float64, Base.RefValue{Bool}}, Optim.var"#19#21"}, options::Optim.Options{Float64, Nothing}; inplace::Bool, autodiff::Symbol)
    @ Optim C:\Users\weerd\.julia\packages\Optim\LScFu\src\multivariate\optimize\interface.jl:155

```

How am I to interpret this? What course of action can I take to get around this problem?  
Thanks for the help in advance

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [March 3, 2022, 1:51pm UTC](https://discourse.julialang.org/t/optimization-error/77358/2 "2022-03-03T13:51:16Z")

</div>

> [@Eriklw](#):
>
> How am I to interpret this?

Probably a programming error in [Linesearches.jl](https://github.com/JuliaNLSolvers/LineSearches.jl). You could open an issue?

Others might help with the question if you can switch the line search algorithm easily.

---

<div class="post-metadata">

**Author:** ![Eriklw](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@Eriklw](https://discourse.julialang.org/u/Eriklw)\
**Post date:** [March 4, 2022, 1:53pm UTC](https://discourse.julialang.org/t/optimization-error/77358/3 "2022-03-04T13:53:49Z")

</div>

I have opened an issue- however this has been discussed some time ago already in an issue of LineSearch.jl und has not changed yet appearently.

---

<div class="post-metadata">

**Author:** ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)\
**Post date:** [March 4, 2022, 2:05pm UTC](https://discourse.julialang.org/t/optimization-error/77358/4 "2022-03-04T14:05:11Z")

</div>

It was also discussed [here](https://discourse.julialang.org/t/optim-with-occasionally-non-finite-values/10174) and one of the responses shows how to use alternative line searches…

---

<div class="post-metadata">

**Author:** ![Eriklw](https://avatars.discourse-cdn.com/v4/letter/e/ea666f/32.png) [@Eriklw](https://discourse.julialang.org/u/Eriklw)\
**Post date:** [March 4, 2022, 2:26pm UTC](https://discourse.julialang.org/t/optimization-error/77358/5 "2022-03-04T14:26:02Z")

</div>

I have seen that as well. However, these work not as well in my experience. And since this (the assertion error) seems to be some kind of runtime error that LineSearch.jl gives out I am still hoping for a fix of that particular method.
