From 295e21ad8d736b87f32f55bce4b43fec70dfd660 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Legat?= Date: Wed, 10 Jul 2024 14:13:47 +0200 Subject: [PATCH] Add support for SumOfSquares cone --- Project.toml | 5 +++++ src/Hypatia.jl | 3 +++ src/MathOptInterface/cones.jl | 19 +++++++++++++++++++ 3 files changed, 27 insertions(+) diff --git a/Project.toml b/Project.toml index 611e8e0b6..c6bdb38a4 100644 --- a/Project.toml +++ b/Project.toml @@ -11,12 +11,17 @@ IterativeSolvers = "42fd0dbc-a981-5370-80f2-aaf504508153" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e" MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +MultivariateBases = "be282fd4-ad43-11e9-1d11-8bd9d7e43378" +MultivariateMoments = "f4abf1af-0426-5881-a0da-e2f168889b5e" PolynomialRoots = "3a141323-8675-5d76-9d11-e1df1406c778" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Requires = "ae029012-a4dd-5104-9daa-d747884805df" SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" +StarAlgebras = "0c0c59c1-dc5f-42e9-9a8b-b5dc384a6cd1" SuiteSparse = "4607b0f0-06f3-5cda-b6b1-a6196a1729e9" +SumOfSquares = "4b9e565b-77fc-50a5-a571-1244f986bda1" +SymbolicWedderburn = "858aa9a9-4c7c-4c62-b466-2421203962a2" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] diff --git a/src/Hypatia.jl b/src/Hypatia.jl index 3b3f55d91..42c2fdf22 100644 --- a/src/Hypatia.jl +++ b/src/Hypatia.jl @@ -44,6 +44,9 @@ const VI = MOI.VariableIndex const SAF = MOI.ScalarAffineFunction const VV = MOI.VectorOfVariables const VAF = MOI.VectorAffineFunction +import StarAlgebras +import MultivariateBases +import SumOfSquares include("MathOptInterface/cones.jl") include("MathOptInterface/transform.jl") include("MathOptInterface/wrapper.jl") diff --git a/src/MathOptInterface/cones.jl b/src/MathOptInterface/cones.jl index d4c67a35a..a1a84f1e4 100644 --- a/src/MathOptInterface/cones.jl +++ b/src/MathOptInterface/cones.jl @@ -635,6 +635,24 @@ function cone_from_moi( return Cones.WSOSInterpNonnegative{T, R}(cone.U, cone.Ps, use_dual = cone.use_dual) end +function _transformation_to(lag::MultivariateBases.LagrangeBasis, gram, weight) + return StarAlgebras.coeffs(weight, lag) .* MultivariateBases.transformation_to(gram, lag) +end + +function cone_from_moi( + ::Type{T}, + cone::SumOfSquares.WeightedSOSCone{MOI.PositiveSemidefiniteConeTriangle,<:MultivariateBases.LagrangeBasis}, +) where {T<:Real} + return cone_from_moi( + T, + WSOSInterpNonnegativeCone{T,T}( + length(cone.basis), + _transformation_to.(Ref(cone.basis), cone.gram_bases, cone.weights), + ), + ) +end + + """ $(TYPEDEF) @@ -785,6 +803,7 @@ const SupportedCone{T <: Real} = Union{ MOI.DualExponentialCone, MOI.LogDetConeTriangle, MOI.RelativeEntropyCone, + SumOfSquares.WeightedSOSCone{MOI.PositiveSemidefiniteConeTriangle,<:MultivariateBases.LagrangeBasis}, } Base.copy(cone::HypatiaCones) = cone # maybe should deep copy the cone struct, but this is expensive