# Setting tolerances in JuMP - is there an Optimizer-independent way?

**URL:** <https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030>\
**Category:** Optimization (Mathematical)\
**Tags:** jump\
**Created:** [February 22, 2023, 5:13pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030 "2023-02-22T17:13:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [February 22, 2023, 5:13pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030/1 "2023-02-22T17:13:08Z")

</div>

Is there a simple Optimizer-independent way to set tolerances in JuMP? I searched the documentation and couldn’t find anything on setting tolerances [I’m tired of multiplying my objective functions by large numbers 😉]

This is probably trivial if you know how to do it, and probably easy to find if you know where to look 😉

Thanks for any help!

---

<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 22, 2023, 6:30pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030/2 "2023-02-22T18:30:55Z")

</div>

> I’m tired of multiplying my objective functions by large numbers

Why are you doing this?

> Is there a simple Optimizer-independent way to set tolerances in JuMP?

Nothing that is widely supported. Gurobi and CPLEX support setting `MOI.AbsoluteGapTolerance()` and `MOI.RelativeGapTolerance()`.

See [Models · JuMP](https://jump.dev/JuMP.jl/stable/moi/reference/models/#MathOptInterface.AbsoluteGapTolerance)

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [February 22, 2023, 9:45pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030/3 "2023-02-22T21:45:17Z")

</div>

> [@odow](#):
>
> > I’m tired of multiplying my objective functions by large numbers
> 
> Why are you doing this?

Because if my objective is 1000 times larger, this is equivalent but will automatically make my answer more precise. It is admittedly a clumsy way, but I don’t know another convenient way to achieve this.

---

<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 22, 2023, 9:50pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030/4 "2023-02-22T21:50:51Z")

</div>

> [@compleat](#):
>
> this is equivalent but will automatically make my answer more precise.

Note that this will only affect absolute tolerances. Some solvers use relative tolerances (e.g., the relative gap when solving a MIP).

The bigger question to think about is why this is necessary. Solvers don’t use exact arithmetic, so you should always anticipate some tolerance. Instead of changing the tolerance, you’re usually better off reformulating the model to use different units. So if your objective value comes out to be much less than 1, you should probably use variables with units of millimeters instead of meters, for example.

---

<div class="post-metadata">

**Author:** ![compleat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/compleat/32/8958_2.png) [@compleat](https://discourse.julialang.org/u/compleat)\
**Post date:** [February 22, 2023, 10:14pm UTC](https://discourse.julialang.org/t/setting-tolerances-in-jump-is-there-an-optimizer-independent-way/95030/5 "2023-02-22T22:14:27Z")

</div>

> [@odow](#):
>
> So if your objective value comes out to be much less than 1, you should probably use variables with units of millimeters instead of meters, for example.

Thanks. That is effectively what I am doing. I just wondered whether there were some other way.
