[MOI / JuMP] Multiple Result Indexing Bug

While developing tests for my JuMP extension in accordance with the newly supported multiple result indexing, I discovered that the same MOI attribute value is returned irrespective of the result index (returning the value of whatever was set last). This behavior is demonstrated in the following minimum working example using JuMP v0.21.1 and MOI v0.9.11:

using JuMP, MathOptInterface; const MOI = MathOptInterface; const MOIU = MOI.Utilities
m = Model()
@variable(m, x >= 0.0)
set_optimizer(m,  () -> MOIU.MockOptimizer( MOIU.Model{Float64}(), 
                       eval_objective_value = false))

mock = JuMP.backend(m).optimizer.model
MOI.set(mock, MOI.TerminationStatus(), MOI.OPTIMAL)
MOI.set(mock, MOI.ResultCount(), 2)
MOI.set(mock, MOI.VariablePrimal(1), JuMP.optimizer_index(x), 1.0)
MOI.set(mock, MOI.VariablePrimal(2), JuMP.optimizer_index(x), 0.0)

value1 = value(x, result = 1) # should be 1.0
value2 = value(x, result = 2) # should be 0.0

println("Result 1:  ", value1)
println("Result 2:  ", value2)
Result 1:  0.0 # not correct
Result 2:  0.0 # correct

Is this a bug with MOI and/or JuMP?

It’s an issue with the mock optimizer.

Please open an issue at MathOptInterface.jl. Pull requests to add result indices to MockOptimizer appreciated.

Gotcha. I just opened an issue. https://github.com/JuliaOpt/MathOptInterface.jl/issues/1036