-
-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BUG: linprog, with highs is killed by the OOM killer when called with dense and large matrices #15888
Comments
@mckib2, is there a different interface for dense matrices or other sparse matrix formats? (I'm not aware of one.) @brunorigal does |
No, HIGHS will always expect a sparse constraint matrix here. Is there potentially a better/more direct way to get to a |
On the same script the interior point method raises an _ArrayMemoryError error, which is better. |
OK so @brunorigal we ultimately need a |
What about something like this specially for dense matrices: n_ctr, n_var = A.shape
A_indptr = (np.arange(n_ctr+1)*n_var).astype(np.int32)
A_indices = (np.meshgrid(np.arange(n_ctr), np.arange(n_var))[0].reshape(-1)).astype(np.int32)
A_data = A.reshape(-1, order='F')
res = _highs_wrapper(c, A_indptr, A_indices, A_data, lhs, rhs, lb, ub, options) in replacement for I checked it yields the same results than csc_matrix on this problem. However, the same problem is then observed in the highs wrapper. |
But why would the code go in
Which problem, specifically? "The script is killed by the OOM killer"? |
I guess you are right, it could be a part of the csc_matrix function. The "same problem" does refer to the OOM killer (it would then be a problem for the highs team). |
Ok, I'll add the sparse label. |
Looking into this a little more, HiGHS underneath relies on The stack overflow answer above suggests that a custom allocator could be used that simply "reuses" the array allocation for the vector, but it's not clear to me currently how well Cython supports custom C++ allocators/deleters. EDIT: followup: without C++17 features and a big rewrite of the HiGHS C++ interfaces, achieving this with custom allocators is probably not possible
By checking size of matrices and available memory? I'm not sure that's necessary or desirable, it seems standard to let the user try even to the point of crashing. What would we consider the "correct" behavior for the HiGHS wrapper? |
I do agree that checking the size of matrices is perhaps not the best solution. However, it would be desirable that the code fail with a python error instead of crashing python. For example if I try to allocate a very large matrix, numpy raises an ArrayMemoryError, which is good because I can catch it. |
@mckib2 is it possible for a Python error to be raised like NumPy's |
@mckib2 quick question here: is it possible for a Python error to be raised like NumPy's |
Crashing is always a bug. I see slightly more verbose output with the reproducer in the issue description, but that should be considered a bug:
It can't be fixed in the wrapper if it's crashing in HiGHS itself. Looking at how memory allocations in HiGHS, there is a random mix of usages of It seems to be like the HiGHS code should be audited for all memory allocations and improved, and once that is done it's probably a matter of catching |
More of a dodge than a fix, but will essentially work with exceptions now.
More of a dodge than a fix, but will essentially work with exceptions now.
More of a dodge than a fix, but will essentially work with exceptions now.
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
MAINT: Switch to the scipy fork of highs TST: xfail known flaky test Co-authored-by: mckib2 <mckib2@users.noreply.github.com> MAINT: Add a note on .gitmodule location Co-authored-by: h-vetinari <h-vetinari@users.noreply.github.com>
Describe your issue.
Hi,
I have a bug when using the highs linprog solver with the code below.
The script is killed by the OOM killer. The problem arises when calling csc_matrix, which itself builds a coo_matrix, which calls the nonzeros method which is supposed to return the indices of non zero (far too many in this dense case).
Is it necessary to call csc_matrix here? It seems very inefficient for dense matrices.
If such a transformation is necessary, it would be better that the code returns a python error to handle the problem correctly.
Reproducing Code Example
Error message
SciPy/NumPy/Python version information
scipy==1.7.3, numpy==1.22.2, python==3.8.10
The text was updated successfully, but these errors were encountered: