Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OverflowError in nevergrad/optimization/utils.py #1495

Open
kvdblom opened this issue Feb 14, 2023 · 0 comments
Open

OverflowError in nevergrad/optimization/utils.py #1495

kvdblom opened this issue Feb 14, 2023 · 0 comments

Comments

@kvdblom
Copy link

kvdblom commented Feb 14, 2023

Steps to reproduce

  1. Run the attached code with the specific problem, dimension, algorithm combination. (There are other combinations with the same issue.)
  2. Observe the standard error output

Observed Results

  • add_evaluation in nevergrad/optimization/utils.py crashes with an OverflowError
  • From some investigation it appears the parameter values become extremely large/small, e.g. -6.52988354e+153 (and consequently the y values become inf or -inf?), resulting in a too large value when taking the square.
  • Main error output:
/.../venv/lib/python3.9/site-packages/sklearn/utils/extmath.py:152: RuntimeWarning: overflow encountered in matmul
  ret = a @ b
/.../venv/lib/python3.9/site-packages/sklearn/utils/extmath.py:152: RuntimeWarning: invalid value encountered in matmul
  ret = a @ b
/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py:146: LossTooLargeWarning: Clipping very high value nan in tell (rescale the cost function?).
  warnings.warn(msg, e)
Traceback (most recent call last):
  File "/.../mwe.py", line 44, in <module>
    run_algos(algorithm, problem, eval_budget, dimension, instance, seed)
  File "/.../mwe.py", line 29, in run_algos
    algorithm(function, seed)
  File "/.../mwe.py", line 18, in __call__
    optimizer.minimize(func)
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 659, in minimize
    args = self.ask()
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 469, in ask
    candidate = self._internal_ask_candidate()
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/optimizerlib.py", line 1552, in _internal_ask_candidate
    data = _learn_on_k_best(self.archive, sample_size)
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/optimizerlib.py", line 1510, in _learn_on_k_best
    minimum = optimizer.minimize(
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 642, in minimize
    self.tell(x, result)
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 381, in tell
    self._update_archive_and_bests(candidate, loss)
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/base.py", line 412, in _update_archive_and_bests
    mvalue.add_evaluation(loss)
  File "/.../venv/lib/python3.9/site-packages/nevergrad/optimization/utils.py", line 82, in add_evaluation
    self.square = max(self.square, self.mean ** 2)
OverflowError: (34, 'Numerical result out of range')

Relevant Code

The example below should reproduce the issue. For ioh==0.3.5 and nevergrad==0.5.0 with Python 3.9.5

import ioh
import nevergrad as ng
from nevergrad.optimization.optimizerlib import MetaModel  # noqa: F401


class NGEvaluator:
  def __init__(self, optimizer: str, eval_budget: int) -> None:
      self.alg = optimizer
      self.eval_budget = eval_budget

  def __call__(self, func, seed) -> None:
      parametrization = ng.p.Array(
          shape=(func.meta_data.n_variables,)).set_bounds(-5, 5)
      parametrization.random_state.seed(seed)
      optimizer = eval(f"{self.alg}")(
          parametrization=parametrization,
          budget=self.eval_budget)
      optimizer.minimize(func)


def run_algos(algorithm: str, problem: int,
            eval_budget: int,
            dimension: int,
            instance: int, seed: int) -> None:
  algorithm = NGEvaluator(algorithm, eval_budget)
  logger = ioh.logger.Analyzer()
  function = ioh.get_problem(problem, instance=instance,
                             dimension=dimension, problem_type="BBOB")
  algorithm(function, seed)
  function.reset()
  logger.close()

  return


if __name__ == "__main__":
  eval_budget = 10000
  dimension = 25
  problem = 11
  instance = 1
  algorithm = "MetaModel"
  seed = 1

  run_algos(algorithm, problem, eval_budget, dimension, instance, seed)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant