coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
514 stars 89 forks source link

Setting threads parameter leads to Cbc crash #303

Closed Sceriffo closed 1 year ago

Sceriffo commented 1 year ago

Describe the bug Setting threads parameter using model's setter method doesn't work and leads to crash of Cbc at the end of computation.

ERROR while running Cbc. Signal SIGSEGV caught. Getting stack trace.
...
python3(_PyObject_MakeTpCall+0x296) [0x5f74f6]
python3(_PyEval_EvalFrameDefault+0x5dc4) [0x571164]
python3(_PyEval_EvalCodeWithName+0x26a) [0x569dba]
python3(_PyFunction_Vectorcall+0x393) [0x5f6eb3]
python3(_PyEval_EvalFrameDefault+0x85a) [0x56bbfa]
python3(_PyEval_EvalCodeWithName+0x26a) [0x569dba]
python3(_PyFunction_Vectorcall+0x393) [0x5f6eb3]
python3(_PyEval_EvalFrameDefault+0x85a) [0x56bbfa]
python3(_PyFunction_Vectorcall+0x1b6) [0x5f6cd6]
python3(_PyEval_EvalFrameDefault+0x72d) [0x56bacd]
python3(_PyEval_EvalCodeWithName+0x26a) [0x569dba]
python3(_PyFunction_Vectorcall+0x393) [0x5f6eb3]
python3(_PyEval_EvalFrameDefault+0x72d) [0x56bacd]
python3(_PyEval_EvalCodeWithName+0x26a) [0x569dba]
python3(PyEval_EvalCode+0x27) [0x6902a7]
python3() [0x67f951]
python3() [0x67f9cf]
python3() [0x67fa71]
python3(PyRun_SimpleFileExFlags+0x197) [0x681b97]
python3(Py_RunMain+0x212) [0x6b9d32]
python3(Py_BytesMain+0x2d) [0x6ba0bd]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7f92f51de083]
python3(_start+0x2e) [0x5fc5fe]

To Reproduce

model.threads = 2
model.optimize()

Expected behavior Threads limited to 2 and Cbc oesn't crash

Desktop (please complete the following information):

Additional context I notice that it works fine by using the Cbc wrapped method. Like:

cbc_set_parameter(model.solver, "threads", "{}".format(2))
Sceriffo commented 1 year ago

I might have a fix.

sebheger commented 1 year ago

@Sceriffo We are more that happy to review a pull request