I noticed the following behavior in CVX: it report as solved my little optimization problem almost immediately (<1 sec), but take up to 20 seconds to return the answer.
After poking around with the profiler I determined it was spending all its time in cvx_pop
. I’m not entirely sure what this function does but it was running a recursive call to cvx_id
on every variable in the workspace, presumably to determine if these were CVX variables or not. The problem is that I have some very large datasets in the workspace that have a deep tree-like structure.
As a temporary fix, I added the following lines, starting at 113 of cvx_pop.m
:
s1 = evalin( 'caller', 'who' );
% ---- MY INSERTION BELOW ----
global CVX_EXCLUDE;
if ~isempty(CVX_EXCLUDE)
for ii = 1:numel(CVX_EXCLUDE)
sidx = strmatch(CVX_EXCLUDE{ii}, s1);
s1(sidx) = [];
end
end
What this does is exclude any variables from the recursive call that I put in the global CVX_EXCLUDE. I put my dataset variables in there and this fixed the problem for me; it now runs <1sec to solve the problem and return the solution.
I’m posting this here to ask if this behavior is a bug or (what I assume) default behavior, and if my fix will cause any possible problems for me in the future (assuming I never exclude any variable that overlaps with any variable used in between cvx_begin
and cvx_end
.) Also in case anyone else is having similar trouble.