|
4 | 4 | import pandas as pd |
5 | 5 |
|
6 | 6 | from optiprofiler.opclasses import Problem |
7 | | -from optiprofiler.utils import get_logger |
| 7 | +from optiprofiler.utils import get_logger, shorten_log_message |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def s2mpj_load(problem_name, *args): |
@@ -64,7 +64,9 @@ def s2mpj_load(problem_name, *args): |
64 | 64 | # Add the subfolder 'python_problems' under the 'src' directory to the system path. |
65 | 65 | sys.path.insert(0, python_problems_dir) |
66 | 66 | 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 | + ) |
68 | 70 | raise |
69 | 71 |
|
70 | 72 | # 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): |
186 | 188 | bx = jx @ x0 - cx |
187 | 189 | except Exception as err: |
188 | 190 | _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) |
191 | 193 |
|
192 | 194 | nonlincons = np.setdiff1d(np.arange(p.m), p.lincons) |
193 | 195 | 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): |
641 | 643 | return h |
642 | 644 |
|
643 | 645 |
|
644 | | -def _warn_s2mpj_evaluation_failure(problem_name, what, err, max_len=180): |
| 646 | +def _warn_s2mpj_evaluation_failure(problem_name, what, err): |
645 | 647 | 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}') |
650 | 649 | logger.warning(f'Failed to evaluate {what} of S2MPJ problem {problem_name}: {msg}') |
0 commit comments