If the solver runtime is only .109930 seconds, why is the elapsed time over 9 seconds?

I have a CVX problem which runs successfully, albeit with numerical problems using the ECOS solver. This issue however seems to be independent of the solver I am using. In the command window, CVX outputs next to the “Runtime” line that the problem took .110662 seconds to solve. However, this clearly was not the case and in fact using tic toc the elapsed time is more than 9 seconds. Is this just expected since CVX is doing something in the background to startup? Or can I improve this? I have tried running using quiet but that doesn’t really seem to speed up the process. The reason I want to decrease the computation time is because I have multiple CVX problems I want to run, and it may take a while since there is this dead time.

1 Like

cvx has to construct the problem that is send into the optimizer. My guess is that cvx spend a lot of time doing that. This has been seen before.

Could be the way you have formulated the model is the cause of that.

Is it possible to formulate the problem once, then run successive CVX sessions where only some constants are changed so that the total time is reduced?

No that is not possible to my knowledge. If you want to use Matlab then maybe calling Mosek directly might be a solution.

cvxpy or MOSEK Fusion might be some solutions outside the Matlab.

How would I call MOSEK directly via matlab? Would it still be a CVX problem?

If you have many problems which are structurally the same, and differ only in input data, you can do what you want by using the optimizer capability of YALMIP (under MATLAB). YALMIP does most of the crunching once to set up the optimizer object. Then each problem instance can be quickly generated and sent to the solver with only a very small overhead. CVX does not have such a capability.

Most CVX models (objective and constraints) can be written very similarly in YALMIP…


I should have mentioned yalmip too. My mistake.

1 Like

Thank you for the reply. My only concern with YALMIP is that there isn’t literature I’ve found regarding my topic that uses it. I’m also aware it isn’t inherently better but if indeed it can generate the model once and store it ill give it a try.

On another note, the Runtime that is spits out in the command window does not seem to be saved as a variable. How can I extract this runtime myself?

I think you’d have to use the MATLAB diary command. and extract it from the diary file.