Skip to content

Commit

Permalink
Merge pull request #2203 from yashcodes/Debug_info_for_unsupported_co…
Browse files Browse the repository at this point in the history
…nstraints

Debug info for unsupported constraints
  • Loading branch information
blegat committed Jul 1, 2020
2 parents c43b1f1 + afcd15f commit 70fe5a1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/JuMP.jl
Expand Up @@ -19,6 +19,7 @@ const _MA = MutableArithmetics
import MathOptInterface
const MOI = MathOptInterface
const MOIU = MOI.Utilities
const MOIB = MOI.Bridges

import Calculus
import DataStructures.OrderedDict
Expand Down
2 changes: 1 addition & 1 deletion src/constraints.jl
Expand Up @@ -381,7 +381,7 @@ function moi_add_constraint(model::MOI.ModelLike, f::MOI.AbstractFunction,
if moi_mode(model) == DIRECT
bridge_message = "."
elseif moi_bridge_constraints(model)
bridge_message = " and there are no bridges that can reformulate it into supported constraints."
error(sprint(io -> MOI.Bridges.debug(model.optimizer, typeof(f), typeof(s); io = io)))
else
bridge_message = ", try using `bridge_constraints=true` in the `JuMP.Model` constructor if you believe the constraint can be reformulated to constraints supported by the solver."
end
Expand Down
18 changes: 14 additions & 4 deletions test/model.jl
Expand Up @@ -290,10 +290,20 @@ function test_model()
end
@testset "after loading the constraint to the optimizer" begin
@testset "optimizer set at Model" begin
err = ErrorException(string("Constraints of type ",
"MathOptInterface.SingleVariable-in-Nonnegative are not ",
"supported by the solver and there are no bridges that ",
"can reformulate it into supported constraints."))
error_string = """
Constrained variables in `Nonnegative` are not supported and cannot be bridged into supported constrained variables and constraints. See details below:
[1] constrained variables in `Nonnegative` are not supported because no added bridge supports bridging it.
Cannot add free variables and then constrain them because:
(1) `MOI.SingleVariable`-in-`Nonnegative` constraints are not supported
(1) `MOI.SingleVariable`-in-`Nonnegative` constraints are not supported because:
Cannot use `MOIB.Constraint.ScalarFunctionizeBridge{Float64,Nonnegative}` because:
(2) `MOI.ScalarAffineFunction{Float64}`-in-`Nonnegative` constraints are not supported
(2) `MOI.ScalarAffineFunction{Float64}`-in-`Nonnegative` constraints are not supported because:
Cannot use `MOIB.Constraint.ScalarSlackBridge{Float64,MOI.ScalarAffineFunction{Float64},Nonnegative}` because:
[1] constrained variables in `Nonnegative` are not supported
"""
err = ErrorException(error_string)

model = Model(mock_factory)
@variable(model, x)
@test_throws err @constraint(model, x in Nonnegative())
Expand Down

0 comments on commit 70fe5a1

Please sign in to comment.