Fix BridgeableConstraint with model_convert#4183
Open
blegat wants to merge 1 commit into
Open
Conversation
1 task
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4183 +/- ##
=======================================
Coverage 99.93% 99.93%
=======================================
Files 42 42
Lines 6230 6231 +1
=======================================
+ Hits 6226 6227 +1
Misses 4 4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
odow
reviewed
Jun 28, 2026
| # `model_convert` normalizes the bridge coefficient type to the value type of | ||
| # the model (`Float64`), even though `BridgeMe` requested `Int`. | ||
| @test NonnegativeBridge{Float64} in model.bridge_types | ||
| @test !(NonnegativeBridge{Int} in model.bridge_types) |
Member
There was a problem hiding this comment.
Suggested change
| @test !(NonnegativeBridge{Int} in model.bridge_types) | |
| @test !(NonnegativeBridge{Int} in model.bridge_types) | |
| return |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tried fixing jump-dev/SumOfSquares.jl#444 with Claude but he got really confused.
The root cause it that the way
model_convertworks is a bit unclear and inconsistent.When you call
@constraint(model, ...), we first create anAbstractConstraintwithbuild_constraint. There we don't have the model type so we cannot convert yet.Then, in the macro code itself we call
model_convert:JuMP.jl/src/macros/@constraint.jl
Lines 188 to 206 in 44397c7
Then we pass the converted
AbstractConstrainttoadd_constraintwhich then also callsmodel_convert:JuMP.jl/src/constraints.jl
Line 1046 in 44397c7
It a bit redundant. I checked and both were added in github.com//pull/3385.
The advantages of doing it in
add_constraintare that 1) it's easier to maintain method implementations that macro code and 2) we don't need to do a broadcast in case of the vectorization.In PolyJuMP, we create a constraint outside the macro so we rely on the
model_convertinadd_constraint.https://github.com/jump-dev/PolyJuMP.jl/blob/571a9874547ea44efe38822e073a3aecffdb127c/src/constraint.jl#L282-L288
However, we didn't call
model_convertthere so that's an issue.So there are a few ways to fix the issue in SumOfSquares. In all of them, we need the fix in
model_convertofBridgeableConstraint. The question is, where shouldmodel_convertbe called.We should decide who's responsibility it is to call
model_convert, is itadd_constraintoradd_constraint.In case
model_convertinadd_constraint(::AbstractModel, ::AbstractConstraint)(we may consider it breaking but that would only be for users that weren't using the macro so unclear if it's a big deal) and in casemodel_convertinadd_constraint(::GenericModel, ::BridgeableConstraint)like done in this PR and then also remove themodel_convertcalled from the macro.