Slowness in setting parameters in python API

40 views
Skip to first unread message

Jeremy Gray

unread,
Nov 25, 2016, 9:49:36 AM11/25/16
to Gurobi Optimization
Hi,

I'm running several thousand small models using the python API, and have run into some speed problems with setting parameters.

I've attached a sample script and profile log, to show timings - I've looped about 9000 times, setting 6 example parameters, and have over 11 million calls to posixpath, and several other functions. Right now the setting of parameters is taking an order of magnitude longer than actually solving the models.

It looks like the method model.setParams(param, val) is doing some strange things, likely related to the wildcard matching, even though my parameters exactly match the names.

Right now, I'm calling gurobi in a submodule, as well as modifying some parameters between models, so would not like to use the global setParams() function, if at all possible.

What seems to be happening, is the setattribute method of params is modified to allow for wildcard matching, which imports functools and fnmatch each time it is called, and runs a lot of calls (I'm guessing it is to do with matching the param name to the key). As the source is binary, its difficult to go any further.

So, is it possible to speed this up? Ideally some method like model.setParams() which only allows exact matches, or a way of setting several parameters at once using a dict.

Thanks,
Jeremy Gray
profilelog.txt
gurobi.py

Renan Garcia

unread,
Nov 25, 2016, 10:07:17 AM11/25/16
to gur...@googlegroups.com
Thank you for reporting this. A workaround, for now, is to store the parameter settings in a PRM file (see http://www.gurobi.com/documentation/7.0/refman/prm_format.html) and read them in with the Model.read() method (see http://www.gurobi.com/documentation/7.0/refman/py_model_read.html).

--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
<profilelog.txt><gurobi.py>

Renan Garcia

unread,
Nov 25, 2016, 12:02:18 PM11/25/16
to gur...@googlegroups.com
Fyi, we have identified a fix that significantly improves the time spent setting parameters in Python. Thank you for helping us improve the product. This fix will be part of our next release. Unfortunately, we don't have a target date yet for when that is due. In the meantime, I believe the PRM file workaround should help speed things up somewhat.

Jeremy Gray

unread,
Nov 25, 2016, 1:34:16 PM11/25/16
to Gurobi Optimization
Thanks Renan!

I'll put together the PRM workaround, it does look faster, at least in the benchmark above.

Thanks too for the quick turn around on the fix, hopefully it gets released soon.

Cheers,
Jeremy
Reply all
Reply to author
Forward
0 new messages