Skip to content

Commit

Permalink
Change recommend to raise an error in MOO case (#1213)
Browse files Browse the repository at this point in the history
* updated callback tests for MOO

* removed stray print

* Delete =

* updated optimization logger for MOO and added get_min_losses function

* edited get_min_losses

* type fixes

* removed testing statement

* removed testing statement

* updated recommendation and minimize

* more efficient get min losses

* added optimization logger test for single objective

* Updated error message

* Update nevergrad/optimization/base.py

Co-authored-by: Jérémy Rapin <jrapin.github@gmail.com>

Co-authored-by: Theodore Clarke <theoajclarke@devfair0149.h2.fair>
Co-authored-by: Jérémy Rapin <jrapin.github@gmail.com>
  • Loading branch information
3 people authored Aug 23, 2021
1 parent 3b09e00 commit 46e2ba7
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nevergrad/optimization/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,10 @@ def recommend(self) -> p.Parameter:
The candidate with minimal loss. :code:`p.Parameters` have field :code:`args` and :code:`kwargs` which can be directly used
on the function (:code:`objective_function(*candidate.args, **candidate.kwargs)`).
"""
if self.num_objectives > 1:
raise RuntimeError(
"No best candidate in MOO. Use optimizer.pareto_front() instead to get the set of all non-dominated candidates."
)
recom_data = self._internal_provide_recommendation() # pylint: disable=assignment-from-none
if recom_data is None or any(np.isnan(recom_data)):
name = "minimum" if self.parametrization.function.deterministic else "pessimistic"
Expand Down Expand Up @@ -652,7 +656,7 @@ def minimize(
(tmp_finished if x_job[1].done() else tmp_runnings).append(x_job)
self._running_jobs, self._finished_jobs = tmp_runnings, tmp_finished
first_iteration = False
return self.provide_recommendation()
return self.provide_recommendation() if self.num_objectives == 1 else p.Constant(None)

def _info(self) -> tp.Dict[str, tp.Any]:
"""Easy access to debug/benchmark info"""
Expand Down

0 comments on commit 46e2ba7

Please sign in to comment.