Skip to content

Commit 37e5061

Browse files
saitcakmakfacebook-github-bot
authored andcommitted
Make scipy minimize failure messages more verbose (#1579)
Summary: Pull Request resolved: #1579 I find warnings with "failed with status 2" uninformative. Having the message there should help interpret them better. Reviewed By: esantorella Differential Revision: D42156805 fbshipit-source-id: c9cc73c721bb86370f1919d1e0dbabbf6915e35d
1 parent 3f89c29 commit 37e5061

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

botorch/generation/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,6 @@ def _process_scipy_result(res: OptimizeResult, options: Dict[str, Any]) -> None:
440440
warnings.simplefilter("always", category=OptimizationWarning)
441441
warnings.warn(
442442
f"Optimization failed within `scipy.optimize.minimize` with status "
443-
f"{res.status}.",
443+
f"{res.status} and message {res.message}.",
444444
OptimizationWarning,
445445
)

test/generation/test_gen.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ def test_gen_candidates_scipy_warns_opt_failure(self):
202202
with warnings.catch_warnings(record=True) as ws:
203203
self.test_gen_candidates(options={"maxls": 1})
204204
expected_msg = (
205-
"Optimization failed within `scipy.optimize.minimize` with status 2."
205+
"Optimization failed within `scipy.optimize.minimize` with status 2"
206+
" and message ABNORMAL_TERMINATION_IN_LNSRCH."
206207
)
207208
expected_warning_raised = any(
208209
(

test/optim/test_optimize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,11 @@ def test_optimize_acqf_warns_on_opt_failure(self):
374374
message = (
375375
"Optimization failed in `gen_candidates_scipy` with the following "
376376
"warning(s):\n[OptimizationWarning('Optimization failed within "
377-
"`scipy.optimize.minimize` with status 2.')]\nBecause you specified"
378-
" `batch_initial_conditions`, optimization will not be retried with"
379-
" new initial conditions and will proceed with the current "
380-
"solution. Suggested remediation: Try again with different "
381-
"`batch_initial_conditions`, or don't provide "
377+
"`scipy.optimize.minimize` with status 2 and message ABNORMAL_TERMINATION"
378+
"_IN_LNSRCH.')]\nBecause you specified `batch_initial_conditions`, "
379+
"optimization will not be retried with new initial conditions and will "
380+
"proceed with the current solution. Suggested remediation: Try again with "
381+
"different `batch_initial_conditions`, or don't provide "
382382
"`batch_initial_conditions.`"
383383
)
384384
expected_warning_raised = any(
@@ -422,8 +422,8 @@ def test_optimize_acqf_successfully_restarts_on_opt_failure(self):
422422
message = (
423423
"Optimization failed in `gen_candidates_scipy` with the following "
424424
"warning(s):\n[OptimizationWarning('Optimization failed within "
425-
"`scipy.optimize.minimize` with status 2.')]\nTrying again with a "
426-
"new set of initial conditions."
425+
"`scipy.optimize.minimize` with status 2 and message ABNORMAL_TERMINATION"
426+
"_IN_LNSRCH.')]\nTrying again with a new set of initial conditions."
427427
)
428428
expected_warning_raised = any(
429429
(
@@ -470,8 +470,8 @@ def test_optimize_acqf_warns_on_second_opt_failure(self):
470470
message_1 = (
471471
"Optimization failed in `gen_candidates_scipy` with the following "
472472
"warning(s):\n[OptimizationWarning('Optimization failed within "
473-
"`scipy.optimize.minimize` with status 2.')]\nTrying again with a "
474-
"new set of initial conditions."
473+
"`scipy.optimize.minimize` with status 2 and message ABNORMAL_TERMINATION"
474+
"_IN_LNSRCH.')]\nTrying again with a new set of initial conditions."
475475
)
476476

477477
message_2 = (

0 commit comments

Comments
 (0)