Skip to content

Conversation

odow
Copy link
Member

@odow odow commented Aug 17, 2025

Closes #2817

I don't think this is the proper fix. But passes the test. I want to run solver-tests with it if CI is green

https://github.com/jump-dev/MathOptInterface.jl/actions/runs/17026926756

@odow

This comment was marked as outdated.

@odow

This comment was marked as outdated.

@odow odow changed the title [Bridges] fix deleting variable with constraint bridged from scalar to vector [Bridges] fix deleting variable with constraint bridges Aug 18, 2025
@odow
Copy link
Member Author

odow commented Aug 18, 2025

The underlying cause is the same as #2696

We don't really have a chain-of-custody to discriminate constraints that were added by the user at the top level from constraints added by bridges, unless we walk all the bridges to check.

julia> MOI.Utilities.@model(
           Model2817b,
           (),
           (MOI.LessThan,),
           (),
           (),
           (),
           (MOI.ScalarAffineFunction,),
           (),
           ()
       );

julia> function MOI.supports_constraint(
           ::Model2817b,
           ::Type{MOI.VariableIndex},
           ::Type{S},
       ) where {S<:MOI.AbstractScalarSet}
           return false
       end

julia> model = MOI.instantiate(Model2817b{Float64}; with_bridge_type = Float64);

julia> y, _ = MOI.add_constrained_variables(model, MOI.Nonpositives(1));

julia> ci = MOI.ConstraintIndex{MOI.VariableIndex,MOI.LessThan{Float64}}(1)
MathOptInterface.ConstraintIndex{MathOptInterface.VariableIndex, MathOptInterface.LessThan{Float64}}(1)

julia> MOI.is_valid(model, ci)
true

@odow
Copy link
Member Author

odow commented Aug 18, 2025

@odow
Copy link
Member Author

odow commented Aug 18, 2025

Okay. I think that's everything passing tests at least. Now to document what exactly I did...

@odow
Copy link
Member Author

odow commented Aug 18, 2025

Because of the false positive potential in
`is_valid(::AbstractBridgeOptimizer, MOI.ConstraintIndex)`, we need to ensure
that we delete constraints only if they were not added by a different constraint
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by different bridge ? It seems to me that if a bridge tries to delete a variable, now it won't delete any constraint created on that variable. So we are kind of assuming that the bridges can't rely on the fact that when they delete variables, the constraint on this variable won't be delete automatically, while the user can expect this behavior

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe I need to check this. I thought if a bridge deletes a variable it will, by the logic in this function, delete the related constraints.

@blegat
Copy link
Member

blegat commented Aug 18, 2025

I think we should also clarify in the docstring of delete for bridges that they should delete all constraints by themself and not rely on the automatic deletion of variable-constraints that are deleted by the variables.

@odow
Copy link
Member Author

odow commented Aug 19, 2025

for bridges that they should delete all constraints by themself and not rely on the automatic deletion of variable-constraints that are deleted by the variables

I don't think this is necessary. Do you have an example that fails? If a bridge has, for example, added a binary variable, the ZeroOne constraint can't exist if the variable has been deleted.

@odow
Copy link
Member Author

odow commented Aug 19, 2025

@odow
Copy link
Member Author

odow commented Aug 19, 2025

Confirmed that it's not necessary, and I've added a test for it.

@odow odow merged commit bd8918d into master Aug 19, 2025
31 checks passed
@odow odow deleted the od/2817 branch August 19, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Deletion bug in bridges
2 participants