# Set\_optimizer\_attribute does not work in newer versions of JuMP, Julia, etc.?

**URL:** <https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727>\
**Category:** Optimization (Mathematical)\
**Created:** [November 3, 2022, 5:23pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727 "2022-11-03T17:23:46Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)\
**Post date:** [November 3, 2022, 5:23pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/1 "2022-11-03T17:23:46Z")

</div>

Hello all,

I have an optimization model. I run it on my computer without any problem. I have the following for loop to assign values to Gurobi parameters:

```julia
for paramrow in eachrow(solver_params)
    if paramrow.Type == "Integer"
        set_optimizer_attribute(Expansion_Model, paramrow.Parameter, Int(paramrow.Value))
    else
        set_optimizer_attribute(Expansion_Model, paramrow.Parameter, paramrow.Value)
    end
end

```

My colleague recently installed JuMP, Gurobi, etc. in his computer, but can not run due to the following error:

```julia
Academic license - for non-commercial use only - expires 2023-08-21
LoadError: MethodError: no method matching set_optimizer_attribute(::Model, ::String15, ::Float64)
Closest candidates are:
  set_optimizer_attribute(::Model, ::MathOptInterface.AbstractOptimizerAttribute, ::Any) at C:\Users\admin\.julia\packages\JuMP\bm7X3\src\JuMP.jl:824
  set_optimizer_attribute(::Model, ::String, ::Any) at C:\Users\admin\.julia\packages\JuMP\bm7X3\src\JuMP.jl:802
in expression starting at F:\UCSD_File\Sanbox_oct\uced-model\Run.jl:36

```

I assume this is related to the differences in JuMP versions. My version is 0.21.9. His version is 1.2.0.

Could you please tell me how to modify this for loop to make it work again in his version? Error already gives some suggestions, but I could not figure it out.

Thank you in advance for all your help,  
Kind regards

---

<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:** [November 3, 2022, 6:53pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/2 "2022-11-03T18:53:07Z")

</div>

The `MethodError` is giving a hint: `set_optimizer_attribute(::Model, ::String15, ::Float64)`.

The `String15` type isn’t something that JuMP supports.

Do

```julia
set_optimizer_attribute(Expansion_Model, "$(paramrow.Parameter)", paramrow.Value)

```

---

<div class="post-metadata">

**Author:** ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)\
**Post date:** [November 4, 2022, 12:41am UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/3 "2022-11-04T00:41:41Z")

</div>

Thank you so much for your answer. `String15` works in my JuMP version (version 0.21.9). So, newer versions do not support that?

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 4, 2022, 2:44am UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/4 "2022-11-04T02:44:16Z")

</div>

This error would also occur in JuMP 0.21.9 (I can reproduce that error in that version).

I assume that `solver_params` is a DataFrame, and more recent versions of DataFrames rely on a package called InlineStrings: this is where this `String15` type comes from, often from creating a DataFrame by reading a CSV file.

I would guess that since you are using an older version of JuMP, you are also using an older version of DataFrames.jl/CSV.jl that doesn’t yet use InlineStrings.

As Oscar’s work-around showed, you can convert your String15 parameter from your dataframe to a string, by either string interpolation

```julia
"$(paramrow.Parameter)"

```

or by a function

```julia
String(paramrow.Parameter)

```

or you can even give the column types when reading in the DataFrame/CSV explicitly as `String`.

---

<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:** [November 4, 2022, 8:38am UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/5 "2022-11-04T08:38:21Z")

</div>

Do you think it _could_ support `String15` (or rather, `InlineStrings` in general)?

In this case it might “just” be an issue of widening the type signatures accepted by `set_optimizer_attribute` to `AbstractString` (I’m using “just” in the loosest possible sense here - I have no insights into the internals of JuMP and the potential implications of this widening). I find that in many of my (data-sciency) workflows `InlineStrings` are absolutely crucial to ensuring that the GC load brought be regular `String`s doesn’t make my sessions unusable, so having them more widely supported would be great.

Also just to clarify a little bit @jd-foster’s comment: `DataFrames` does not “rely” on `InlineStrings`, so this is unrelated to DataFrames versions. `InlineStrings` were an optimization targeted at reducing GC stress in string-heavy workflows introduced into `CSV.jl` with version 0.9 (iirc). Since then, the default setting is to parse identified string columns into `InlineStrings`, this can be changed with the `stringtype` kwarg in `CSV.File`/`CSV.read`, i.e. `CSV.read("myfile.csv", DataFrame; stringtype = String)` will revert to the old behaviour of storing strings as `String`s.

---

<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:** [November 4, 2022, 9:19am UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/6 "2022-11-04T09:19:29Z")

</div>

We could add a method that does the convert. Open an issue, or a PR if interested 😄

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [November 4, 2022, 9:33am UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/7 "2022-11-04T09:33:08Z")

</div>

> [@nilshg](#):
>
> does not “rely”

You’re right, maybe I should have said “can use” or “is compatible with”. The verbs we usually use don’t always work in the context of abstract types and multiple dispatch.

---

<div class="post-metadata">

**Author:** ![fksayaci](https://avatars.discourse-cdn.com/v4/letter/f/b77776/32.png) [@fksayaci](https://discourse.julialang.org/u/fksayaci)\
**Post date:** [November 7, 2022, 8:09pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/8 "2022-11-07T20:09:38Z")

</div>

Thank you so much for your answers. I changed the statement from `paramrow.Parameter` to `"$(paramrow.Parameter)"` in my version of JuMP. It works.

Kind regards

---

<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:** [November 7, 2022, 9:14pm UTC](https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in-newer-versions-of-jump-julia-etc/89727/9 "2022-11-07T21:14:10Z")

</div>

I’ve opened a PR, so if it gets merged this will be fixed in a future release of JuMP:

> <https://github.com/jump-dev/JuMP.jl/pull/3127>
>
> x-ref https://discourse.julialang.org/t/set-optimizer-attribute-does-not-work-in…-newer-versions-of-jump-julia-etc/89727
