# Specifying JuMP solvers for function-wrapped optimization models

**URL:** <https://discourse.julialang.org/t/specifying-jump-solvers-for-function-wrapped-optimization-models/81030>\
**Category:** Optimization (Mathematical)\
**Created:** [May 13, 2022, 3:54pm UTC](https://discourse.julialang.org/t/specifying-jump-solvers-for-function-wrapped-optimization-models/81030 "2022-05-13T15:54:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tominapa](https://avatars.discourse-cdn.com/v4/letter/t/cab0a1/32.png) [@Tominapa](https://discourse.julialang.org/u/Tominapa)\
**Post date:** [May 13, 2022, 3:54pm UTC](https://discourse.julialang.org/t/specifying-jump-solvers-for-function-wrapped-optimization-models/81030/1 "2022-05-13T15:54:40Z")

</div>

I am building a package based around a specific optimization problem, implemented in JuMP. My code builds an optimization model based on input data, with most everything automated behind the scenes for user-friendliness. I would like to allow users to select whichever solver they would like (and are able to access) but have no idea how to implement this.

Ideally, something like this

```julia
using CustomPackage
using Gurobi

sol = CustomPackageFunction(DataDirectory, Solver=Gurobi)

```

where `Solver` is an optional keyword argument allowing a user to select a solver, and if not specified, defaulting to an open-source option.

A trivial option might be to use keywords and if statements, and have all the `JuMP.model()` calls pre-defined, but I would imagine there is a better solution that would allow an arbitrary solver to be passed in.

---

<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:** [May 13, 2022, 7:51pm UTC](https://discourse.julialang.org/t/specifying-jump-solvers-for-function-wrapped-optimization-models/81030/2 "2022-05-13T19:51:37Z")

</div>

Does this tutorial help?

[https://jump.dev/JuMP.jl/stable/tutorials/getting\_started/design\_patterns\_for\_larger\_models/#Remove-solver-dependence,-add-error-checks](https://jump.dev/JuMP.jl/stable/tutorials/getting_started/design_patterns_for_larger_models/#Remove-solver-dependence,-add-error-checks)

---

<div class="post-metadata">

**Author:** ![Tominapa](https://avatars.discourse-cdn.com/v4/letter/t/cab0a1/32.png) [@Tominapa](https://discourse.julialang.org/u/Tominapa)\
**Post date:** [May 25, 2022, 4:06pm UTC](https://discourse.julialang.org/t/specifying-jump-solvers-for-function-wrapped-optimization-models/81030/3 "2022-05-25T16:06:54Z")

</div>

Yes, this is precisely what I needed. Thank you. I will summarize my solution future readers:

```nohighlight
using CustomPackage
using Clp
using Gurobi

sol = CustomPackageFunction(DataDirectory, optimizer=Gurobi.Optimizer)

```

With a function setup like this:

```nohighlight
function CustomPackageFunction(DataDirectory; optimizer=Clp.Optimizer)
    model = JuMP.Model(optimizer)
    return model
end

```

The optional keyword argument `optimizer` allows a user to pass in whatever optimizer they have but defaults to the open-source `Clp.Optimizer` if `optimizer` is not included as an argument.
