Conic solvers usually don’t support both conic variables and conic constraints.
They either have the primal form as interface (variables in cones and equality constraints):
min c' x
A x = b
x in K
or the dual form as interface (free variables and and affine constraints in cones):
min c' x
A x + b in K
x free
Mosek for instance uses the primal form.
When you model, your model is sometimes closer to the primal or sometimes to the dual form.
If your model is closer to the primal form, you should give it as is to Mosek.
Otherwise, you should give the dual form to Mosek.
As you have seen, modeling the primal form is error prone as writing @constraint(model, X >= zeros(X))
creates an affine constraints hence need to create slack variables in primal form!
So the user should be more disciplined and create make sure the constraint on the variables are not interpreted as affine constraints.
The modeling language should also allow creating constraints on variables (which is not the case in YALMIP and that can prevent you to create the best model sometimes, see @mforets presentation at JuMP-dev)
For these reasons, YALMIP always use the dual form for modeling and dualize the problem when the solver needs the primal form.
In JuMP, we just give the problem to the solver as it is modeled by the user and if you want to dual to be given instead you have to say it explicitly using Dualization.jl.
In your case, you can do
using JuMP, MosekTools, LinearAlgebra
A = [0. 1; -1 -1];
B = [0.;1];
model = Model(with_optimizer(() -> Dualization.DualOptimizer(Mosek.Optimizer())))
@variable(model, Y[1:2, 1:2], PSD)
@variable(model, W[1:2])
Q = [1 0; 0 0.1]
R = 1
Z = zeros(2,1)
M11 = (A*Y + B*W') + (A*Y + B*W')'
M = [M11 Y W;
Y -inv(Q) Z;
W' Z' -inv(R);]
@constraint(model, Symmetric(-M) in PSDCone())
@objective(model, Max, tr(Y))
JuMP.optimize!(model)
println(tr(value.(Y)))
Note that here, doing @constraint(model, Y >= zeros(size(Y)))
and @constraint(model, M <= 0)
instead would lead the same result as you are modeling in dual form since Mosek is in primal form and you use Dualization.jl.
This gives
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 5
Cones : 0
Scalar variables : 0
Matrix variables : 2
Integer variables : 0
Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 5
Cones : 0
Scalar variables : 0
Matrix variables : 2
Integer variables : 0
Optimizer - threads : 4
Optimizer - solved problem : the primal
Optimizer - Constraints : 5
Optimizer - Cones : 1
Optimizer - Scalar variables : 3 conic : 3
Optimizer - Semi-definite variables: 1 scalarized : 15
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 15 after factor : 15
Factor - dense dim. : 0 flops : 6.14e+02
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 1.7e+00 9.0e+00 1.3e+01 0.00e+00 1.200000000e+01 0.000000000e+00 1.0e+00 0.00
1 3.6e-01 1.9e+00 4.2e+00 -7.61e-01 7.493854220e+00 1.637944828e+00 2.1e-01 0.00
2 9.2e-02 4.9e-01 6.4e-01 4.11e-01 5.431599917e+00 3.638549110e+00 5.4e-02 0.00
3 2.0e-02 1.1e-01 9.4e-02 2.68e-01 6.802314950e+00 6.369265942e+00 1.2e-02 0.00
4 2.4e-04 1.3e-03 1.2e-04 9.08e-01 6.662079753e+00 6.655739510e+00 1.4e-04 0.00
5 8.9e-06 4.7e-05 8.0e-07 1.00e+00 6.660644505e+00 6.660411659e+00 5.2e-06 0.00
6 8.9e-07 4.7e-06 2.6e-08 1.00e+00 6.660618400e+00 6.660594963e+00 5.2e-07 0.00
7 8.7e-08 4.6e-07 7.8e-10 1.00e+00 6.660615958e+00 6.660613675e+00 5.1e-08 0.00
8 8.7e-09 4.6e-08 2.5e-11 1.00e+00 6.660615311e+00 6.660615082e+00 5.1e-09 0.00
9 3.6e-10 2.5e-09 2.1e-13 1.00e+00 6.660615168e+00 6.660615158e+00 2.1e-10 0.00
Optimizer terminated. Time: 0.00
6.660615158242325
as with YALMIP