Python API custom PSD matrix variable

26 views
Skip to first unread message

Cristian E. Boghiu

unread,
May 11, 2021, 12:46:44 PM5/11/21
to mosek
Hello,

I'm a quantum information theory PhD student working from Barcelona. I would to consult with you about whether I can define custom SDP matrices with python fusion or the python API. 

The essence of the problem is as follows. I have a very big dense SDP variable where I know many of the elements of the matrix are exactly the same. For example, take the 4x4 symmetric matrix:

G = 
[[var1 var2 var3 var4],
 [var2 var5 var6 var7],
 [var3 var6 var8 var9],
 [var4 var7 var9 var10]]

In my problem I know that var2=var3=var6, var9=var10, var1=var5 and var4=var7. This becomes a problem with many variables and lots of constraints:

var1 = M.variable(...)
var2 = M.variable(...)
var3 = M.variable(...)
var5 = M.variable(...)
var6 = M.variable(...)
var7 = M.variable(...)
var8 = M.variable(...)
var9 = M.variable(...)
var10 = M.variable(...)
G = 
[[var1 var2 var3 var4],
 [var2 var5 var6 var7],
 [var3 var6 var8 var9],
 [var4 var7 var9 var10]]
s.t.
var1=var5
var2=var3=var6
var9=var10
var4=var7

I checked and Python fusion does not smartly eliminate unnecessary variables. That's ok, but I would like to know if there is the option of doing it myself by just using less variables from the start. If I could define my own variable G, I could have 

var1 = M.variable(...)
var2 = M.variable(...)
var3 = M.variable(...)
var4 = M.variable(...)
G = 
[[var1 var2 var2 var3],
 [var2 var1 var2 var3],
 [var2 var2 var4 var5],
 [var3 var3 var5 var5]]

+ other constraints I didn't mention:

equality constraints: var_x = constant
proportionality constraints var_i = constant * var_j
PSD constraints: G is PSD (I prefer to implement this as G - lambda*Id >> 0 with lambda an unbounded variable)

This is possible with YALMIP for MATLAB and this gives solving times using MOSEK of the order of 10x faster. I would like to implement this in Python as most of my code is in Python, and currently I only use MATLAB to solve the SDP.

What would be the way to use the Python API or FUSION to achieve this?

I could provide the code for my problem, but I don't think that would be helpful necessarily.

I tried to look into the documentation and I couldn't find anything, sorry if it's already there but I missed it.

Thank you for your time and for reading this,

Cristian

Michal Adamaszek

unread,
May 11, 2021, 1:26:19 PM5/11/21
to mosek
You could make some tricks like

x= M.variable(5)
G= x.pick([0,1,1,2,1,0,1,2,1,1,3,4,2,2,4,4]).reshape([4,4])

(sorry if I messed up the indices but you see the point)

or equivalently define G as something like Expr.add([ Expr.mul(x.index(i), Ai) for i in range(...) ]) where Ai are appropriate constant matrices .

However if I were to guess the speedup more likely comes from the fact that Yalmip dualized your LMI, and not from saving on a few variables. When you write G-lambda*I>>0 you will get a PSD variable X and order of dim(G)^2 equality constraints G-lambda*I=X. So maybe you should consider dualizing your model. https://docs.mosek.com/modeling-cookbook/duality.html#semidefinite-duality-and-lmis

Cristian E. Boghiu

unread,
May 13, 2021, 7:15:36 AM5/13/21
to mosek
Hi,

As you say Yalmip dualizes the LMI. Once I deactivated dualization it gave the same speeds as the Python implementation.

Thank you for your help!

Cristian
Reply all
Reply to author
Forward
0 new messages