# NLopt failed due to Forced Stop

**URL:** https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [February 9, 2020, 2:09am UTC](https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364 "2020-02-09T02:09:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Fisheryu1234](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fisheryu1234/32/9588_2.png) [@Fisheryu1234](https://discourse.julialang.org/u/Fisheryu1234)
#### Post date: [February 9, 2020, 2:09am UTC](https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364/1 "2020-02-09T02:09:00Z")

</div>

Hi, I encountered a rather complicated constrained maximum likelihood estimation

The constraint is numerically solved from a large-scale nonlinear fixed-point problem given primitive parameters (12,800 equality constraints) . I am trying JuMP with solver Ipopt to solve the fixed points but, for some parameter values, optimal solutions couldn’t be found. So I instead use minimum distance to comprise.  
In math:

\max\_{\theta} \mathcal{L}(\phi(\theta)), \quad s.t. \phi(\theta) = g(\phi(\theta))

g is not differentiable because of min/max equality constraints. I sketch my code below

```julia
using NLopt, JuMP
function cmle(θ::Array{Float64,1}, nograd) ## the constrained MLE objective function
fxp = Model(with_optimizer(Ipopt.Optimizer, tol=1.e-6, mu_strategy = "adaptive"))
....
....
@NLobjective(fixpoint,Min,sum(distance[i]^2 for i = 1:12800) ### This line just for demonstration 
JuMP.optimize!(fxp)
ϕ = value.(fxp). ## the 
return likelihood = f(ϕ)
end

opt = Opt(:LN_COBYLA,15) 
opt.lower_bounds = lowpar
opt.upper_bounds = uppar
opt.xtol_rel = 1e-4
#opt.ftol_rel = 1e-6
opt.min_objective = cmle

(ml,θmin,ret) = optimize(opt,initial_opt = Opt(:LN_COBYLA,15) ##using gradient-free algorithm COBYLA
opt.xtol_rel = 1e-4
opt.min_objective = cmle

(ml,θmin,ret) = optimize(opt, initial_P) 
## the initial values has been provided to ensure the fixed point mapping has a numerical solution.

```

When I try

```julia
cmle(initial_p)

```

the JuMP works and it reports a correct large number as the initial likelihood.

However, the optimize output is always like, whatever gradient-free algorithm I choose

 ![Screen Shot 2020-02-08 at 8.00.38 PM](https://global.discourse-cdn.com/julialang/original/3X/f/8/f8a1646b22247ab4fbbd1ce31622a0e9cdfb9116.png)

Does anyone have a clue what’s going wrong?  
PS: I used mathematical programming with equilibrium constraints (MPEC) to get rid of solving the fixed point. The result didn’t look reasonable so I wanna double check with NFXP.  
Thanks!

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [February 9, 2020, 5:35pm UTC](https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364/2 "2020-02-09T17:35:22Z")

</div>

Hi there,

Take a read of the first post in [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757) (Don’t worry about the long thread).

In particular, it’s easier to help if you can simplify your problem to a minimal working example. Since we can’t run your example, it’s a little hard to offer advice.

The most common reason for NLopt to return `:FORCED_STOP` is an error in the objective function ([NLopt Reference - NLopt Documentation](https://nlopt.readthedocs.io/en/latest/NLopt_Reference/#forced-termination)). You probably need to check that `fxp` solved correctly before trying to return the likelihood.

See [Query Solutions · JuMP](https://www.juliaopt.org/JuMP.jl/stable/solutions/#Obtaining-solutions-1)

---

<div class="post-metadata">

### Author: ![longemen3000](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/longemen3000/32/7298_2.png) [@longemen3000](https://discourse.julialang.org/u/longemen3000)
#### Post date: [February 9, 2020, 6:54pm UTC](https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364/3 "2020-02-09T18:54:50Z")

</div>

Also, I remembered that NLSolve isn’t compatible with the last version of JuMP

---

<div class="post-metadata">

### Author: ![ykc](https://avatars.discourse-cdn.com/v4/letter/y/8edcca/32.png) [@ykc](https://discourse.julialang.org/u/ykc)
#### Post date: [February 24, 2020, 11:47pm UTC](https://discourse.julialang.org/t/nlopt-failed-due-to-forced-stop/34364/4 "2020-02-24T23:47:06Z")

</div>

Where is the objective value at the end of optimization coming from? Do you get the likelihood reported by JuMP when you plug the solution at forced termination back into your objective function? Or is that the objective value at the starting point?  
(Edited my previous response because these seem more relevant for debugging the problem.)
