Help on speed optimization

245 views
Skip to first unread message

Zhang David

unread,
May 12, 2023, 5:55:05 AM5/12/23
to mo...@googlegroups.com
Hi guys,

I’m trying to speed up mosek for some performance critical optimization process. Right now, I’m using mosek fusion Python API.
I wonder what speed gains I may get if I switch to:

1. Python optimizer API
2. C optimizer API

Just some rough ballpark idea would be helpful for me to evaluate if the gains is worth the time effort. 

My problem size is ~1600.

Really appreciate! 

Michal Adamaszek

unread,
May 12, 2023, 6:01:54 AM5/12/23
to mosek
Almost impossible to answer in such generality.

First you can write the same model in Fusion in much more or much less efficient ways.

Second, whether it is worthwhile depends on what time it takes to model the problem compared to solving it. 

Fusion has to do some processing, so there is real work it performs. The passage from Python Optimizer API to C Optimizer API is much thinner, this layer just passes data backend forth.

Whichever one you use the time to set up the problem should be a small fraction of the time it takes to solve it. If that is not the case then something is out of proportion.

Michal

Zhang David

unread,
May 12, 2023, 6:14:11 AM5/12/23
to mo...@googlegroups.com
Hi Michal,

Thank you for the quick response! 

To provide more details, the problem setup is very close to this portfolio optimization w/ impact example here: https://docs.mosek.com/10.0/pythonfusion/case-studies-portfolio.html#market-impact-costs

Problem size is 1500 ids. 

It sounds to me that there *might* be meaningful speed gains from Python Fusion API to Python Optimizer API, but likely not much from Python Optimizer API to C Optimizer API. Is that roughly a correct take ? 

If we assume the optimization w/ impact is the exact problem, dim = 1500, what do you say the rough speed diff btw Python Fusion API and Python Optimizer API ? 

Appreciate the help! 

--
You received this message because you are subscribed to the Google Groups "mosek" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mosek+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mosek/a4bf2402-7514-431a-b48c-cd3415ea3802n%40googlegroups.com.

Erling D. Andersen

unread,
May 12, 2023, 6:29:55 AM5/12/23
to mosek
Unfortunately,  the 1500 does not provide much info.

I think your take is wrong since good Fusion code is not much slower than Optimizer API code. 
I would not expect a significant speedup unless you are doing something weird with Fusion.

Michal Adamaszek

unread,
May 12, 2023, 6:46:57 AM5/12/23
to mosek
For one of those standard models much of the work is probably spent before Fusion ie. in some numpy computations and preparing data. That you will also have to do for the Optimizer API model. The Fusion model itself is not very complex and most critical work (like mul(G,x)) is already very optimized internally. So the speedup by rewriting this in the Optimizer API should not be very significant.

Michal

Zhang David

unread,
May 12, 2023, 7:09:26 AM5/12/23
to mo...@googlegroups.com
Thank you Erling for the clarification ! 

Can we define what "good Fusion code" is? Something very similar to the examples (i.e. no redundant constraints / avoid numerical issues etc.) ?


Zhang David

unread,
May 12, 2023, 7:52:27 AM5/12/23
to mo...@googlegroups.com
Thank you Michael - this is very helpful ! Really appreciate it ! 

Michal Adamaszek

unread,
May 12, 2023, 8:24:13 AM5/12/23
to mosek
"no redundant constraints / avoid numerical issues etc.", good scaling -- this applies to any formulation of an optimization problem, whether Fusion API or otherwise.

I guess good Fusion code means reasonably well vectorized in a way that makes it compact and readable. Hopefully as in our examples. 

(For instance one could imagine a Fusion model where every scalar variable is declared as a separate variable object and then they are painfully stacked together for each operation etc. That would be against the spirit and also very inefficient).

Michal

Zhang David

unread,
May 12, 2023, 9:51:27 AM5/12/23
to mo...@googlegroups.com
Perfect! Thank you again for the clear explanation! 

Reply all
Reply to author
Forward
0 new messages