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

Error with scipy 1.8.0 #300

Closed
bwheelz36 opened this issue Feb 7, 2022 · 18 comments
Closed

Error with scipy 1.8.0 #300

bwheelz36 opened this issue Feb 7, 2022 · 18 comments

Comments

@bwheelz36
Copy link
Collaborator

I am getting an error with scipy 1.8.0

File "/home/brendan/python/TestVenv/lib/python3.8/site-packages/bayes_opt/util.py", line 65, in acq_max
if max_acq is None or -res.fun[0] >= max_acq:
TypeError: 'float' object is not subscriptable

The problem appears to be that in this new version of scipy, res.fun is returned as a number instead of an array.
I haven't yet found exactly where in scipy the change is. A fix may be as simple as adding an if statement to handle this case.

I'll keep looking into it but for now I suggest limiting scipy installations to 1.7 or less.

@jobquiroz
Copy link

I have the same problem. I used pip install scipy==1.7 and it seems to work.

@bfeif
Copy link

bfeif commented Mar 1, 2022

Came here with the same issue. pip install scipy==1.7 fixed it for me as well.

@aeslava97
Copy link

Same, pip install scipy==1.7 did it for me

bwpriest added a commit to LLNL/MuyGPyS that referenced this issue Mar 23, 2022
…tion. (#46)

* Refactored optimization API to take an opt_method arg.

* Exposed kwargs to wrapped optimization methods to the batch optimizer.

* Add wrapper for bayes_opt Bayesian optimization to optimization chassis.

* Added bayesian-optimization as a build dependency.

* Set scipy upper bound due to issue with bayesian-optimization (bayesian-optimization/BayesianOptimization#300).

* Added Bayesian optimization verification to version testing.

* Updated documentation to reflect support for BayesianOptimization.

* Fixed a bug that only occurred when optimizing eps.

* Added a test case that verifies that both array and kwarg versions of objective functions and their component parts agree.
@ngupta20
Copy link

Glad to see others have reproduced this issue,

#319 should handle this in a version-explicit way.

Thanks!

@bwheelz36
Copy link
Collaborator Author

hey all, just an update on this.
I have permissions to manage this repository now and I have merged #303 into the main branch, which should resolve this error. However, I am still not able to release the code through pypi or conda forge. I will keep trying to get these permissions, but for now I would recommend installing directly from the master branch like this:

 pip install git+https://github.com/fmfn/BayesianOptimization

@peterdsharpe
Copy link

peterdsharpe commented Jul 21, 2022

@bwheelz36 Any update on this after over a month? For a package with 6.1k stars, getting this fix pushed to PyPI/conda would seem to be quite critical.

@bwheelz36
Copy link
Collaborator Author

Agreed, the problem is I don't actually have the rights to do that yet. I'll try to get in touch with Fernando again though, thanks for the reminder.

@bwheelz36
Copy link
Collaborator Author

Assuming I get the rights, I can handle the pypi release - does anyone want to volunteer to help with the conda release? I guess I could figure it out but I don't normally use conda...

@xxl4tomxu98
Copy link

As far as I am concerned, this has NOT fixed, after I downgraded scipy version to 1.70 and installed "pip install git+https://github.com/fmfn/BayesianOptimization" I still got the same error, can anyone explain why?

@xxl4tomxu98
Copy link

Should I only do ONE of the above, namely either downgrade Scipy OR install Master branch of the repo, not both?

@bwheelz36
Copy link
Collaborator Author

@xxl4tomxu98 - either should fix it. if you install scipy version 1.8, install from the master branch here (which will also work with scipy 1.7)
if you pip install, make sure you have scipy version <1.8.
the most likely explanation as to why it didn't work when you downgraded to 1.7 is that somehow you hadn't actually downgraded with 1.7, or you did then it later got updated somehow. you could check:

import scipy
scipy.__version__

@xxl4tomxu98
Copy link

well, I do conda list and checked to see scipy is V1.7

@xxl4tomxu98
Copy link

My bayes_opt is also installed with conda

@daeh
Copy link

daeh commented Aug 17, 2022

Assuming I get the rights, I can handle the pypi release - does anyone want to volunteer to help with the conda release? I guess I could figure it out but I don't normally use conda...

@bwheelz36 I also have no experience maintaining conda packages, but I'm eager for this change to be available through conda. So if you think it'd actually be helpful, I'd be happy to lend a hand (basically just working off https://conda-forge.org/docs/maintainer/updating_pkgs.html#updating-recipes). Other people would obviously be better equipped, but let me know if you just need another person to help sort through the steps.

@bwheelz36
Copy link
Collaborator Author

Hi @daeh
Thanks! I'm not sure if you already read through #339 - basically the conda package should get updated once the pypi package gets updated, which should happen when I get the rights to it..

@edubu2
Copy link

edubu2 commented Jan 4, 2023

@bwheelz36, I'm still getting this error - I tried installing with pip, conda, and github, tried scipy==1.7 and 1.8, each on both python 3.10 and python 3.7. I see this was closed but am curious if this fix was uploaded?

In which environment does this work? Note I'm on Apple Silicon (M1 pro)

SETUP:

pbounds = {
    'n_estimators': (1, 50),
    'max_depth': (4, 40),
    'learning_rate': (0.3, 0.3),
    'colsample_bytree': (0.5, 1.),
    'min_child_weight': (1, 14),
    'subsample': (0.5, 1.),
    'reg_alpha': (0, 6),
    'reg_lambda': (1, 6),
    'gamma': (1, 6)
}

optimizer = BayesianOptimization(
    f=fit_bayesian,
    pbounds=pbounds,
    random_state=1
)

optimizer.maximize(
    init_points=2,
    n_iter=6,
)

ERROR:

/var/folders/96/g2vfz16s07jb12xnxmvl1zc80000gp/T/ipykernel_94169/80009563.py in <module>
      1 optimizer.maximize(
      2     init_points=2,
----> 3     n_iter=6,
      4 )

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/bayes_opt/bayesian_optimization.py in maximize(self, init_points, n_iter, acquisition_function, acq, kappa, kappa_decay, kappa_decay_delay, xi, **gp_params)
    309                 x_probe = self.suggest(util)
    310                 iteration += 1
--> 311             self.probe(x_probe, lazy=False)
    312 
    313             if self._bounds_transformer and iteration > 0:

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/bayes_opt/bayesian_optimization.py in probe(self, params, lazy)
    206             self._queue.add(params)
    207         else:
--> 208             self._space.probe(params)
    209             self.dispatch(Events.OPTIMIZATION_STEP)
    210 

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/bayes_opt/target_space.py in probe(self, params)
    234         x = self._as_array(params)
    235         params = dict(zip(self._keys, x))
--> 236         target = self.target_func(**params)
    237 
    238         if self._constraint is None:

/var/folders/96/g2vfz16s07jb12xnxmvl1zc80000gp/T/ipykernel_94169/129796447.py in fit_bayesian(n_estimators, max_depth, learning_rate, colsample_bytree, min_child_weight, subsample, reg_alpha, reg_lambda, gamma)
     39             reg_alpha=reg_alpha,
     40             reg_lambda=reg_lambda,
---> 41             gamma=gamma
     42             )
     43 

/var/folders/96/g2vfz16s07jb12xnxmvl1zc80000gp/T/ipykernel_94169/2885977117.py in fit_model(X_train, y_train, n_estimators, max_depth, learning_rate, colsample_bytree, min_child_weight, subsample, reg_alpha, reg_lambda, gamma)
     25             reg_lambda=reg_lambda,
     26             gamma=gamma)
---> 27         cv_model = model.fit(X_train, y_train)
     28 
     29         return cv_model

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/xgboost/core.py in inner_f(*args, **kwargs)
    573         for k, arg in zip(sig.parameters, args):
    574             kwargs[k] = arg
--> 575         return f(**kwargs)
    576 
    577     return inner_f

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/xgboost/sklearn.py in fit(self, X, y, sample_weight, base_margin, eval_set, eval_metric, early_stopping_rounds, verbose, xgb_model, sample_weight_eval_set, base_margin_eval_set, feature_weights, callbacks)
    970             verbose_eval=verbose,
    971             xgb_model=model,
--> 972             callbacks=callbacks,
    973         )
    974 

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/xgboost/core.py in inner_f(*args, **kwargs)
    573         for k, arg in zip(sig.parameters, args):
    574             kwargs[k] = arg
--> 575         return f(**kwargs)
    576 
    577     return inner_f

/opt/anaconda3/envs/bayes/lib/python3.7/site-packages/xgboost/training.py in train(params, dtrain, num_boost_round, evals, obj, feval, maximize, early_stopping_rounds, evals_result, verbose_eval, xgb_model, callbacks, custom_metric)
    176     bst = cb_container.before_training(bst)
    177 
--> 178     for i in range(start_iteration, num_boost_round):
    179         if cb_container.before_iteration(bst, i, dtrain, evals):
    180             break

TypeError: 'numpy.float64' object cannot be interpreted as an integer

@bwheelz36
Copy link
Collaborator Author

Hi, yes the fix has been uploaded to pypi.
could you let me know which version of each package you are using by pasting the output of pip freeze in a terminal?
Are you using a fresh environment? the most likely explanation is that a different package version than you think is being called.

@till-m
Copy link
Member

till-m commented Jan 5, 2023

I think that this is a different error, unrelated to this package. Either start_iteration or num_boost_round is a float/np.float64 when it should be of type int. Can you please post your fit_bayesian function, too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants