Skip to content

Commit a3c9089

Browse files
committed
Improve info
1 parent 35d211b commit a3c9089

1 file changed

Lines changed: 8 additions & 9 deletions

File tree

s2mpj_tools.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pandas as pd
55

66
from optiprofiler.opclasses import Problem
7-
from optiprofiler.utils import get_logger
7+
from optiprofiler.utils import get_logger, shorten_log_message
88

99

1010
def s2mpj_load(problem_name, *args):
@@ -64,7 +64,9 @@ def s2mpj_load(problem_name, *args):
6464
# Add the subfolder 'python_problems' under the 'src' directory to the system path.
6565
sys.path.insert(0, python_problems_dir)
6666
except Exception as err:
67-
get_logger(__name__).warning(f'Failed to add the path of Python problems of S2MPJ to the system path: {err}')
67+
get_logger(__name__).warning(
68+
f'Failed to add the path of Python problems of S2MPJ to the system path: {shorten_log_message(err)}'
69+
)
6870
raise
6971

7072
# Check if 'problem_name' has the pattern '_n_m' or '_n'. If it has, find the position of the pattern and return the dimension 'n' and the number of constraints 'm'.
@@ -186,8 +188,8 @@ def s2mpj_load(problem_name, *args):
186188
bx = jx @ x0 - cx
187189
except Exception as err:
188190
_warn_s2mpj_evaluation_failure(name, 'the linear constraint Jacobian', err)
189-
jx = None
190-
bx = None
191+
jx = np.full((getattr(p, 'm', 0), getattr(p, 'n', x0.size)), np.nan)
192+
bx = np.full(getattr(p, 'm', 0), np.nan)
191193

192194
nonlincons = np.setdiff1d(np.arange(p.m), p.lincons)
193195
idx_eq = np.intersect1d(np.arange(p.nle, p.nle + p.neq), idx_cl_finite)
@@ -641,10 +643,7 @@ def _getHx(p, problem_name, x):
641643
return h
642644

643645

644-
def _warn_s2mpj_evaluation_failure(problem_name, what, err, max_len=180):
646+
def _warn_s2mpj_evaluation_failure(problem_name, what, err):
645647
logger = get_logger(__name__)
646-
msg = f'{type(err).__name__}: {err}'
647-
msg = re.sub(r'\s+', ' ', msg).strip()
648-
if len(msg) > max_len:
649-
msg = msg[:max_len - 3] + '...'
648+
msg = shorten_log_message(f'{type(err).__name__}: {err}')
650649
logger.warning(f'Failed to evaluate {what} of S2MPJ problem {problem_name}: {msg}')

0 commit comments

Comments
 (0)