Skip to content

set_optimizer does not copy optimizer attributes #1750

@odow

Description

@odow
julia> using JuMP, Clp

julia> model = Model()
A JuMP Model
Feasibility problem with:
Variables: 0
Model mode: AUTOMATIC
CachingOptimizer state: NO_OPTIMIZER
Solver name: No optimizer attached.

julia> @variable(model, x)
x

julia> set_silent(model)

julia> set_optimizer(model, Clp.Optimizer)

julia> optimize!(model)
Clp3002W Empty problem - 0 rows, 1 columns and 0 elements
Clp0000I Optimal - objective value 0
Clp0032I Optimal objective 0 - 0 iterations time 0.002

Found by @anavarro01 in odow/SDDP.jl#495, but I initially mis-diagnosed it as the Gurobi printing issue (sorry).

set_optimizer constructs a new caching optimizer: https://github.com/jump-dev/JuMP.jl/blob/1e0b6ee82bfec5e4fe210b70caff47610607e81c/src/optimizer_interface.jl#L103-L121

but it is missing the logic we previous had to copy supported OptimizerAttributes:

for attr in MOI.get(m.model_cache, MOI.ListOfOptimizerAttributesSet())
# Skip attributes which don't apply to the new optimizer.
if attr isa MOI.RawOptimizerAttribute
# Even if the optimizer claims to `supports` `attr`, the value
# might have a different meaning (e.g., two solvers with `logLevel`
# as a RawOptimizerAttribute). To be on the safe side, just skip all raw
# parameters.
continue
elseif !MOI.is_copyable(attr) || !MOI.supports(m.optimizer, attr)::Bool
continue
end
value = MOI.get(m.model_cache, attr)
optimizer_value = map_indices(m.model_to_optimizer_map, attr, value)
MOI.set(m.optimizer, attr, optimizer_value)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions