# AssertionError when deleting and updating constraint in JuMP using Mosek solver

**URL:** https://discourse.julialang.org/t/assertionerror-when-deleting-and-updating-constraint-in-jump-using-mosek-solver/96238
**Category:** Optimization (Mathematical)
**Tags:** jump, mosek
**Created:** [March 17, 2023, 10:56am UTC](https://discourse.julialang.org/t/assertionerror-when-deleting-and-updating-constraint-in-jump-using-mosek-solver/96238 "2023-03-17T10:56:42Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bobo](https://avatars.discourse-cdn.com/v4/letter/b/f9ae1b/32.png) [@bobo](https://discourse.julialang.org/u/bobo)
#### Post date: [March 17, 2023, 10:56am UTC](https://discourse.julialang.org/t/assertionerror-when-deleting-and-updating-constraint-in-jump-using-mosek-solver/96238/1 "2023-03-17T10:56:42Z")

</div>

Dear team,

I would like to sequentially solve a problem by updating a constraint, the way I do it is to delete and restate the constraint inside a loop. Once the problem is solved and I try to delete the constraint I get the following error “AssertionError: (m.x\_sd[ref2id(vi)]).matrix == -1”. I got the error only if I use Mosek as a solver (with SCS everything is ok).

Here is a simple example to replicate the error :

```julia
using JuMP
using MosekTools
function error_delete()
    m = Model(Mosek.Optimizer)
    @variable m x[1:4,1:4]
    A = rand(4,4)
    #@constraint m c1 A*x*A' in JuMP.PSDCone()
    c1 = @constraint(m, A*x*A' in JuMP.PSDCone())
    @objective m Min sum(x[i,i] for i=1:4)
    for i = 1: 10
        delete(m,c1)
        #unregister(m,:c1)
        B = rand(4,4)
        #@constraint m c1 B*x*B' in JuMP.PSDCone()
        c1 = @constraint(m,B*x*B' in JuMP.PSDCone())
        optimize!(m)
    end
end

error_delete()

```

Am I doing something the wrong way?

---

<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: [March 17, 2023, 10:54pm UTC](https://discourse.julialang.org/t/assertionerror-when-deleting-and-updating-constraint-in-jump-using-mosek-solver/96238/2 "2023-03-17T22:54:26Z")

</div>

Hi @bobo, welcome to the forum.

I don’t have a Mosek license so I can’t test this, but this looks like a bug in MosekTools.jl.

Mosek has a few quirks on how it handles PSD cones, so @blegat is the person to ask about what’s going on here.

---

<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: [March 20, 2023, 12:53pm UTC](https://discourse.julialang.org/t/assertionerror-when-deleting-and-updating-constraint-in-jump-using-mosek-solver/96238/3 "2023-03-20T12:53:45Z")

</div>

Thanks for reporting. This is because Mosek does not support deleting matrix variables. The error should be improved in [Better error message for deletion of matrix variable by blegat · Pull Request #121 · jump-dev/MosekTools.jl · GitHub](https://github.com/jump-dev/MosekTools.jl/pull/121)
