# How do I model a combination of polynomial and SOC constraints?

**URL:** <https://discourse.julialang.org/t/how-do-i-model-a-combination-of-polynomial-and-soc-constraints/108968>\
**Category:** Optimization (Mathematical)\
**Created:** [January 18, 2024, 3:03pm UTC](https://discourse.julialang.org/t/how-do-i-model-a-combination-of-polynomial-and-soc-constraints/108968 "2024-01-18T15:03:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Khr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/khr/32/206305_2.png) [@Khr](https://discourse.julialang.org/u/Khr)\
**Post date:** [January 18, 2024, 3:03pm UTC](https://discourse.julialang.org/t/how-do-i-model-a-combination-of-polynomial-and-soc-constraints/108968/1 "2024-01-18T15:03:49Z")

</div>

I have a problem consisting of both polynomial constraints (using the `PolyJuMP`), with nonnegativity requirements on a certain domain, which should be able to be handled using the `SumOfSquares` package and several second-order conic constraints. In short, I am having trouble including all the constraints and finding a solver to recognize the structure and start working. Specifically, I create two polynomial variables and both a nonnegativity and SOC constraint:

```julia
using JuMP
using PolyJuMP

using LinearAlgebra

using SumOfSquares
using DynamicPolynomials

model = SOSModel(CSDP.Optimizer)

# Variables
@polyvar xvar yvar
X = monomials([x, y], 0:2)
poly = @variable(model, poly, Poly(X))

domain = @set yvar == 1

# Nonnegativity constraint on domain
@constraint(model, poly >= 0, domain = domain)

poly_dx = differentiate(poly, xvar)
poly_dy = differentiate(poly, yvar)

poly_dx_val = poly_dx(1, 1)
poly_dy_val = poly_dy(1, 1)

term_val = norm([1; poly_dx_val; poly_dy_val])

obj_var = @variable(model, obj_var)

# SOC constraint
@constraint(model, obj_var >= term_val)

@objective(model, Min, obj_var)

```

However, I get a

```julia
LoadError: MathOptInterface.UnsupportedNonlinearOperator: The nonlinear operator `:norm` is not supported by the model.

```

As an alternative, I made the constraint more explicit:

```julia
term_val_sq = 1 + (poly_dx_val)^2 + (poly_dy_val)^2
@constraint(model, 0 >= term_val_sq - (obj_var^2))
@constraint(model, obj_var >= 0)

```

In that case I get the error

```julia
ERROR: LoadError: MathOptInterface.UnsupportedConstraint{MathOptInterface.ScalarQuadraticFunction{Float64}, MathOptInterface.GreaterThan{Float64}}: `MathOptInterface.ScalarQuadraticFunction{Float64}`-in-`MathOptInterface.GreaterThan{Float64}` constraint is not supported by the model: Unable to transform a quadratic constraint into a second-order 
cone constraint because the quadratic constraint is not strongly convex.

```

even though the constraint should be convex. Any ideas on why I get these errors? Is there another optimizer backend which may work?

---

<div class="post-metadata">

**Author:** ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)\
**Post date:** [January 18, 2024, 8:14pm UTC](https://discourse.julialang.org/t/how-do-i-model-a-combination-of-polynomial-and-soc-constraints/108968/2 "2024-01-18T20:14:04Z")

</div>

Hi @Khr, welcome to the forum.

To create an SOC constraint, you need to use the `SecondOrderCone()` syntax ([Constraints · JuMP](https://jump.dev/JuMP.jl/stable/manual/constraints/#Second-order-cone-constraints)).

Here’s how I’d write your model:

```julia
using CSDP
using DynamicPolynomials
using JuMP
using LinearAlgebra
using PolyJuMP
using SumOfSquares
model = SOSModel(CSDP.Optimizer)
@polyvar(x, y)
X = monomials([x, y], 0:2)
poly = @variable(model, poly, Poly(X))
@constraint(model, poly >= 0, domain = @set(y == 1))
poly_dx = differentiate(poly, x)
poly_dy = differentiate(poly, y)
@variable(model, t)
@constraint(model, [t, 1, poly_dx(1, 1), poly_dy(1, 1)] in SecondOrderCone())
@objective(model, Min, t)
optimize!(model)
solution_summary(model)

```

---

<div class="post-metadata">

**Author:** ![Khr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/khr/32/206305_2.png) [@Khr](https://discourse.julialang.org/u/Khr)\
**Post date:** [January 19, 2024, 10:11am UTC](https://discourse.julialang.org/t/how-do-i-model-a-combination-of-polynomial-and-soc-constraints/108968/3 "2024-01-19T10:11:02Z")

</div>

Thank you very much, that seems to have done the trick.
