I compared JuMP and YALMIP’s performance in parsing convex problem. I noticed a difference in the problem size of the final optimization problem that is passed to Mosek. The problem from JuMP was quite large, than YALMIP.
-
YALMIP generated problem has 5 constraints, 0 scalar variables, 2 matrix variables
-
JuMP generated problem has 18 constraints, 5 scalar variables, 2 matrix variables
Both give the exact same answer. Any comments on why this is the case? Am I formulating the problem incorrectly in JuMP? Any help in this regard will be greatly appreciated. Details of the test problem are below.
Thanks.
Problem Statement
Design of LQR for a system \dot{x} = Ax + Bu, with u=Kx. This is solved using a SDP problem. I am not getting into the details of LQR theory here. The codes for YALMIP and JuMP are as following.
YALMIP (MATLAB)
clc; clear;
A = [0 1; -1 -1];
B = [0;1];
Q = [1 0; 0 0.1];
R = 1;
Y = sdpvar(2,2);
W = sdpvar(1,2)
Z = zeros(2,1);
M11 = (AY + BW) + (AY + BW)‘;
M = [M11 Y W’;
Y -inv(Q) Z;
W Z’ -inv( R );]
constr = [M <= 0, Y>=0];
optimize(constr,-trace(Y));
disp(trace(value(Y)));
JuMP Code
using JuMP, MosekTools, LinearAlgebra
A = [0. 1; -1 -1];
B = [0.;1];
model = Model(with_optimizer(Mosek.Optimizer));
@variable(model, Y[1:2, 1:2], Symmetric);
@variable(model, W[1:2]);
Q = [1 0; 0 0.1];
R = 1;
Z = zeros(2,1);
M11 = (AY + BW’) + (AY + BW’)‘;
M = [M11 Y W;
Y -inv(Q) Z;
W’ Z’ -inv(R);]
@SDconstraint(model,Symmetric(M) <= zeros(size(M)));
@SDconstraint(model,Symmetric(Y) >= zeros(size(Y)));
@objective(model,Max,tr(Y));
println(“Calling optimize!(…)”);
JuMP.optimize!(model);
println(tr(value.(Y)));
MOSEK Output from YALMIP
MOSEK Version 9.0.89 (Build date: 2019-5-24 09:53:18)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: MACOSX/64-X86
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.01
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 : 8
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.02
1 3.6e-01 1.9e+00 4.2e+00 -7.61e-01 7.493854220e+00 1.637944828e+00 2.1e-01 0.06
2 9.2e-02 4.9e-01 6.4e-01 4.11e-01 5.431599917e+00 3.638549110e+00 5.4e-02 0.06
3 2.0e-02 1.1e-01 9.4e-02 2.68e-01 6.802314950e+00 6.369265942e+00 1.2e-02 0.06
4 2.4e-04 1.3e-03 1.2e-04 9.08e-01 6.662079753e+00 6.655739510e+00 1.4e-04 0.06
5 8.9e-06 4.7e-05 8.0e-07 1.00e+00 6.660644505e+00 6.660411659e+00 5.2e-06 0.07
6 8.9e-07 4.7e-06 2.6e-08 1.00e+00 6.660618400e+00 6.660594963e+00 5.2e-07 0.07
7 8.7e-08 4.6e-07 7.8e-10 1.00e+00 6.660615958e+00 6.660613675e+00 5.1e-08 0.07
8 8.7e-09 4.6e-08 2.5e-11 1.00e+00 6.660615311e+00 6.660615082e+00 5.1e-09 0.07
9 3.6e-10 4.4e-09 2.1e-13 1.00e+00 6.660615168e+00 6.660615158e+00 2.1e-10 0.07
Optimizer terminated. Time: 0.10
Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 6.6606151676e+00 nrm: 4e+00 Viol. con: 4e-09 barvar: 0e+00
Dual. obj: 6.6606151582e+00 nrm: 1e+01 Viol. con: 0e+00 barvar: 2e-08
Optimizer summary
Optimizer - time: 0.10
Interior-point - iterations : 9 time: 0.07
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00
6.660615158242211
MOSEK Output from JuMP
Problem
Name :
Objective sense : max
Type : CONIC (conic optimization problem)
Constraints : 18
Cones : 0
Scalar variables : 5
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 started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 2 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Problem
Name :
Objective sense : max
Type : CONIC (conic optimization problem)
Constraints : 18
Cones : 0
Scalar variables : 5
Matrix variables : 2
Integer variables : 0
Optimizer - threads : 8
Optimizer - solved problem : the primal
Optimizer - Constraints : 18
Optimizer - Cones : 2
Optimizer - Scalar variables : 9 conic : 9
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 : 153 after factor : 153
Factor - dense dim. : 0 flops : 2.76e+03
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 9.0e+00 1.0e+00 1.0e+00 0.00e+00 0.000000000e+00 0.000000000e+00 1.0e+00 0.00
1 1.9e+00 2.1e-01 3.3e-01 -7.58e-01 1.494060954e+00 -2.347484915e-01 2.1e-01 0.00
2 4.8e-01 5.4e-02 4.8e-02 3.97e-01 3.216540796e+00 2.621094335e+00 5.4e-02 0.00
3 1.3e-01 1.5e-02 1.1e-02 1.56e-01 6.236366207e+00 5.794301541e+00 1.5e-02 0.00
4 2.8e-03 3.1e-04 3.0e-05 8.65e-01 6.647109017e+00 6.639514147e+00 3.1e-04 0.00
5 6.2e-05 6.9e-06 9.9e-08 1.00e+00 6.660351189e+00 6.660190874e+00 6.9e-06 0.00
6 5.8e-06 6.5e-07 2.8e-09 1.00e+00 6.660595719e+00 6.660580869e+00 6.5e-07 0.00
7 4.9e-07 5.4e-08 6.8e-11 1.00e+00 6.660614264e+00 6.660613014e+00 5.4e-08 0.00
8 4.8e-08 5.3e-09 2.1e-12 1.00e+00 6.660615113e+00 6.660614990e+00 5.3e-09 0.00
9 6.2e-10 6.1e-10 3.1e-15 1.00e+00 6.660615160e+00 6.660615159e+00 6.9e-11 0.00
Optimizer terminated. Time: 0.01
6.660615160346445