Embedded Performance vs Non-Embedded #603
-
Hi. I’ve found that the embedded program is solving my problem on the order of 2x faster than using OSQP directly. I’m solving repeated portfolio optimization problems with n=250 instruments, but I added a gross position constraint and I punish transaction costs. I have two questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
The only major difference should be that the "embedded" version that you get by running codegen does some of the computation work of matrix factorisation up front. This is quite a lot of the overall solve cost in many cases. If you are solving the same sort of problem repeatedly, e.g. by just updating the linear cost and constraint terms ,then you should expect the solve time after the first solve to be about the same since at that point the required matrix factorisations should be available in either the embedded or non-embedded implementations. This assume that you are using the problem data update functions to do so. If you just rebuild the problem using a fresh solver object at every solve then you pay the factorisation costs every time. It's also possible that you have the embedded version configured to not dynamically update the I don't think you can expect a bigger performance gap at larger scales because I think the effect you are seeing isn't explainable by the above. |
Beta Was this translation helpful? Give feedback.
-
Whether or not the You will see in the link above though that for the embedded version "the frequency does not rely on any timing". What this means is that in the non-embedded case we update For comparison purposes, I think you need |
Beta Was this translation helpful? Give feedback.
-
Regarding "the frequency does not rely on any timing" : the solver works by choosing a single value This generally works well, but we sometimes find that our initial choice of We must then have some rule about when to compute such a refactorisation. In the non-embedded case we time the initial factorisation, and if the total iteration time exceeds some fraction of that initial factorisation time then we assume it will be beneficial to refactor. This is the We can also trigger a refactor (or at least check to see if it would be helpful) after a fixed number of iterations instead, and this is what is done in the embedded codegen default options. The reason is that we pre-compute the initial factorisation during codegen in this case, and so can't rely on the factorisation timing since the compiled code might be running on a different machine than the one that generated it. This is the I think, but am not entirely certain, that these are the only parameters that differ in the embedded codegen code. If you enable verbose output you should be able to see all of the settings in either case. As far as other settings go : it depends on the problem structure, overall size and how the solver is behaving on your problems in the first place. |
Beta Was this translation helpful? Give feedback.
Regarding "the frequency does not rely on any timing" : the solver works by choosing a single value
rho
and then computing a one-time matrix factorisation in the first iteration for a matrix whose entries are partly determined byrho
. Subsequent iterations then require only a forward-backward solve using those same factors. This means that the first iteration -- i.e. the one that computes the factors -- is much slower than subsequent ones.This generally works well, but we sometimes find that our initial choice of
rho
was not ideal. We therefore have the option to make a new choice and refactor. The downside of doing so is that we must make a new factorisation. The upside is that we can g…