Skip to content

Conversation

odow
Copy link
Member

@odow odow commented Sep 8, 2021

This one is a real doozy that took me while to isolate. Two dueling bugs here:

  • MOI.VectorOfVariables(λ) should have been MOI.VectorOfVariables(η)
  • λ was boxed and causing some weird failure with CPLEX.

Note the λ@_5::Core.Box.

julia> function main(model)
           MOI.empty!(model)    
           function _add_SOS2()
               λ = MOI.add_variables(model, 2)
               c = MOI.add_constraint(
                   model,
                   MOI.VectorOfVariables(λ), 
                   MOI.SOS2{Float64}([1.0, 2.0, 3.0]),
               )
               return λ, c
           end
           x = MOI.add_variables(model, 2)
           λ, c1 = _add_SOS2(model)
           MOI.delete(model, c1)
           MOI.add_constraint(
               model,
               MOI.VectorOfVariables(λ),
               MOI.SOS2{Float64}([1.0, 2.0, 3.0]),
           )
           MOI.optimize!(model)
           return
       end
main (generic function with 1 method)

julia> @code_warntype main(CPLEX.Optimizer())
Variables
  #self#::Core.Const(main)
  model::CPLEX.Optimizer
  @_3::Union{}
  c1::Union{}
  λ@_5::Core.Box
  x::Vector{MathOptInterface.VariableIndex}
  _add_SOS2::var"#_add_SOS2#18"{CPLEX.Optimizer}
  λ@_8::Union{}

Body::Union{}
1 ─      (λ@_5 = Core.Box())
│   %2 = MathOptInterface.empty!::Core.Const(MathOptInterface.empty!)
│        (%2)(model)
│   %4 = Main.:(var"#_add_SOS2#18")::Core.Const(var"#_add_SOS2#18")
│   %5 = Core.typeof(model)::Core.Const(CPLEX.Optimizer)
│   %6 = Core.apply_type(%4, %5)::Core.Const(var"#_add_SOS2#18"{CPLEX.Optimizer})
│        (_add_SOS2 = %new(%6, model, λ@_5))
│   %8 = MathOptInterface.add_variables::Core.Const(MathOptInterface.add_variables)
│        (x = (%8)(model, 2))
│        (_add_SOS2)(model)
│        Core.Const(:(Base.indexed_iterate(%10, 1)))
│        Core.Const(:(Core.getfield(%11, 1)))
│        Core.Const(:(Core.setfield!@_5, :contents, %12)))
│        Core.Const(:(@_3 = Core.getfield(%11, 2)))
│        Core.Const(:(Base.indexed_iterate(%10, 2, @_3)))
│        Core.Const(:(c1 = Core.getfield(%15, 1)))
│        Core.Const(:(MathOptInterface.delete))
│        Core.Const(:((%17)(model, c1)))
│        Core.Const(:(MathOptInterface.add_constraint))
│        Core.Const(:(MathOptInterface.VectorOfVariables))
│        Core.Const(:(Core.isdefined@_5, :contents)))
│        Core.Const(:(%21))
│        Core.Const(:(goto %26))
│        Core.Const(Core.NewvarNode(:(λ@_8)))
│        Core.Const(:(λ@_8))
│        Core.Const(:(Core.getfield@_5, :contents)))
│        Core.Const(:((%20)(%26)))
│        Core.Const(:(MathOptInterface.SOS2))
│        Core.Const(:(Core.apply_type(%28, Main.Float64)))
│        Core.Const(:(Base.vect(1.0, 2.0, 3.0)))
│        Core.Const(:((%29)(%30)))
│        Core.Const(:((%19)(model, %27, %31)))
│        Core.Const(:(MathOptInterface.optimize!))
│        Core.Const(:((%33)(model)))
└──      Core.Const(:(return nothing))

@odow odow added the Submodule: Tests About the Tests submodule label Sep 8, 2021
@odow odow merged commit 2cfa951 into master Sep 8, 2021
@odow odow deleted the od/sos2 branch September 8, 2021 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Submodule: Tests About the Tests submodule
Development

Successfully merging this pull request may close these issues.

1 participant