From 3379af5fb62c6e2924cc7026918db06f04e8d71e Mon Sep 17 00:00:00 2001 From: odow Date: Mon, 28 Feb 2022 14:31:10 +1300 Subject: [PATCH 1/3] [Bridges] error in RSOCtoPSD when dimension is 2 --- src/Bridges/Constraint/soc_to_psd.jl | 11 ++++++++++- test/Bridges/Constraint/soc_to_psd.jl | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Bridges/Constraint/soc_to_psd.jl b/src/Bridges/Constraint/soc_to_psd.jl index 3c5ef137b9..ee3e147c46 100644 --- a/src/Bridges/Constraint/soc_to_psd.jl +++ b/src/Bridges/Constraint/soc_to_psd.jl @@ -120,13 +120,16 @@ function MOIB.inverse_adjoint_map_function( end """ -The `RSOCtoPSDBridge` transforms the second order cone constraint ``\\lVert x \\rVert \\le 2tu`` with ``u \\ge 0`` into the semidefinite cone constraints +The `RSOCtoPSDBridge` transforms the second order cone constraint +``\\lVert x \\rVert \\le 2tu`` with ``u \\ge 0`` into the semidefinite cone +constraints ```math \\begin{pmatrix} t & x^\\top\\\\ x & 2uI \\end{pmatrix} \\succeq 0 ``` + Indeed by the Schur Complement, it is positive definite iff ```math \\begin{align*} @@ -179,6 +182,12 @@ end function MOIB.map_function(::Type{<:RSOCtoPSDBridge{T}}, func) where {T} scalars = MOIU.eachscalar(func) + if length(scalars) < 3 + error( + "Unable to bridge RotatedSecondOrderCone to PSD because the ", + "dimension is too small." + ) + end h = MOIU.operate!(*, T, scalars[2], convert(T, 2)) return _SOCtoPSDaff(T, scalars[[1; 3:length(scalars)]], h) end diff --git a/test/Bridges/Constraint/soc_to_psd.jl b/test/Bridges/Constraint/soc_to_psd.jl index 6b4567fd62..7907bb159c 100644 --- a/test/Bridges/Constraint/soc_to_psd.jl +++ b/test/Bridges/Constraint/soc_to_psd.jl @@ -150,6 +150,22 @@ function test_RSOCtoPSD() return end +# TODO(odow): we should fix this so it does not error. +function test_rsoc_to_psd_dimension_2() + inner = MOI.Utilities.Model{Float64}() + model = MOI.Bridges.Constraint.RSOCtoPSD{Float64}(inner) + x = MOI.add_variables(model, 2) + @test_throws( + ErrorException, + MOI.add_constraint( + model, + MOI.VectorOfVariables(x), + MOI.RotatedSecondOrderCone(2), + ), + ) + return +end + end # module TestConstraintSOCtoPSD.runtests() From 3d76ef892c3b598f5da647261a7ddb06a024aa33 Mon Sep 17 00:00:00 2001 From: Oscar Dowson Date: Mon, 28 Feb 2022 14:45:02 +1300 Subject: [PATCH 2/3] Update src/Bridges/Constraint/soc_to_psd.jl --- src/Bridges/Constraint/soc_to_psd.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/Constraint/soc_to_psd.jl b/src/Bridges/Constraint/soc_to_psd.jl index ee3e147c46..b778cb89bb 100644 --- a/src/Bridges/Constraint/soc_to_psd.jl +++ b/src/Bridges/Constraint/soc_to_psd.jl @@ -185,7 +185,7 @@ function MOIB.map_function(::Type{<:RSOCtoPSDBridge{T}}, func) where {T} if length(scalars) < 3 error( "Unable to bridge RotatedSecondOrderCone to PSD because the ", - "dimension is too small." + "dimension is too small.", ) end h = MOIU.operate!(*, T, scalars[2], convert(T, 2)) From 28ce937e4481c13b0350acd778493f69740bd0db Mon Sep 17 00:00:00 2001 From: odow Date: Tue, 1 Mar 2022 11:04:43 +1300 Subject: [PATCH 3/3] Add length --- src/Bridges/Constraint/soc_to_psd.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bridges/Constraint/soc_to_psd.jl b/src/Bridges/Constraint/soc_to_psd.jl index b778cb89bb..a4cdc4e5cf 100644 --- a/src/Bridges/Constraint/soc_to_psd.jl +++ b/src/Bridges/Constraint/soc_to_psd.jl @@ -185,7 +185,7 @@ function MOIB.map_function(::Type{<:RSOCtoPSDBridge{T}}, func) where {T} if length(scalars) < 3 error( "Unable to bridge RotatedSecondOrderCone to PSD because the ", - "dimension is too small.", + "dimension is too small: got $(length(scalars)), expected >= 3.", ) end h = MOIU.operate!(*, T, scalars[2], convert(T, 2))