# Issue with Optimization.LBFGS

**URL:** <https://discourse.julialang.org/t/issue-with-optimization-lbfgs/129076>\
**Category:** Optimization (Mathematical)\
**Tags:** optimization, enzyme\
**Created:** [May 16, 2025, 7:44pm UTC](https://discourse.julialang.org/t/issue-with-optimization-lbfgs/129076 "2025-05-16T19:44:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![miguelborrero](https://avatars.discourse-cdn.com/v4/letter/m/eb9ed0/32.png) [@miguelborrero](https://discourse.julialang.org/u/miguelborrero)\
**Post date:** [May 16, 2025, 7:44pm UTC](https://discourse.julialang.org/t/issue-with-optimization-lbfgs/129076/1 "2025-05-16T19:44:07Z")

</div>

Hi there,

Disclaimer: I can not share the actual data or objective function so this might be a long shot but maybe the error itself has enough information.

I am trying to optimize a function `g` with non-linear constraints through ` cons` and I use the solver `Optimization.LBFGS()` which allows for non-linear solving with constraints but I am getting a strange error.

To be clear: without `cons = cons` it works. The code I am running is:

```julia
optf = OptimizationFunction(g, AutoEnzyme(), cons = cons)
prob = OptimizationProblem(optf, y_init, p, lcons = repeat([-Inf], num_schools), ucons = repeat([0.0], num_schools))
sol_lbfgs = solve(prob, Optimization.LBFGS())

```

```julia
julia> sol_lbfgs = solve(prob, Optimization.LBFGS())
ERROR: MethodError: no method matching (::Colon)(::Int64, ::Nothing)

Closest candidates are:
  (::Colon)(::T, ::Any, ::T) where T<:Real
   @ Base range.jl:50
  (::Colon)(::A, ::Any, ::C) where {A<:Real, C<:Real}
   @ Base range.jl:10
  (::Colon)(::T, ::Any, ::T) where T
   @ Base range.jl:49
  ...

Stacktrace:
 [1] __solve(cache::OptimizationCache{…})
   @ Optimization ~/.julia/packages/Optimization/PnmC0/src/lbfgsb.jl:176
 [2] solve!(cache::OptimizationCache{…})
   @ SciMLBase ~/.julia/packages/SciMLBase/2TYas/src/solve.jl:187
 [3] solve(::OptimizationProblem{…}, ::Optimization.LBFGS; kwargs::@Kwargs{})
   @ SciMLBase ~/.julia/packages/SciMLBase/2TYas/src/solve.jl:95
 [4] solve(::OptimizationProblem{…}, ::Optimization.LBFGS)
   @ SciMLBase ~/.julia/packages/SciMLBase/2TYas/src/solve.jl:92
 [5] top-level scope
   @ REPL[6225]:1
Some type information was truncated. Use `show(err)` to see complete types.

```

Does someone have any information regarding where the error could be coming from?

I apologize for not being able to provide a MWE.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [May 16, 2025, 8:14pm UTC](https://discourse.julialang.org/t/issue-with-optimization-lbfgs/129076/2 "2025-05-16T20:14:50Z")

</div>

`LBFGS-B` is not compatible with nonlinear constraints IIRC. Try IPOPT instead.

We should throw a better error message here.
