-
Notifications
You must be signed in to change notification settings - Fork 46
Description
Bug description
If you pip install nevergrad and look at the list of available optimizers given by optimagic, it includes bayes_opt and om.algos.nevergrad_bo. But these are not in fact usable without extra dependencies.
To Reproduce
I made a new clean python virtual environment and did pip install nevergrad optimagic
I then ran:
import optimagic as om
import numpy as np
def three_minima_function(params):
x, y = params
res = -2 * np.exp(-((x - 1) ** 2 + (y - 1) ** 2) / 0.2) \
- 1.5 * np.exp(-((x + 1) ** 2 + (y + 1) ** 2) / 0.5) \
- 1 * np.exp(-((x - 1) ** 2 + (y + 1) ** 2) / 1)
res = np.ceil(res * 100) / 100
return res
list_of_algos = om.algos.Scalar.Global.GradientFree.Bounded.Available
bounds = om.Bounds(lower=np.array([-5, -5]), upper=np.array([5, 5]))
algo = om.algos.nevergrad_bo # Also fails with om.algos.bayes_opt
res=om.minimize(
fun=three_minima_function,
params=np.arange(2),
algorithm=algo,
bounds=bounds,
algo_options={"stopping_maxfun": 50, "stopping_maxiter": 50},
)
print(algo, three_minima_function(res.x), res.nfev)
This code fails with:
from bayes_optim import RealSpace
ModuleNotFoundError: No module named 'bayes_optim'
If you try:
om.algos.bayes_opt
instead it fails with:
from bayes_opt import acquisition
ImportError: cannot import name 'acquisition' from 'bayes_opt' (/home/raph/python/myenv-opti/lib/python3.12/site-packages/bayes_opt/__init__.py)
Expected behavior
bayes_opt should be not offered when nevergrad is installed but a recent bayesian-optimization version is not. om.algos.nevergrad_bo should not be offered when bayes_optim is not installed.
You can get bayes_opt to work by pip install bayesian-optimization -U but that uninstalls nevergrad due to a version conflict. You can get om.algos.nevergrad_bo to work by pip install bayes_optim (this installs a number of huge torch/cuda related modules even if you don't have a GPU. There is a cpu only version of torch and the install is much faster if you do pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu first).
System
Ubuntu 24.04.2 LTS