Error in cvx_optval for cvx_status solved problem

I have run a code with sdpt3 and sedumi and solved it 30 times with a change in the input. In one of the instances an optimum is obtained, cvx_status reports solved, but cvx_optval is NAN. The optimum makes sense for this problem. The same happens in both solvers. In mosek the code fails completely with a
Msg. : Out of space in stack buffer 680 373
Please report this message to support@mosek.com.

This does not look like a difficult problem and is NOT large. The objective is
min norm(A*x)

Perhaps there is a CVX bug. Are you using CVX 2.2?

Can you show us the CVX code, preferabty with all input data?

Perhaps you could show us all the solver and CVX output for the “anomalous” case. Are the CVX variables populated with finite double precision values? If so, please show us that as well.

I suggest you create and send a task file to Mosek support per the instructions in section 1.1 of https://docs.mosek.com/9.3/faq.pdf .

You have triggered a bug I must be responsible for.

I would upgrade to the latest Mosek and if that does not solve it I would contact Mosek support.

If you look at the result of running this code and look at risks, then risks(3) is NaN

%%????problem with third point on curve??? why???
%% We are given the data matrix R of (20) samples of returns for 5 stocks.
%% The homework asked to minimize the risk with a return of at least .5.
%% This file does this for returns given in       rps = .45:.01:.58;
%% The output (efficient curve) is plotted.
%% we save the optimal portfolios as columns of the matrix xs.
clear
seed = 1;
rngsave = rng(seed);
R=[  0.3486    0.4133    0.0251    0.2370    0.6404
    0.0024    0.7346    0.9619    0.4633    0.0074
    0.4755    0.8461    0.2523    0.8453    0.3135
    0.1808    0.1173    0.5731    0.9971    0.3559
    0.9480    0.7666    0.6546    0.7951    0.5124
    0.9597    0.1039    0.5144    0.7837    0.8571
    0.5050    0.4942    0.5087    0.8373    0.8269
    0.4723    0.2503    0.1319    0.4870    0.6043
    0.1234    0.0150    0.1747    0.4092    0.2195
    0.9012    0.8101    0.2859    0.5669    0.2886
    0.6310    0.0293    0.3013    0.5978    0.4783
    0.3699    0.0608    0.7016    0.7624    0.8179
    0.5514    0.0626    0.7349    0.5296    0.7356
    0.4743    0.0660    0.1014    0.3222    0.1447
    0.8676    0.2211    0.1591    0.9794    0.9312
    0.9271    0.1842    0.5918    0.1102    0.4538
    0.6420    0.4931    0.3504    0.4496    0.8862
    0.5628    0.3657    0.1346    0.9531    0.0110
    0.6715    0.3420    0.0465    0.1261    0.2356
    0.4833    0.9535    0.4653    0.1806    0.9052];
rbar=mean(R);
Rbar=ones(length(R),1)*rbar;
A1=R-Rbar;
n=size(R,2);
t=2;
s=2;
rps = .45:.01:.7;
ind=find(rps==.5);
risks=zeros(length(rps),1);
riskse=zeros(length(rps),1);
returns=risks;
returnse=risks;
cnt=0;
warning off
xs=[];
xse=[];
for rp = rps
      cnt=cnt+1;
      clear x
      cvx_begin quiet
      cvx_solver sdpt3
      %cvx_solver mosek
      cvx_precision best
      variable x(n)          %    portfolio
      minimize(norm(A1*x))
      subject to
                sum(x) == 1;
      	  %sum(x(1:t)) <= .25
      	  %sum(x(t+1:t+s)) <= .2
      	  rbar*x >= rp;
      	  %x>=0
      cvx_end
      risks(cnt)=cvx_optval;
      %risks(cnt)=norm(A1*x)^2;
      %cvx_status
      %[risks(cnt) norm(A1*x) rbar*x]
      returns(cnt)=rbar*x;
      %%%now for equality constraint
      clear xe
      cvx_begin  quiet
      cvx_solver sdpt3
      %cvx_solver sedumi
      %cvx_solver mosek
      %cvx_precision best
      variable xe(n)          %    portfolio
      minimize(norm(A1*xe))
      subject to
                sum(xe) == 1;
      	  %sum(x(1:t)) <= .25
      	  %sum(x(t+1:t+s)) <= .2
      	  rbar*xe >= rp;
      	  %x>=0
      cvx_end
      riskse(cnt)=cvx_optval;
      %riskse(cnt)=norm(A1*xe)^2;
      returnse(cnt)=rbar*xe;
      figure(1)
      clf
      plot(risks(1:cnt),rps(1:cnt),'-xb')
      hold on
      plot(risks(1:cnt),returns(1:cnt),'-or')
      plot(riskse(1:cnt),rps(1:cnt),'-dy')
      plot(riskse(1:cnt),returnse(1:cnt),'-vk')
      legend('riskVSrps','riskVSreturns','riskseVSrpse','riskseVSreturnse', ...
      	         'location','best')
      title('risk versus return')
      xlabel('risk')
      ylabel('return')
      %[rps(1:cnt)'  returns(1:cnt) risks(1:cnt)]
      drawnow
      hold off
      xs=[xs x];
      xse=[xse xe];
      end
warning on
fprintf('the optimal portfolio for .5, the %i-th column of xs, is \n')
xs(:,ind)

Version 2.2, Build 1148 (62bfcca) Tue Jan 28 00:51:35 2020

I copied and pasted the code into the previous reply. But it seems that ® does not copy well and ends up as a copyright symbol?

I did not notice any anomalous behavior for SDPT3 or SeDuMi solvers. All problems solved, all reported “correct” values of cvx_optval, and results matched between the two solvers. I saw no case in which cvx_status is Solved, but cvx_optval is NaN.

I encountered the fatal Mosek error for each of the two CVX problems for each of a few different rps values I tried… Mosek personnel advise against using cvx_precision best; when removed, the same error occurred. Here is the output without the quiet option. CVX’s reporting is correct given the fatal Mosek error.

++++++++++++++++++++++++++++++

Calling Mosek 9.3.1: 23 variables, 6 equality constraints
For improved efficiency, Mosek is solving the dual problem.

MOSEK Version 9.3.6 (Build date: 2021-9-7 12:37:09)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 6
Cones : 1
Scalar variables : 23
Matrix variables : 0
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
MOSEK fatal error stopenv.
Version : 9.3.6
Platform: Windows/64-X86
File : src\prslv\prselim.c
Line : 5122
Msg. : Out of space in stack buffer 680 373
Please report this message to support@mosek.com.


Status: Error
Optimal value (cvx_optval): NaN

Error using mosekopt
Fatal MOSEK error in src\prslv\prselim.c line 5122.

Error in cvx_mosek
Error in cvx_run_solver (line 50)
[ varargout{1:nargout} ] = sfunc( inputs{:} );
Error in cvx_mosek
Error in cvxprob/solve (line 429)
[ x, status, tprec, iters, y ] = shim.solve( At, b, c, cones, quiet, prec, solv.settings, eargs{:} );
Error in cvx_end (line 88)
solve( prob );

I also ran this in the last 8.x version of Mosek, and got the same error message, other than line and buffer number being different.

Calling Mosek 8.1.0.80: 23 variables, 6 equality constraints
For improved efficiency, Mosek is solving the dual problem.

MOSEK Version 8.1.0.80 (Build date: 2019-3-12 19:45:08)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 6
Cones : 1
Scalar variables : 23
Matrix variables : 0
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
MOSEK fatal error stopenv.
Version : 8.1.0.80
Platform: Windows/64-X86
File : src\prslv\prselim.c
Line : 4503
Msg. : Out of space in stack buffer 680 525
Please report this message to support@mosek.com.


Status: Error
Optimal value (cvx_optval): NaN

Error using mosekopt
Fatal MOSEK error in src\prslv\prselim.c line 4503.

Error in cvx_mosek
Error in cvx_run_solver (line 50)
[ varargout{1:nargout} ] = sfunc( inputs{:} );
Error in cvx_mosek
Error in cvxprob/solve (line 429)
[ x, status, tprec, iters, y ] = shim.solve( At, b, c, cones, quiet, prec, solv.settings, eargs{:} );
Error in cvx_end (line 88)
solve( prob );

Reproduced. This is an error in Mosek. @hwolkowi We will let you know through Mosek support when there is a fix.

(Unrelated, since that would only have an effect later, but as mentioned by @Mark_L_Stone, do not use cvx_precision best with Mosek)

OK - thanks. It seems that there is a problem with cvx_precision best with sdpt3 and sedumi as well. As they both gave a bad cvx_optval though claiming that cvx_status solved and the objective value was fine but cvx_optval was NaN

As i wrote earlier, I was not able to reproduce cvx_optval NaN on any of the instances with any solver/. So your experience still falls in the unexplained mystery category.