Accessing backend of Model

Hi,

I have a usecase where I have to copy models. I also need to access the solver backend. However it seems that I can either use direct_model(), so I have access to the backend, but can’t copy the model, or i can use Model(), but I can’t find the way to access the backend in this mode.

Minimum examples:

using JuMP
using HiGHS

backend = HiGHS.Optimizer()
m = direct_model(backend)
@variable(m, a)

Highs_writeOptions(backend, "options.txt") # this works
copy_model(m)                                            # this does not
using JuMP
using HiGHS

m = Model(HiGHS.Optimizer)
@variable(m, a)

copy_model(m) # this works
Highs_writeOptions(m.moi_backend, "options.txt") # this does not
1 Like

After a bit more research I found the solution.
If anyone comes accross the same issue, this seems to work so far

using JuMP
using HiGHS

m = Model(HiGHS.Optimizer)
@variable(m, a)
optimize!(m)

Highs_writeOptions(m.moi_backend.optimizer.model, "options.txt") # this does not

Hi Maxime, welcome to the forum.

You’re pretty close. You can use unsafe_backend instead, which essentially is your last option in a nice function call.

Here is the part of the documentation to read

https://jump.dev/JuMP.jl/stable/manual/models/#Unsafe-backend

Hi odow,

Thank you for your answer

1 Like