Possible issue: solveroutput inaccessible when MOSEK fails in custom optimizer

17 views
Skip to first unread message

Juraj Danicic

unread,
Nov 6, 2025, 9:30:31 AM (8 days ago) Nov 6
to YALMIP
Hi!

I’m seeing what looks like a bug (or at least surprising behavior) in YALMIP when a custom-built optimizer uses MOSEK and the solver fails to find a solution.

Symptom
When the optimizer returns with no solution, attempting to read the MOSEK result structure throws:

"Error using indexing
Field not accesible. You can only acsess P.options"

Example stack trace
Error in Main_20251105>extractMosekDiagnostics (line 2660)
res = diagn.solveroutput.res;

Error in Main_20251105 (line 1109)
extractMosekDiagnostics(diagn, maxSolverTime, kcl, log);

This happens regardless of how I label/name the optimizer; the message still refers to “P”. It looks like when the solver fails, the diagnostic/return object exposes only options (P.options), and fields such as diagn.solveroutput (e.g., .res) are not accessible.

Initialization (excerpt)
ops = sdpsettings( ...
'verbose', 2, ...
'debug', 1, ...
'cachesolvers', 1, ...
'savesolverinput', 1, ...
'savesolveroutput', 1 ...
);
ops.solver = solverName; % e.g., 'mosek'

What I expected
With 'savesolveroutput' = 1, I expected diagn.solveroutput to be present even on infeasible/failed runs so I can inspect MOSEK’s task/result (e.g., res, r) for logging and recovery.

Questions

Is this a bug in how solveroutput is attached when the problem status is not “solved”?

If it’s intended, what’s the supported way to access MOSEK’s result/task (e.g., res) from an optimizer call that ends in infeasibility/other failure?

Would it make sense for diagn.solveroutput to be consistently available whenever 'savesolveroutput'=1, regardless of termination status?

Minimal repro sketch (LP infeasible)
sdpvar x
F = [x <= 1, x >= 2];
obj = x;
ops = sdpsettings('solver','mosek', 'savesolverinput',1, 'savesolveroutput',1, 'verbose',2, 'debug',1);
% via optimizer:
opt = optimizer(F, obj, ops, [], x);
[~, diagn] = opt([]);
% or direct:
diagn = optimize(F, obj, ops);
% then:
res = diagn.solveroutput.res; % triggers the error when infeasible

Happy to provide any additional details or try a patch/branch if that helps.

Thanks a lot for your time and for YALMIP!

Best regards

Johan Löfberg

unread,
Nov 6, 2025, 9:37:55 AM (8 days ago) Nov 6
to YALMIP
Not sure what is going on there, but as a start,


[~, diagn] = opt([])

should return diagn being an integer (the error code). Full diagnostics from solver is 6th output

Johan Löfberg

unread,
Nov 6, 2025, 11:14:00 AM (8 days ago) Nov 6
to YALMIP
I cannot reproduce your issue


>> opt = optimizer(F, obj, ops, [], x);
[~, diagn] = opt([]);
diagn

diagn = optimize(F, obj, ops);
% then:
res = diagn.solveroutput.res

MOSEK Version 10.2.0 (Build date: 2024-5-22 07:05:59)
Copyright (c) MOSEK ApS, Denmark WWW: mosek.com
Platform: Windows/64-X86

Problem
  Name                   :                
  Objective sense        : minimize        
  Type                   : LO (linear optimization problem)
  Constraints            : 1              
  Affine conic cons.     : 0              
  Disjunctive cons.      : 0              
  Cones                  : 0              
  Scalar variables       : 2              
  Matrix variables       : 0              
  Integer variables      : 0              

Optimizer started.
Presolve started.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 0                 time                   : 0.00            
Lin. dep.  - primal attempts        : 0                 successes              : 0              
Lin. dep.  - dual attempts          : 0                 successes              : 0              
Lin. dep.  - primal deps.           : 0                 dual deps.             : 0              
Presolve terminated. Time: 0.02    
Optimizer terminated. Time: 0.06    


Interior-point solution summary
  Problem status  : DUAL_INFEASIBLE
  Solution status : DUAL_INFEASIBLE_CER
  Primal.  obj: -1.0000000000e+00   nrm: 1e+00    Viol.  con: 0e+00    var: 0e+00  

Basic solution summary
  Problem status  : DUAL_INFEASIBLE
  Solution status : DUAL_INFEASIBLE_CER
  Primal.  obj: -1.0000000000e+00   nrm: 1e+00    Viol.  con: 0e+00    var: 0e+00  
Optimizer summary
  Optimizer                 -                        time: 0.06    
    Interior-point          - iterations : 0         time: 0.03    
      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    


diagn =

     1


MOSEK Version 10.2.0 (Build date: 2024-5-22 07:05:59)
Copyright (c) MOSEK ApS, Denmark WWW: mosek.com
Platform: Windows/64-X86

Problem
  Name                   :                
  Objective sense        : minimize        
  Type                   : LO (linear optimization problem)
  Constraints            : 1              
  Affine conic cons.     : 0              
  Disjunctive cons.      : 0              
  Cones                  : 0              
  Scalar variables       : 2              
  Matrix variables       : 0              
  Integer variables      : 0              

Optimizer started.
Presolve started.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 1                 time                   : 0.00            
Lin. dep.  - tries                  : 0                 time                   : 0.00            
Lin. dep.  - primal attempts        : 0                 successes              : 0              
Lin. dep.  - dual attempts          : 0                 successes              : 0              
Lin. dep.  - primal deps.           : 0                 dual deps.             : 0              
Presolve terminated. Time: 0.00    
Optimizer terminated. Time: 0.03    


Interior-point solution summary
  Problem status  : DUAL_INFEASIBLE
  Solution status : DUAL_INFEASIBLE_CER
  Primal.  obj: -1.0000000000e+00   nrm: 1e+00    Viol.  con: 0e+00    var: 0e+00  

Basic solution summary
  Problem status  : DUAL_INFEASIBLE
  Solution status : DUAL_INFEASIBLE_CER
  Primal.  obj: -1.0000000000e+00   nrm: 1e+00    Viol.  con: 0e+00    var: 0e+00  
Optimizer summary
  Optimizer                 -                        time: 0.03    
    Interior-point          - iterations : 0         time: 0.02    
      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    


res =

  struct with fields:

         sol: [1×1 struct]
        info: [1×1 struct]
       rcode: 0
        rmsg: ''
    rcodestr: 'MSK_RES_OK'

Juraj Danicic

unread,
Nov 7, 2025, 4:08:35 AM (7 days ago) Nov 7
to YALMIP
This is an excerpt from a larger code:

% =====================================================================

    % SOLVE

    % =====================================================================      

    params_now                      = {z_prev, i_RC_1_prev, i_RC_2_prev, ...

                                        T_prev, P_ref_h(:), i_pack_LB(:), i_pack_HB(:), S_prev(:), SOH_prev};

   

    t_solve                         = tic;

    [sol, solverOK, c, ~, ~, diagn] = opt(params_now{:});

    wall_solve                      = toc(t_solve);

 

   


log.status_str(kcl) = string(diagn.infostr);

    log.solve_time(kcl) = diagn.solvertime;

    log.solve_wall(kcl) = wall_solve;

    log.problem_type(kcl) = string(diagn.problem);



Error using indexing

Field not accesible. You can only acsess P.options

 

Error in Main_20251105 (line 1283)

    log.status_str(kcl) = string(diagn.infostr);

 


It seems as if, as long as there is a solution, diagn functions normally. But if the solution is not found, I get this strange message (with a typo!), and a reference to "P", which is I guess a variable name that I never use.

Johan Löfberg

unread,
Nov 7, 2025, 4:17:22 AM (7 days ago) Nov 7
to YALMIP
Ah, now I see it. in optimizer/subsref line 140, there is this code

  % Check for garbage call
        for i = 1:length(subs.subs)
            if isnan(subs.subs{i})
                if length(self.dimoutOrig)>1
                    for j = 1:length(self.dimoutOrig)
                        sol{j} = nan(self.dimoutOrig{j});
                    end
                else
                    sol = nan(self.dimoutOrig{1});
                end
                varargout{1} = sol;
                varargout{2} = -10;
                varargout{3} = yalmiperror(-10);
                varargout{4} = [];
                varargout{5} = self;
                varargout{6} = self;
                return
            end
        end

varargout{6} should be set to something else there, preferably a diagnostic with error code -10 (nan in data) since the problem does not appear to be infeasibility but some garbage sent in the data

Juraj Danicic

unread,
Nov 7, 2025, 4:32:06 AM (7 days ago) Nov 7
to YALMIP
I see. How do you suggest me to proceed?

Johan Löfberg

unread,
Nov 7, 2025, 4:42:13 AM (7 days ago) Nov 7
to YALMIP
You are sending garbage somewhere in  params_now{:}, meaning you've created this weird data somewhere without noticing this, and should thus trace back where you do that

Juraj Danicic

unread,
Nov 7, 2025, 5:17:15 AM (7 days ago) Nov 7
to YALMIP
Alright. Thank you! Have a nice day!

Best regards
Reply all
Reply to author
Forward
0 new messages