Skip to content

Commit def69e1

Browse files
authored
Revert LDLFactorizations package extension (#2972)
1 parent dc2a3aa commit def69e1

File tree

4 files changed

+20
-113
lines changed

4 files changed

+20
-113
lines changed

Project.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,13 @@ SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
1818
SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b"
1919
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2020

21-
[weakdeps]
22-
LDLFactorizations = "40e66cde-538c-5869-a4ad-c39174c6795b"
23-
24-
[extensions]
25-
MathOptInterfaceLDLFactorizationsExt = "LDLFactorizations"
26-
2721
[compat]
2822
BenchmarkTools = "1"
2923
CodecBzip2 = "0.6, 0.7, 0.8"
3024
CodecZlib = "0.6, 0.7"
3125
ForwardDiff = "1"
3226
JSON = "0.21, 1"
3327
JSONSchema = "1"
34-
LDLFactorizations = "0.10"
3528
LinearAlgebra = "1"
3629
MutableArithmetics = "1"
3730
NaNMath = "0.3, 1"
@@ -45,9 +38,8 @@ Test = "1"
4538
julia = "1.10"
4639

4740
[extras]
48-
LDLFactorizations = "40e66cde-538c-5869-a4ad-c39174c6795b"
4941
JSONSchema = "7d188eb4-7ad8-530c-ae41-71a32a6d4692"
5042
ParallelTestRunner = "d3525ed8-44d0-4b2c-a655-542cee43accc"
5143

5244
[targets]
53-
test = ["LDLFactorizations", "JSONSchema", "ParallelTestRunner"]
45+
test = ["JSONSchema", "ParallelTestRunner"]

ext/MathOptInterfaceLDLFactorizationsExt.jl

Lines changed: 0 additions & 50 deletions
This file was deleted.

src/Bridges/Constraint/bridges/QuadtoSOCBridge.jl

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,6 @@ end
6060
const QuadtoSOC{T,OT<:MOI.ModelLike} =
6161
SingleBridgeOptimizer{QuadtoSOCBridge{T},OT}
6262

63-
function compute_sparse_sqrt_fallback(Q, ::F, ::S) where {F,S}
64-
msg = """
65-
Unable to transform a quadratic constraint into a SecondOrderCone
66-
constraint because the quadratic constraint is not strongly convex and
67-
our Cholesky decomposition failed.
68-
69-
If the constraint is convex but not strongly convex, you can work-around
70-
this issue by manually installing and loading `LDLFactorizations.jl`:
71-
```julia
72-
import Pkg; Pkg.add("LDLFactorizations")
73-
using LDLFactorizations
74-
```
75-
76-
LDLFactorizations.jl is not included by default because it is licensed
77-
under the LGPL.
78-
"""
79-
return throw(MOI.AddConstraintNotAllowed{F,S}(msg))
80-
end
81-
8263
function compute_sparse_sqrt(Q, func, set)
8364
# There's a big try-catch here because Cholesky can fail even if
8465
# `check = false`. As one example, it currently (v1.12) fails with
@@ -88,22 +69,20 @@ function compute_sparse_sqrt(Q, func, set)
8869
# The try-catch isn't a performance concern because the alternative is not
8970
# being able to reformulate the problem.
9071
try
91-
factor = LinearAlgebra.cholesky(Q; check = false)
92-
if !LinearAlgebra.issuccess(factor)
93-
return compute_sparse_sqrt_fallback(Q, func, set)
94-
end
72+
factor = LinearAlgebra.cholesky(Q)
9573
L, p = SparseArrays.sparse(factor.L), factor.p
9674
# We have Q = P' * L * L' * P. We want to find Q = U' * U, so U = L' * P
9775
# First, compute L'. Note I and J are reversed
9876
J, I, V = SparseArrays.findnz(L)
9977
# Then, we want to permute the columns of L'. The rows stay in the same
10078
# order.
10179
return I, p[J], V
102-
catch err
103-
if err isa MOI.AddConstraintNotAllowed
104-
rethrow(err)
105-
end
106-
msg = "There was an error computing a matrix square root"
80+
catch
81+
msg = """
82+
Unable to transform a quadratic constraint into a SecondOrderCone
83+
constraint because the quadratic constraint is not strongly convex and
84+
our Cholesky decomposition failed.
85+
"""
10786
throw(MOI.UnsupportedConstraint{typeof(func),typeof(set)}(msg))
10887
end
10988
end

test/Bridges/Constraint/test_QuadtoSOCBridge.jl

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import LinearAlgebra
1010
import SparseArrays
1111
using Test
1212

13-
import LDLFactorizations
1413
import MathOptInterface as MOI
1514

1615
function runtests()
@@ -345,13 +344,16 @@ function test_semidefinite_cholesky_fail()
345344
model = MOI.Bridges.Constraint.QuadtoSOC{Float64}(inner)
346345
x = MOI.add_variables(model, 2)
347346
f = 0.5 * x[1] * x[1] + 1.0 * x[1] * x[2] + 0.5 * x[2] * x[2]
348-
c = MOI.add_constraint(model, f, MOI.LessThan(1.0))
349-
F, S = MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone
350-
ci = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
351-
g = MOI.get(inner, MOI.ConstraintFunction(), ci)
352-
y = MOI.get(inner, MOI.ListOfVariableIndices())
353-
sum_y = 1.0 * y[1] + 1.0 * y[2]
354-
@test isapprox(g, MOI.Utilities.vectorize([1.0, 1.0, sum_y, 0.0]))
347+
@test_throws(
348+
MOI.UnsupportedConstraint,
349+
MOI.add_constraint(model, f, MOI.LessThan(1.0)),
350+
)
351+
# F, S = MOI.VectorAffineFunction{Float64}, MOI.RotatedSecondOrderCone
352+
# ci = only(MOI.get(inner, MOI.ListOfConstraintIndices{F,S}()))
353+
# g = MOI.get(inner, MOI.ConstraintFunction(), ci)
354+
# y = MOI.get(inner, MOI.ListOfVariableIndices())
355+
# sum_y = 1.0 * y[1] + 1.0 * y[2]
356+
# @test isapprox(g, MOI.Utilities.vectorize([1.0, 1.0, sum_y, 0.0]))
355357
return
356358
end
357359

@@ -361,12 +363,8 @@ function test_compute_sparse_sqrt_edge_cases()
361363
[1.0 0.0; 0.0 2.0],
362364
# Cholesky works, with pivoting
363365
[1.0 0.0 1.0; 0.0 1.0 1.0; 1.0 1.0 3.0],
364-
# Cholesky fails due to 0 eigen value. LDL works
365-
[1.0 1.0; 1.0 1.0],
366366
# Cholesky succeeds, even though 0 eigen value
367367
[2.0 2.0; 2.0 2.0],
368-
# Cholesky fails because of 0 column/row. LDL works
369-
[2.0 0.0; 0.0 0.0],
370368
]
371369
B = SparseArrays.sparse(A)
372370
f = zero(MOI.ScalarQuadraticFunction{eltype(A)})
@@ -381,6 +379,8 @@ function test_compute_sparse_sqrt_edge_cases()
381379
# Test failures
382380
for A in Any[
383381
[-1.0 0.0; 0.0 1.0],
382+
[1.0 1.0; 1.0 1.0],
383+
[2.0 0.0; 0.0 0.0],
384384
# Found from test_quadratic_nonconvex_constraint_basic
385385
[0.0 -1.0; -1.0 0.0],
386386
# Different element type. We could potentially make this work in future,
@@ -400,20 +400,6 @@ function test_compute_sparse_sqrt_edge_cases()
400400
return
401401
end
402402

403-
function test_compute_sparse_sqrt_fallback()
404-
# Test the default fallback that is hit when LDLFactorizations isn't loaded.
405-
# We could put the test somewhere else so it runs before this file is
406-
# loaded, but that's pretty flakey for a long-term solution. Instead, we're
407-
# going to abuse the lack of a strong type signature to hit it:
408-
f = zero(MOI.ScalarAffineFunction{Float64})
409-
A = SparseArrays.sparse([-1.0 0.0; 0.0 1.0])
410-
@test_throws(
411-
MOI.AddConstraintNotAllowed{typeof(f),MOI.GreaterThan{Float64}},
412-
MOI.Bridges.Constraint.compute_sparse_sqrt(A, f, MOI.GreaterThan(0.0)),
413-
)
414-
return
415-
end
416-
417403
end # module
418404

419405
TestConstraintQuadToSOC.runtests()

0 commit comments

Comments
 (0)