# Reading JuMP model "lower bound already set"

**URL:** https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156
**Category:** Optimization (Mathematical)
**Tags:** jump
**Created:** [March 15, 2023, 11:09pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156 "2023-03-15T23:09:30Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![shakedregev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shakedregev/32/45821_2.png) [@shakedregev](https://discourse.julialang.org/u/shakedregev)
#### Post date: [March 15, 2023, 11:09pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/1 "2023-03-15T23:09:30Z")

</div>

Writing the model like this works

```julia
model = JuMP.Model(Clarabel.Optimizer)
*set variables and contraints*
write_to_file(model, "my_model.lp")

```

The model is also solved correctly by Clarabel. However, problems occur when I try to read it.

```julia
model = read_from_file("my_model.lp")
set_optimizer(model, Clarabel.Optimizer)
optimize!(model)

```

I get the error:

```julia
LoadError: MathOptInterface.LowerBoundAlreadySet{MathOptInterface.Interval{Float64}, MathOptInterface.GreaterThan{Float64}}: Cannot add `VariableIndex`-in-`MathOptInterface.GreaterThan{Float64}` constraint for variable MathOptInterface.VariableIndex(1) as a `VariableIndex`-in-`MathOptInterface.Interval{Float64}` constraint was already set for this variable and both constraints set a lower bound.

```

These 3 lines are all I’m doing in the read portion. Also, it throws the same error if I get rid of the second line.

---

<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 15, 2023, 11:18pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/2 "2023-03-15T23:18:12Z")

</div>

Can you provide a reproducible example? What is the contents of `my_model.lp`?

---

<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 15, 2023, 11:39pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/3 "2023-03-15T23:39:53Z")

</div>

This is an embarrassing bug! Let me take a look.

```julia
julia> using JuMP

julia> model = Model();

julia> @variable(model, 0 <= x <= 1)
x

julia> write_to_file(model, "model.lp")

julia> read_from_file("model.lp")
ERROR: MathOptInterface.LowerBoundAlreadySet{MathOptInterface.Interval{Float64}, MathOptInterface.GreaterThan{Float64}}: Cannot add `VariableIndex`-in-`MathOptInterface.GreaterThan{Float64}` constraint for variable MathOptInterface.VariableIndex(1) as a `VariableIndex`-in-`MathOptInterface.Interval{Float64}` constraint was already set for this variable and both constraints set a lower bound.
Stacktrace:

```

---

<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 16, 2023, 1:16am UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/4 "2023-03-16T01:16:56Z")

</div>

Fixed in [[FileFormats.LP] fix reading models with default bounds by odow · Pull Request #2121 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/pull/2121).

I’ll get a new release tagged in the next day or so.

---

<div class="post-metadata">

### Author: ![shakedregev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shakedregev/32/45821_2.png) [@shakedregev](https://discourse.julialang.org/u/shakedregev)
#### Post date: [March 16, 2023, 5:37pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/5 "2023-03-16T17:37:27Z")

</div>

Thanks, I tried using the package manager to add the branch you linked here

```julia
add MathOptInterface#od/fix-lp-read

```

This worked with no issues, but then I got the same error when running my code. Not sure if I am not doing it correctly or if it just hasn’t been updated.

Edit: I think the problem is that it hasn’t been updated properly in my package directory

---

<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 16, 2023, 7:27pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/6 "2023-03-16T19:27:17Z")

</div>

> Not sure if I am not doing it correctly or if it just hasn’t been updated.

After updating a package, you need to restart Julia for the change to take effect.

If it’s still a problem after that, can you provide a reproducible example?

Note that I merged the branch, so now you need `] add MathOptInterface#master`.

---

<div class="post-metadata">

### Author: ![shakedregev](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shakedregev/32/45821_2.png) [@shakedregev](https://discourse.julialang.org/u/shakedregev)
#### Post date: [March 16, 2023, 9:32pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/7 "2023-03-16T21:32:20Z")

</div>

Thanks, that worked!

---

<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 16, 2023, 9:49pm UTC](https://discourse.julialang.org/t/reading-jump-model-lower-bound-already-set/96156/8 "2023-03-16T21:49:20Z")

</div>

We’ll tag the fix in the next day or so. Just waiting for a couple of other things: [Prep for v1.13.2 by odow · Pull Request #2122 · jump-dev/MathOptInterface.jl · GitHub](https://github.com/jump-dev/MathOptInterface.jl/pull/2122).

Sorry for the bug! It turns out we could read and write LP files, but we couldn’t read some of our own LP files…
