# Argument error : invalid NLopt arguments: finite domain required for global algorithm

**URL:** https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427
**Category:** New to Julia
**Tags:** question
**Created:** [January 31, 2025, 11:26am UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427 "2025-01-31T11:26:29Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [January 31, 2025, 11:26am UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/1 "2025-01-31T11:26:29Z")

</div>

Hi,

I am trying to run a Julia code to fit a LinearMixedModel and facing an **Argument error : invalid NLopt arguments: finite domain required for global algorithm**.

Julia version I am working on is 1.8.5

Any help will be appreciated.  
Thank you

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [January 31, 2025, 1:28pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/2 "2025-01-31T13:28:23Z")

</div>

> [@Somya](#):
>
> I am trying to run a Julia code to fit a LinearMixedModel and facing an **Argument error : invalid NLopt arguments: finite domain required for global algorithm**.

The error means exactly what it says: NLopt has both global and local optimization algorithms, but the former are only supported on a finite domain.

So, either specify upper and lower bounds to all your variables or switch to local optimization.

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [January 31, 2025, 5:21pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/3 "2025-01-31T17:21:47Z")

</div>

Can you provide more detail on how you got to this error? For example, MixedModels.jl version and whether you changed any of the default settings.

For the default settings, MixedModels.jl sets up the optimization problem with appropriate constraints and then uses the BOBYQA optimizer.

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 3, 2025, 12:01pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/5 "2025-02-03T12:01:17Z")

</div>

I am using julia version “ **1.8.5** ” and package MixedModels version “ **3.9.0** ”.  
I am trying to fit a “LinearMixedModel” as below:

_`model = fit!(LinearMixedModel(formula, input_dataframe), REML=true)`_

And its very strange that till last month I was able to run this command successfully, but now I am facing an issue with NLopt.

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 3, 2025, 12:02pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/6 "2025-02-03T12:02:58Z")

</div>

Thank you for your response.

Could you please confirm how can I specify upper and lower bounds to all variables or switch to local optimization if I am trying to fit a “LinearMixedModel” ?

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 3, 2025, 3:54pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/7 "2025-02-03T15:54:07Z")

</div>

Unless you have a very good reason to be on the 3.x series, I would recommend upgrading to the 4.x series of MixedModels. The primary breaking change was to the internal storage and not to any user-facing API, so the fast majority of users would not experience any breakage on upgrade.

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 3, 2025, 3:55pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/8 "2025-02-03T15:55:39Z")

</div>

MixedModels.jl sets up the bounds to be as constrained as possible:

- variance parameters are constrained to be non-negative, i.e. they only have a lower bound
- no other parameters are constrained

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 4, 2025, 6:46am UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/9 "2025-02-04T06:46:04Z")

</div>

I am getting same NLopt error using MixedModels version “ **4.8.0** ”.

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 4, 2025, 6:48am UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/10 "2025-02-04T06:48:54Z")

</div>

The same functionality was working fine till last month and I did not made any upgrades ? Even if any upgrade is necessary, it should not break backward compatibility of existing versions.

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 4, 2025, 3:18pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/11 "2025-02-04T15:18:52Z")

</div>

Without more information, it’s really hard to tell what’s going on. Can you share, even privately, the code + data that leads to this error?

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 4, 2025, 5:05pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/12 "2025-02-04T17:05:39Z")

</div>

PFA code which you can use to replicate the error.

```julia
using Pkg;

Pkg.add(Pkg.PackageSpec(name="MixedModels", version="4.30.0"));

Pkg.add(Pkg.PackageSpec(name="StatsModels", version="0.7.4"));

Pkg.add(Pkg.PackageSpec(name="DataFrames", version="1.7.0"));

Pkg.status();

using MixedModels
using StatsModels
using DataFrames

# Example data
df = DataFrame(
    y = [3.1, 2.9, 3.5, 4.2, 3.0],
    x1 = [1, 2, 1, 2, 1],
    x2 = [0.5, 0.5, 0.5, 0.5, 0.5],
    group = ["A", "A", "B", "B", "A"]
)

# Fit a linear mixed model with fixed effects for x1 and x2, and a random intercept for 'group'
model = fit(LinearMixedModel, @formula(y ~ x1 + x2 + (1|group)), df)

# Print the model results
println(model)

```

---

<div class="post-metadata">

### Author: ![dmbates](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmbates/32/44_2.png) [@dmbates](https://discourse.julialang.org/u/dmbates)
#### Post date: [February 4, 2025, 6:01pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/13 "2025-02-04T18:01:00Z")

</div>

I don’t get an error from this call to `fit(MixedModel, ` but I do get a warning about a rank-deficient model matrix for the fixed effects.

```julia
┌ Warning: Fixed-effects matrix is rank deficient
└ @ MixedModels ~/.julia/packages/MixedModels/FUijl/src/Xymat.jl:41
Linear mixed model fit by maximum likelihood
 y ~ 1 + x1 + x2 + (1 | group)
   logLik -2 logLik AIC AICc BIC    
    -2.2089 4.4179 12.4179 Inf 10.8556

Variance components:
            Column Variance Std.Dev. 
group (Intercept) 0.134369 0.366564
Residual 0.070780 0.266046
 Number of obs: 5; levels of grouping factors: 2

  Fixed-effects parameters:
────────────────────────────────────────────────────
                 Coef. Std. Error z Pr(>|z|)
────────────────────────────────────────────────────
(Intercept) 3.07144 0.449942 6.83 <1e-11
x1 0.239281 0.24568 0.97 0.3301
x2 -0.0 NaN NaN NaN
────────────────────────────────────────────────────

```

This is with

```julia
julia> versioninfo()
Julia Version 1.11.3
Commit d63adeda50d (2025-01-21 19:42 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 8 × Apple M1 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 6 virtual cores)
Environment:
  JULIA_EDITOR = code
  JULIA_NUM_THREADS = 

```

and version 4.30.0 of MixedModels

---

<div class="post-metadata">

### Author: ![palday](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palday/32/12640_2.png) [@palday](https://discourse.julialang.org/u/palday)
#### Post date: [February 4, 2025, 6:20pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/14 "2025-02-04T18:20:54Z")

</div>

> [@Somya](#):
>
> ```julia
> using Pkg;
> 
> Pkg.add(Pkg.PackageSpec(name="MixedModels", version="4.30.0"));
> 
> Pkg.add(Pkg.PackageSpec(name="StatsModels", version="0.7.4"));
> 
> Pkg.add(Pkg.PackageSpec(name="DataFrames", version="1.7.0"));
> 
> Pkg.status();
> 
> using MixedModels
> using StatsModels
> using DataFrames
> 
> # Example data
> df = DataFrame(
> y = [3.1, 2.9, 3.5, 4.2, 3.0],
> x1 = [1, 2, 1, 2, 1],
> x2 = [0.5, 0.5, 0.5, 0.5, 0.5],
> group = ["A", "A", "B", "B", "A"]
> )
> 
> # Fit a linear mixed model with fixed effects for x1 and x2, and a random intercept for 'group'
> model = fit(LinearMixedModel, @formula(y ~ x1 + x2 + (1|group)), df)
> 
> # Print the model results
> println(model)
> 
> ```

Same here, though the rank deficiency is expected given that `x2` is constant.

Has the change in behavior (i.e. the recent failures) happened at the same time as a change in computer – hardware, operating system, etc.?

---

<div class="post-metadata">

### Author: ![Somya](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Somya](https://discourse.julialang.org/u/Somya)
#### Post date: [February 5, 2025, 1:40pm UTC](https://discourse.julialang.org/t/argument-error-invalid-nlopt-arguments-finite-domain-required-for-global-algorithm/125427/15 "2025-02-05T13:40:16Z")

</div>

I got the solution. Upgrading StatsModels julia package from version 0.6.28 to 0.7.4 worked for me.

Thank you for your suggestions and help 🙂
