# Error in using KNITRO with JuMP

**URL:** <https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [March 12, 2023, 4:36am UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951 "2023-03-12T04:36:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rick](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Rick](https://discourse.julialang.org/u/Rick)\
**Post date:** [March 12, 2023, 4:36am UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/1 "2023-03-12T04:36:48Z")

</div>

Hi everyone,

I have just updated my packages, then I am unable to use `KNITRO.jl` with `JuMP` anymore.

The code I run is:

```julia
using KNITRO, JuMP
model = Model(KNITRO.Optimizer)

```

Then, I get the following error:

```julia
The provided `optimizer_constructor` returned an object of type KNITRO.Optimizer. Expected a MathOptInterface.ModelLike.

```

My package versions are:

- `JuMP` v1.6.0
- `KNITRO` v0.13.2

I tried passing another optimizer to the `JuMP` `Model`, but I don’t get such an error.

Anyone has experience with this? Any suggestions are appreciated. Thanks!!

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [March 12, 2023, 4:46pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/2 "2023-03-12T16:46:26Z")

</div>

They latest JuMP release is 1.9.0 so you should probably use that.

---

<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:** [March 12, 2023, 6:40pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/3 "2023-03-12T18:40:42Z")

</div>

> They latest JuMP release is 1.9.0 so you should probably use that.

JuMP v1.X is backwards compatible, so it should work with v1.6.0 😄

@Rick, unfortunately I cannot reproduce this. Can you show the full output of these commands in your REPL?

```julia
julia> import Pkg

julia> Pkg.status()
      Status `/private/tmp/kn/Project.toml`
  [4076af6c] JuMP v1.6.0
  [67920dd8] KNITRO v0.13.2

julia> using JuMP, KNITRO

julia> model = Model(KNITRO.Optimizer)
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: EMPTY_OPTIMIZER
Solver name: Knitro

```

---

<div class="post-metadata">

**Author:** ![Rick](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Rick](https://discourse.julialang.org/u/Rick)\
**Post date:** [March 12, 2023, 9:29pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/4 "2023-03-12T21:29:01Z")

</div>

Thanks @odow!

The output of the command is as follows:

```julia
ERROR: LoadError: The provided `optimizer_constructor` returned an object of type KNITRO.Optimizer. Expected a MathOptInterface.ModelLike.
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] _instantiate_and_check(optimizer_constructor::Type{KNITRO.Optimizer})
   @ MathOptInterface ~/.julia/packages/MathOptInterface/YIcoo/src/instantiate.jl:96
 [3] _instantiate_and_check(optimizer_constructor::MathOptInterface.OptimizerWithAttributes)
   @ MathOptInterface ~/.julia/packages/MathOptInterface/YIcoo/src/instantiate.jl:117
 [4] instantiate(optimizer_constructor::MathOptInterface.OptimizerWithAttributes; with_bridge_type::Type{Float64})
   @ MathOptInterface ~/.julia/packages/MathOptInterface/YIcoo/src/instantiate.jl:149
 [5] set_optimizer(model::Model, optimizer_constructor::MathOptInterface.OptimizerWithAttributes; add_bridges::Bool)
   @ JuMP ~/.julia/packages/JuMP/vuP7I/src/optimizer_interface.jl:110
 [6] Model(optimizer_factory::MathOptInterface.OptimizerWithAttributes; add_bridges::Bool)
   @ JuMP ~/.julia/packages/JuMP/vuP7I/src/JuMP.jl:221
 [7] Model
   @ ~/.julia/packages/JuMP/vuP7I/src/JuMP.jl:220 [inlined]

```

---

<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:** [March 12, 2023, 9:32pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/5 "2023-03-12T21:32:08Z")

</div>

> [@odow](#):
>
> ```julia
> julia> import Pkg
> 
> julia> Pkg.status()
> 
> ```

What about this part?

---

<div class="post-metadata">

**Author:** ![Rick](https://avatars.discourse-cdn.com/v4/letter/r/9f8e36/32.png) [@Rick](https://discourse.julialang.org/u/Rick)\
**Post date:** [March 12, 2023, 9:43pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/6 "2023-03-12T21:43:18Z")

</div>

> [@odow](#):
>
> `Pkg.status()`

Here’s my output. Is the warning message for `MOI` related?

```julia
┌ Warning: Replacing module `MathOptInterface`
└ @ Base loading.jl:937
      Status `/Project.toml`
  [6e4b80f9] BenchmarkTools v1.3.2
  [336ed68f] CSV v0.10.9
  [159f3aea] Cairo v1.0.5
  [49dc2e85] Calculus v0.5.1
  [5ae59095] Colors v0.12.10
  [a93c6f00] DataFrames v1.4.4
  [31c24e10] Distributions v0.25.80
  [186bb1d3] Fontconfig v0.4.1
  [f6369f11] ForwardDiff v0.10.34
  [c91e804a] Gadfly v1.3.4
  [2e9cd046] Gurobi v0.11.5
  [7073ff75] IJulia v1.24.0
  [b6b21f68] Ipopt v1.1.0
  [4138dd39] JLD v0.13.3
  [4076af6c] JuMP v1.6.0
  [67920dd8] KNITRO v0.13.2 `https://github.com/jump-dev/KNITRO.jl.git#master`
  [b8f27783] MathOptInterface v1.11.4
  [429524aa] Optim v1.7.4
  [d96e819e] Parameters v0.12.3
  [91a5bcdd] Plots v1.38.2
  [132c30aa] ProfileSVG v0.2.1
  [c46f51b8] ProfileView v1.5.2
  [92933f4c] ProgressMeter v1.7.2
  [d330b81b] PyPlot v2.11.0
  [df47a6cb] RData v1.0.0
  [a8a75453] StatProfilerHTML v1.4.2
  [2913bbd2] StatsBase v0.33.21
  [ade2ca70] Dates
  [37e2e46d] LinearAlgebra
      Status `/Project.toml`
  [6e4b80f9] BenchmarkTools v1.3.2
  [336ed68f] CSV v0.10.9
  [159f3aea] Cairo v1.0.5
  [49dc2e85] Calculus v0.5.1
  [5ae59095] Colors v0.12.10
  [a93c6f00] DataFrames v1.4.4
  [31c24e10] Distributions v0.25.80
  [186bb1d3] Fontconfig v0.4.1
  [f6369f11] ForwardDiff v0.10.34
  [c91e804a] Gadfly v1.3.4
  [2e9cd046] Gurobi v0.11.5
  [7073ff75] IJulia v1.24.0
  [b6b21f68] Ipopt v1.1.0
  [4138dd39] JLD v0.13.3
  [4076af6c] JuMP v1.6.0
  [67920dd8] KNITRO v0.13.2 `https://github.com/jump-dev/KNITRO.jl.git#master`
  [b8f27783] MathOptInterface v1.11.4
  [429524aa] Optim v1.7.4
  [d96e819e] Parameters v0.12.3
  [91a5bcdd] Plots v1.38.2
  [132c30aa] ProfileSVG v0.2.1
  [c46f51b8] ProfileView v1.5.2
  [92933f4c] ProgressMeter v1.7.2
  [d330b81b] PyPlot v2.11.0
  [df47a6cb] RData v1.0.0
  [a8a75453] StatProfilerHTML v1.4.2
  [2913bbd2] StatsBase v0.33.21
  [ade2ca70] Dates
  [37e2e46d] LinearAlgebra

```

---

<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:** [March 12, 2023, 9:51pm UTC](https://discourse.julialang.org/t/error-in-using-knitro-with-jump/95951/7 "2023-03-12T21:51:31Z")

</div>

Can you copy the code I wrote above in a new Julia REPL, and provide all output (exactly like I have done). I don’t know why the status has printed twice, or what the “Replacing module” appears.

Also, you shouldn’t need the `master` branch installed. Run

```julia
import Pkg
Pkg.free("KNITRO")

```

Then restart Julia.

Finally, what do you see if you do:

```plaintext
julia> import KNITRO

julia> KNITRO.Optimizer()
##### This license is only intended for use by JuMP-dev team. #####
##### License is valid until Aug 31, 2023 #####
A MathOptInterface model with backend:
Knitro 13.1.0
-----------------------
Problem Characteristics
-----------------------
Objective goal: Minimize
Objective type: -1
Number of variables: 0
Number of constraints: 0
Number of nonzeros in Jacobian: 0
Number of nonzeros in Hessian: 0

```
