Skip to content

Commit 0e54b76

Browse files
authored
[Bridges] throw better error for nonconvex quadratic constraints (#1655)
1 parent 2e969ef commit 0e54b76

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

src/Bridges/Constraint/quad_to_soc.jl

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,17 @@ function bridge_constraint(
7878
F = try
7979
LinearAlgebra.cholesky(LinearAlgebra.Symmetric(Q))
8080
catch
81-
error("""
82-
Unable to transform a quadratic constraint into a second-order cone
83-
constraint because the quadratic constraint is not strongly convex.
84-
85-
Convex constraints that are not strongly convex (i.e., the matrix is
86-
positive semidefinite but not positive definite) are not supported
87-
yet.
88-
89-
Note that a quadratic equality constraint is non-convex.""")
81+
throw(
82+
MOI.UnsupportedConstraint{typeof(func),typeof(set)}(
83+
"Unable to transform a quadratic constraint into a " *
84+
"second-order cone constraint because the quadratic " *
85+
"constraint is not strongly convex.\n\nConvex constraints " *
86+
"that are not strongly convex (i.e., the matrix is positive " *
87+
"semidefinite but not positive definite) are not supported " *
88+
"yet.\n\nNote that a quadratic equality constraint is " *
89+
"non-convex.",
90+
),
91+
)
9092
end
9193
# Construct the VectorAffineFunction. We're aiming for:
9294
# | 1 |

test/Bridges/Constraint/quad_to_soc.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function test_error_for_nonconvex_quadratic_constraints()
2424
mock = MOI.Utilities.MockOptimizer(MOI.Utilities.Model{Float64}())
2525
bridged_mock = MOI.Bridges.Constraint.QuadtoSOC{Float64}(mock)
2626
x = MOI.add_variable(bridged_mock)
27-
@test_throws ErrorException begin
27+
@test_throws(
28+
MOI.UnsupportedConstraint,
2829
MOI.add_constraint(
2930
bridged_mock,
3031
MOI.ScalarQuadraticFunction(
@@ -34,8 +35,9 @@ function test_error_for_nonconvex_quadratic_constraints()
3435
),
3536
MOI.GreaterThan(0.0),
3637
)
37-
end
38-
@test_throws ErrorException begin
38+
)
39+
@test_throws(
40+
MOI.UnsupportedConstraint,
3941
MOI.add_constraint(
4042
bridged_mock,
4143
MOI.ScalarQuadraticFunction(
@@ -45,7 +47,7 @@ function test_error_for_nonconvex_quadratic_constraints()
4547
),
4648
MOI.LessThan(0.0),
4749
)
48-
end
50+
)
4951
return
5052
end
5153

0 commit comments

Comments
 (0)