From 6ae3a81debb28b6871b4ec6928a0b3cc55aeb45d Mon Sep 17 00:00:00 2001 From: Rohit Goswami Date: Sun, 30 Jul 2023 23:11:41 +0000 Subject: [PATCH] BUG: Fix gh-15888 More of a dodge than a fix, but will essentially work with exceptions now. --- scipy/optimize/_highs/cython/src/Highs.pxd | 2 +- scipy/optimize/_highs/cython/src/_highs_wrapper.pyx | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scipy/optimize/_highs/cython/src/Highs.pxd b/scipy/optimize/_highs/cython/src/Highs.pxd index 6d9a77d2c25f..64ff8029c1bb 100644 --- a/scipy/optimize/_highs/cython/src/Highs.pxd +++ b/scipy/optimize/_highs/cython/src/Highs.pxd @@ -22,7 +22,7 @@ cdef extern from "Highs.h": cdef cppclass Highs: HighsStatus passHighsOptions(const HighsOptions& options) HighsStatus passModel(const HighsLp& lp) - HighsStatus run() + HighsStatus run() except + HighsStatus setHighsLogfile(FILE* logfile) HighsStatus setHighsOutput(FILE* output) HighsStatus writeHighsOptions(const string filename, const bool report_only_non_default_values = true) diff --git a/scipy/optimize/_highs/cython/src/_highs_wrapper.pyx b/scipy/optimize/_highs/cython/src/_highs_wrapper.pyx index 0ed66806e611..41d56c0f93ed 100644 --- a/scipy/optimize/_highs/cython/src/_highs_wrapper.pyx +++ b/scipy/optimize/_highs/cython/src/_highs_wrapper.pyx @@ -649,7 +649,16 @@ def _highs_wrapper( } # Solve the LP - cdef HighsStatus run_status = highs.run() + cdef HighsStatus run_status = HighsStatusOK + try: + run_status = highs.run() + except Exception as e: + print(f"The problem is too large to be solved. Details: {e}") + return { + 'status': -1, # Probably should be something else + 'message': "The problem is too large to be solved.", + } + if run_status == HighsStatusError: return { 'status': highs.getModelStatus(),