scipy: BUG: optimize.milp: segfault from HiGHS

Describe your issue.

Ran across a simple test case where many problems like the test case are used in production with no problems for years but the solver segmentation faults with this particular one. No output from the command line on verbose except

Running HiGHS 1.2.0 [date: 2021-07-09, git hash: n/a] Copyright © 2022 ERGO-Code under MIT licence terms Presolving model 29 rows, 231 cols, 1988 nonzeros Segmentation fault (core dumped) <

test.zip

Reproducing Code Example

import scipy.optimize as opt

import numpy as np

import pickle


[c1, constraints, integrality, bounds] = pickle.load(open('test.pkl', 'rb'))

res = opt.milp(c=c1, constraints=constraints,
        integrality=integrality, bounds=bounds, options={'disp':True})


print(res.x)

print('done')

Error message

$ python test_case_311.py 
Running HiGHS 1.2.0 [date: 2021-07-09, git hash: n/a]
Copyright (c) 2022 ERGO-Code under MIT licence terms
Presolving model
29 rows, 231 cols, 1988 nonzeros
Segmentation fault (core dumped)

SciPy/NumPy/Python version and system information

Currently on anaconda with 3.11 python
>>> scipy.__version__
'1.11.4'
I have also tried on anaconda with python 3.13 with the same results.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 17 (11 by maintainers)

Most upvoted comments

Very odd: I’ve reproduced this in (Python and) C++

When this error occurs, in the function detectParallelRowsAndCols(), the expression rowNz.index() is -1, which causes addToMatrix() to be called with col=-1. The value -1 is converted into the maximum unsigned integer, which is 18446744073709551615, which is bigger than the vector allocated for this.

Here is the line and the context:

#10 0x00007fffc7569c80 in presolve::HPresolve::detectParallelRowsAndCols (this=0x7fffffff8e90, postsolve_stack=...)
    at ../subprojects/highs/src/presolve/HPresolve.cpp:6156
6156	            addToMatrix(parallelRowCand, rowNz.index(),
(gdb) list
6151	          HighsInt pos = findNonzero(parallelRowCand, rowNz.index());
6152	          if (pos != -1)
6153	            unlink(pos);  // all common nonzeros are cancelled, as the rows are
6154	                          // parallel
6155	          else            // might introduce a singleton
6156	            addToMatrix(parallelRowCand, rowNz.index(),
6157	                        -rowScale * rowNz.value());
6158	        }
6159	
6160	        if (model->row_upper_[parallelRowCand] != kHighsInf)

I don’t know why rowNz.index() is -1.

With python 3.13 and scipy 1.14.1. Same error.