Skip to content

reading MathOptFormat model with start values raises LoadError when optimizing #2651

Closed
@brunompacheco

Description

@brunompacheco

Hi!

There's a weird bug when reading models in MathOptFormat when some variables have start values assigned. When trying to optimize the model read from the .mof.json file, a LoadError is raised with respect to the VariablePrimalStart attribute.

MRE:

using JuMP, SCIP

model = Model()
@variable(model, x >= 0, start=10.0)

JuMP.write_to_file(model, "test.mof.json")

loaded_model = JuMP.read_from_file("test.mof.json")

set_optimizer(loaded_model, SCIP.Optimizer)

optimize!(loaded_model)

This raises

ERROR: LoadError: MathOptInterface.SetAttributeNotAllowed{MathOptInterface.VariablePrimalStart}: Setting attribute MathOptInterface.VariablePrimalStart() cannot be performed. You may want to use a `CachingOptimizer` in `AUTOMATIC` mode or you may need to call `reset_optimizer` before doing this operation if the `CachingOptimizer` is in `MANUAL` mode.
Stacktrace:
  [1] throw_set_error_fallback(model::SCIP.Optimizer, attr::MathOptInterface.VariablePrimalStart, index::MathOptInterface.VariableIndex, value::Int64; error_if_supported::MathOptInterface.SetAttributeNotAllowed{MathOptInterface.VariablePrimalStart})
    @ MathOptInterface ~/.julia/packages/MathOptInterface/zRYzr/src/attributes.jl:601
  [2] throw_set_error_fallback(model::SCIP.Optimizer, attr::MathOptInterface.VariablePrimalStart, index::MathOptInterface.VariableIndex, value::Int64)
    @ MathOptInterface ~/.julia/packages/MathOptInterface/zRYzr/src/attributes.jl:593
  [3] set(::SCIP.Optimizer, ::MathOptInterface.VariablePrimalStart, ::MathOptInterface.VariableIndex, ::Int64)
    @ MathOptInterface ~/.julia/packages/MathOptInterface/zRYzr/src/attributes.jl:553
  [4] set(b::MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}, attr::MathOptInterface.VariablePrimalStart, index::MathOptInterface.VariableIndex, value::Int64)
    @ MathOptInterface.Bridges ~/.julia/packages/MathOptInterface/zRYzr/src/Bridges/bridge_optimizer.jl:1292
  [5] _pass_attribute(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}, index_map::MathOptInterface.Utilities.IndexMap, vis_src::Vector{MathOptInterface.VariableIndex}, attr::MathOptInterface.VariablePrimalStart)
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/zRYzr/src/Utilities/copy.jl:93
  [6] pass_attributes(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}, index_map::MathOptInterface.Utilities.IndexMap, vis_src::Vector{MathOptInterface.VariableIndex})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/zRYzr/src/Utilities/copy.jl:78
  [7] default_copy_to(dest::MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}, src::MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/zRYzr/src/Utilities/copy.jl:389
  [8] copy_to
    @ ~/.julia/packages/MathOptInterface/zRYzr/src/Bridges/bridge_optimizer.jl:442 [inlined]
  [9] optimize!
    @ ~/.julia/packages/MathOptInterface/zRYzr/src/MathOptInterface.jl:121 [inlined]
 [10] optimize!(m::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.Bridges.LazyBridgeOptimizer{SCIP.Optimizer}, MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.Model{Float64}}})
    @ MathOptInterface.Utilities ~/.julia/packages/MathOptInterface/zRYzr/src/Utilities/cachingoptimizer.jl:321
 [11] optimize!(model::Model; ignore_optimize_hook::Bool, _differentiation_backend::MathOptInterface.Nonlinear.SparseReverseMode, kwargs::@Kwargs{})
    @ JuMP ~/.julia/packages/JuMP/xlp0s/src/optimizer_interface.jl:595
 [12] optimize!(model::Model)
    @ JuMP ~/.julia/packages/JuMP/xlp0s/src/optimizer_interface.jl:546

I have figured that a simple workaround is simply

set_start_value.(all_variables(loaded_model), start_value.(all_variables(loaded_model)))

before optimizing.

I am running JuMP 1.24.0.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions