How can I forcefully bridge sum-of-squares constraints into PSD constraints?

It’s getting a little into the depths of JuMP and MOI, but you could do something like this:

using DynamicPolynomials
using SumOfSquares

@polyvar x1 x2
f1 = x1 + x2 + 1
f2 = 19 - 14x1 + 3x1^2 - 14x2 + 6x1*x2 + 3x2^2
f3 = 2x1 - 3x2
f4 = 18 - 32x1 + 12x1^2 + 48x2 - 36x1*x2 + 27x2^2
f = (1 + f1^2 * f2) * (30 + f3^2 * f4)

MOI.Utilities.@model(
    MyNewModel,
    (),
    (),
    (MOI.Nonnegatives,MOI.PositiveSemidefiniteConeTriangle),
    (),
    (),
    (),
    (),
    (MOI.VectorAffineFunction,),
    true,
)

model = SOSModel(MyNewModel{Float64})
@variable(model, γ)
@objective(model, Max, γ)
@constraint(model, f >= γ)
MOI.Utilities.attach_optimizer(model)
moi_model = backend(model).optimizer.model

julia> MOI.get(moi_model, MOI.ListOfConstraints())
2-element Vector{Tuple{DataType, DataType}}:
 (MathOptInterface.VectorAffineFunction{Float64}, MathOptInterface.Nonnegatives)
 (MathOptInterface.VectorAffineFunction{Float64}, MathOptInterface.PositiveSemidefiniteConeTriangle)

(p.s. The next version of JuMP will make this much easier by exposing an unsafe_backend function to avoid the .optimizer.model mess.)

1 Like