CVXs seems to block a Mosek license

I’m trying to compute a E-optimal design using the code snippet

% E-optimal design
%
%      minimize    w
%      subject to  sum_i lambda_i*vi*vi' >= w*I
%                  lambda >= 0,  1'*lambda = 1;
%

cvx_begin sdp
  variables t lambda(p)
  maximize ( t )
  subject to
    V*diag(lambda)*V' >= t*eye(n,n);
    sum(lambda) == 1;
    lambda >= 0;
cvx_end

as it can be found among the provided examples

Matlab’s output reads

Calling SDPT3 4.0: 12886 variables, 166 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 166
 dim. of sdp    var  = 159,   num. of sdp  blk  =  1
 dim. of linear var  = 165
 dim. of free   var  =  1 *** convert ublk to lblk
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|6.2e+03|3.2e+02|2.8e+05| 3.642686e-11  0.000000e+00| 0:0:00| chol  1  1 
 1|0.864|0.350|8.4e+02|2.1e+02|8.1e+04| 1.707783e+01 -2.300620e+01| 0:0:01| chol  1  1 
 2|0.890|0.548|9.2e+01|9.4e+01|3.2e+04| 4.868087e+01 -5.822043e+01| 0:0:01| chol  1  1 
 3|0.729|0.623|2.5e+01|3.5e+01|1.3e+04| 4.639634e+01 -9.081951e+01| 0:0:01| chol  1  1 
 4|1.000|0.985|6.3e-07|5.4e-01|3.0e+02| 4.667192e+01 -8.599810e+01| 0:0:01| chol  1  1 
 5|1.000|0.957|6.9e-05|2.3e-02|3.7e+01| 2.859648e+01 -4.136292e+00| 0:0:02| chol  1  1

which suggests the use of the SDPT3 solver.

On the other hand, I have Mosek installed and also on the Matlab path (but not explicitly used in theproblem at hand).

For reasons unclear to me, solving the above cvx problem checks out a Mosek license and keeps it for the duration of the Matlab session. Even if I manually call

mosekopt('nokeepenv')

the license is still blocked.

Do I need to tell cvx to free the Mosek license (which seems to be blocked for no reason)?

What happens if you insert
cvx_solver mosek
in your program?

You can read

https://docs.mosek.com/latest/toolbox/guidelines-toolbox.html#the-license-system

Mosek always by default checks out the license from the first invocation until it is unloaded, that is typically until the end of your Matlab session.

It is possible that the Mosek license is being checked out when CVX makes some initial small test to see which solvers work, maybe even in cvx_setup. CVX does not have any facilities to manage Mosek license checkouts.

You can solve a tiny problem with cvx_solver mosek and the parameter cache_license (see link above) set to off and then any licenses will be returned after optimization. (But not so tiny as to be solved by CVX symbolically without the solver).

If you write to Mosek support with all the versions etc. then we can investigate it. I think that using CVX with a Mosek floating license is generally uncharted territory.

1 Like

By the way I now made a small test.

The license is checked out during cvx_setup. It can be correctly returned with mosekopt('nokeepenv'). If that doesn’t work for you then most likely you have a few different Moseks in your Matlab path and your invocation of mosekopt loads a different library - use the new CVX that comes without embedded Mosek and use only your own single Mosek installation and it should be fine.

There is no Mosek license checkout when SDPT3 is called.

If at some point you actually use Mosek for the first time to solve a problem then, due to some CVX path manipulation I don’t understand, you can no longer call mosekopt unless you explicitly add the Mosek toolbox back your Matlab path. So either that or using cache_license off.

1 Like

If I insert the
cvx_solver mosek
statement, then the Mosek solver is used (instead of SDPT3) and two licenses are blocked (we have 2 floating licenses).
By issuing the command
mosekopt('nokeepenv')
one of the 2 licenses is freed again.

Issue the nokeepenv just after cvx_setup to release the license consumed by cvx_setup. That cleared the license for me.

As far as I know, I have only one version of Mosek installed (i.e., V10.0.0).

On the other hand, when I execute cvx_setup I get, among other stuff, the output

3 solvers issued warnings:
    Mosek     9.1.9      {cvx}\mosek\w64
        Using MOSEK with CVX requires an academic MOSEK license
        or a MOSEK-enabled CVX Professional license. Commercial
        users with MOSEK licenses should contact sales@cvxr.com.
    Mosek_2   9.1.9      C:\Program Files\Mosek\10.0\toolbox\r2017aom
        Using MOSEK with CVX requires an academic MOSEK license
        or a MOSEK-enabled CVX Professional license. Commercial
        users with MOSEK licenses should contact sales@cvxr.com.
    Mosek_3   9.1.9      C:\Program Files\Mosek\10.0\toolbox\r2017aom
        Using MOSEK with CVX requires an academic MOSEK license
        or a MOSEK-enabled CVX Professional license. Commercial
        users with MOSEK licenses should contact sales@cvxr.com.

It seems that CVX acts as if every Mosek license (of which we have 2 floating ones) corresponds to an independent solver (Mosek_2 and Mosek_3). What I don’t understand, however, is the first entry (located at {cvx}\mosek\w64).
If, in fact, I remove my only Mosek installation (at C:\Program Files\Mosek\10.0\) from the path and reperform a cvx_setup, I get

1 solver issued warnings:
    Mosek    9.1.9      {cvx}\mosek\w64
        Using MOSEK with CVX requires an academic MOSEK license
        or a MOSEK-enabled CVX Professional license. Commercial
        users with MOSEK licenses should contact sales@cvxr.com.

which blocks a license. I can free it by issuing a mosekopt('nokeepenv') command.

Calling CVX now, will no longer block a license.

They are independent solvers. {cvx}\mosek\w64 is the old Mosek 9 that comes packaged with CVX inside the CVX installation (just remove it, you don’t want it) and the other is your own Mosek 10 (keep it, use it). Why your own Mosek 10 is detected twice was always a mystery; the most recent CVX (look for the open sourced version from 2024) fixes it; I would just use that.

The number of Mosek’s detected by CVX has nothing to do with the number of your floating licenses.

Removing the {cvx}\mosek folder does the job. Now it seems that everything runs as expected, thanks!