numbbo / coco

Numerical Black-Box Optimization Benchmarking Framework
https://numbbo.github.io/coco
Other
263 stars 91 forks source link

RuntimeError: 50 elements of the 50 element gradient array `gradf` are NaN. This often indicates numerical issues. #2289

Closed Yash-Pisat closed 6 months ago

Yash-Pisat commented 6 months ago

I am using Bayesian Optimization as a solver for running experiments on BBOB test suite and I have selected few functions from this suite. I am using budget as 50 and running the experiment for all the dimension, it takes a lot of time. for these run which is expected.

I am getting this error now and then and it stops the experiment. Can anyone tell me, how I can resolve this numerical issue or bypass this issue:

Traceback (most recent call last): File "/Users/yash.pisat/Desktop/COCO/coco/experiments/Bay_opt_exp_template.py", line 219, in <module> train_x,train_y, mean_gp, variance_gp, acquisition_values_ei, model = fmin(problem, problem.lower_bounds, problem.upper_bounds, 2,"EI" ) File "/Users/yash.pisat/Desktop/COCO/coco/experiments/Bay_opt_exp_template.py", line 97, in BO new_x, acq_value = optimize_acqf( File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/optim/optimize.py", line 563, in optimize_acqf return _optimize_acqf(opt_acqf_inputs) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/optim/optimize.py", line 584, in _optimize_acqf return _optimize_acqf_batch(opt_inputs=opt_inputs) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/optim/optimize.py", line 349, in _optimize_acqf_batch batch_candidates, batch_acq_values, ws = _optimize_batch_candidates() File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/optim/optimize.py", line 333, in _optimize_batch_candidates ) = opt_inputs.gen_candidates( File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/generation/gen.py", line 252, in gen_candidates_scipy res = minimize_with_timeout( File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/optim/utils/timeout.py", line 80, in minimize_with_timeout return optimize.minimize( File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_minimize.py", line 713, in minimize res = _minimize_lbfgsb(fun, x0, args, jac, bounds, File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_lbfgsb_py.py", line 347, in _minimize_lbfgsb sf = _prepare_scalar_function(fun, x0, jac=jac, args=args, epsilon=eps, File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_optimize.py", line 288, in _prepare_scalar_function sf = ScalarFunction(fun, x0, args, grad, hess, File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_differentiable_functions.py", line 166, in __init__ self._update_fun() File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_differentiable_functions.py", line 262, in _update_fun self._update_fun_impl() File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_differentiable_functions.py", line 163, in update_fun self.f = fun_wrapped(self.x) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_differentiable_functions.py", line 145, in fun_wrapped fx = fun(np.copy(x), *args) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_optimize.py", line 79, in __call__ self._compute_if_needed(x, *args) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/scipy/optimize/_optimize.py", line 73, in _compute_if_needed fg = self.fun(x, *args) File "/Users/yash.pisat/Desktop/COCO/cocovenv/lib/python3.10/site-packages/botorch/generation/gen.py", line 220, in f_np_wrapper raise RuntimeError(msg) RuntimeError: 50 elements of the 50 element gradient arraygradfare NaN. This often indicates numerical issues.

nikohansen commented 6 months ago

This doesn't look to be much related to numbbo/coco and may well be a bug in scipy. A quick "fix" could cover the call with a try-except statement to catch the exception and move on.

nikohansen commented 6 months ago

Can this be closed?

Yash-Pisat commented 6 months ago

Yes sure! Thankyou for the suggestion. I'll implement it in my code.