Performances of pywraplp vs mathopt (including LP warm-start) #4328
-
First of all, thanks to the google team for these amazing optimization libraries. They are extremely useful in my research work. I have been testing both pywraplp and mathopt in Python and I am a but confused by their performances. Concretely, I have numerous LP problems that are very similar and, to save time, I have been solving them consecutively using LP warm start to leverage previous LP solutions.
In both cases, I use the solver GLOP However, from my numerical tests, using pywraplp is 2 to 3 times faster than using mathopt. Is this difference of performances normal/known? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
One difference between MathOpt and With |
Beta Was this translation helpful? Give feedback.
-
To add a little to what soppera, said: It is very hard to say what is wrong without running a profiler. One guess is that building your protos could be a bottleneck. Internally, we use a C++ implementation of python proto. Getting this work externally requires some extra configuration/may not be possible with our existing build systems (bazel more likely to be supported than cmake). E.g. see: https://stackoverflow.com/questions/74941471/how-to-i-install-protobufs-c-python-extension Stepping back a bit, if model construction is indeed the bottleneck, and not solve time, then I think the right thing to do is to move as much of the computation out of python as possible. Ideally, you could just write the code in c++/java/go. But of course this is not always possible. Another option, assuming your data begins in numpy arrays, for mathopt to add bulk operations for Python, which is something we would like to do. I think that numpy bulk operations are utlimately faster and less intrusive to the code than trying to optimize all the constant factors by manually inlining things. |
Beta Was this translation helpful? Give feedback.
One difference between MathOpt and
pywraplp
is that MathOpt separates the model from the solver(s).With
pywraplp
you would reuse the same underlying Glop model when changing only a few things. This is possible with MathOpt as well by usingIncrementalSolver
. This class will allow you to call itssolve()
method multiple times and to reuse the same Glop solver.