# Can't access moment\_matrix() function in SumOfSquares

**URL:** <https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624>\
**Category:** Optimization (Mathematical)\
**Tags:** jump, polynomials\
**Created:** [October 2, 2020, 1:12am UTC](https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624 "2020-10-02T01:12:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aliceee](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@aliceee](https://discourse.julialang.org/u/aliceee)\
**Post date:** [October 2, 2020, 1:12am UTC](https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624/1 "2020-10-02T01:12:23Z")

</div>

Hi, I’m trying to use the moment\_matrix function in SumOfSquares package.

```julia
using MultivariateMoments
ν3 = moment_matrix(constr)

```

However, I got the following error:

```julia
ArgumentError: ModelLike of type MosekModel does not support accessing the attribute SumOfSquares.MomentMatrixAttribute(1)

Stacktrace:

```

Does anyone know why it is the case? Everything was fine when I tried the example provided in the documentation.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [October 2, 2020, 9:35pm UTC](https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624/2 "2020-10-02T21:35:51Z")

</div>

Could you provide a more complete example that reproduces the error? My guess is that `constr` is not a Sum-of-Squares constraint.

---

<div class="post-metadata">

**Author:** ![aliceee](https://avatars.discourse-cdn.com/v4/letter/a/8baadc/32.png) [@aliceee](https://discourse.julialang.org/u/aliceee)\
**Post date:** [October 2, 2020, 9:53pm UTC](https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624/3 "2020-10-02T21:53:38Z")

</div>

Thanks for your quick reply! The polynomial opt problem that I was trying to optimize is

```julia
model = SOSModel(Mosek.Optimizer)
@polyvar B[1:2,1:3] 
@variable(model, t1)
@variable(model, t2)
@variable(model, var)
@polyvar c0
@polyvar x[1:3]
@polyvar p[1:2]
kernel = (transpose(p)*vec(B*x) + c0).^2
expr = subs(kernel, c0=> 1.0 , p =>[0.2, 0.6], x=>[0.4, 0.2, 1.0]);
@constraints(model, begin
    t1 >= 0
    t2 >= 0
end)
S = @set vec(B*[1,1,1])[1]>=0 && vec(B*[1,1,1])[2]>=0 && vec(B*[1,1,1])[1] + vec(B*[1,1,1])[2]==1
@constraint(model, t1 >= 48.0 - expr, domain=S)
@constraint(model, t2 >= expr - 48.0, domain=S)
@constraint(model, constr, var >= t1+2*t2)
@objective(model, Min, var)
optimize!(model)

```

And I’m trying to extract the value of optimal B in this problem.

---

<div class="post-metadata">

**Author:** ![blegat](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/blegat/32/217090_2.png) [@blegat](https://discourse.julialang.org/u/blegat)\
**Post date:** [October 3, 2020, 8:25am UTC](https://discourse.julialang.org/t/cant-access-moment-matrix-function-in-sumofsquares/47624/4 "2020-10-03T08:25:45Z")

</div>

The Sum-of-Squares constraints here are

```julia
c1 = @constraint(model, t1 >= 48.0 - expr, domain=S)
c2 = @constraint(model, t2 >= expr - 48.0, domain=S)

```

You should do `moment_matrix(c1)` and/or `moment_matrix(c2)` and try extracting atoms from these.
