MathOptInterface.jl icon indicating copy to clipboard operation
MathOptInterface.jl copied to clipboard

Test ConstraintDual for bridges

Open blegat opened this issue 5 months ago • 5 comments

I always thought it a bit silly to only define the setter for ConstraintDualStart and not with ConstraintDual. I sometimes want to test things mixing a MockOptimizer and a bridge and I can't because bridges don't define the setters for ConstraintDual.

I suggest the following non-breaking change: We should now encourage bridges to supports ConstraintDual. When they do, a new test will be enabled that will do an important consistency check. So the new test will not be run for existing bridge which is nice since it could be breaking but after the transition, it will be run for all bridges that don't disable it by doing dual = nothing.

This would have caught the bug in https://github.com/jump-dev/MathOptInterface.jl/pull/2809 as the CI should show

blegat avatar Aug 12 '25 08:08 blegat

I'm still against this. Bridges could/should write better tests regardless. Testing the dual is tricky. And even our Start is a bad test because it checks only get/set doesn't error. It doesn't really have a way to test that the logic is correct.

odow avatar Aug 19 '25 23:08 odow

Yes, we just check that get and set are inverse of each other and that's precisely what this PR is fixing. Now it also checks that it is the adjoint of the bridge transformation so it's starting to get difficult to get the test passing with an incorrect dual

blegat avatar Aug 22 '25 11:08 blegat

Let me take over from here and split it up.

odow avatar Aug 27 '25 03:08 odow

So you added ZeroOne to the fallback for dual objective value because some tests tried to call constant(::ZeroOne)? Why is IndicatorSOS1Bridge even attempting to test the duals?

This design feels wrong. Could dual tests be opt-in?

Is a separate bug that we don't have a generic fallback for constant? The test error violates the MethodError principle.

odow avatar Aug 27 '25 21:08 odow

#2826 removes the use of constant.

odow avatar Aug 28 '25 03:08 odow