Skip to content

Commit 6dec535

Browse files
authored
Fix error message for LDL factorization failures (#2956)
1 parent f83a565 commit 6dec535

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

ext/MathOptInterfaceLDLFactorizationsExt.jl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ function MOI.Bridges.Constraint.compute_sparse_sqrt_fallback(
2121
) where {F<:MOI.ScalarQuadraticFunction,S<:MOI.AbstractSet}
2222
n = LinearAlgebra.checksquare(Q)
2323
factor = LDLFactorizations.ldl(Q)
24-
if minimum(factor.D) < 0
24+
# Ideally we should use `LDLFactorizations.factorized(factor)` here, but it
25+
# has some false negatives. Instead we check that the factorization appeared
26+
# to work. This is a heuristic. There might be other cases where check is
27+
# insufficient.
28+
if minimum(factor.D) < 0 || any(issubnormal, factor.D)
2529
msg = """
2630
Unable to transform a quadratic constraint into a SecondOrderCone
2731
constraint because the quadratic constraint is not convex.

test/Bridges/Constraint/test_QuadtoSOCBridge.jl

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -363,11 +363,11 @@ function test_compute_sparse_sqrt_edge_cases()
363363
[1.0 0.0; 0.0 2.0],
364364
# Cholesky works, with pivoting
365365
[1.0 0.0 1.0; 0.0 1.0 1.0; 1.0 1.0 3.0],
366-
# Cholesky fails due to 0 eigen value
366+
# Cholesky fails due to 0 eigen value. LDL works
367367
[1.0 1.0; 1.0 1.0],
368368
# Cholesky succeeds, even though 0 eigen value
369369
[2.0 2.0; 2.0 2.0],
370-
# Cholesky fails because of 0 column/row
370+
# Cholesky fails because of 0 column/row. LDL works
371371
[2.0 0.0; 0.0 0.0],
372372
]
373373
B = SparseArrays.sparse(A)
@@ -378,12 +378,18 @@ function test_compute_sparse_sqrt_edge_cases()
378378
end
379379
@test isapprox(A, U' * U; atol = 1e-10)
380380
end
381-
A = [-1.0 0.0; 0.0 1.0]
382-
B = SparseArrays.sparse(A)
383-
@test_throws(
384-
MOI.UnsupportedConstraint{typeof(f),typeof(s)},
385-
MOI.Bridges.Constraint.compute_sparse_sqrt(B, f, s),
386-
)
381+
# Test failures
382+
for A in [
383+
[-1.0 0.0; 0.0 1.0],
384+
# Found from test_quadratic_nonconvex_constraint_basic
385+
[0.0 -1.0; -1.0 0.0],
386+
]
387+
B = SparseArrays.sparse(A)
388+
@test_throws(
389+
MOI.UnsupportedConstraint{typeof(f),typeof(s)},
390+
MOI.Bridges.Constraint.compute_sparse_sqrt(B, f, s),
391+
)
392+
end
387393
return
388394
end
389395

0 commit comments

Comments
 (0)