Skip to content

Commit 07f75b2

Browse files
committed
Refactor DifferentialEvolutionSolver initialization to support scipy version compatibility
1 parent fb9d6a2 commit 07f75b2

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

bayes_opt/acquisition.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727

2828
import numpy as np
2929
from numpy.random import RandomState
30+
from packaging import version
31+
from scipy import __version__ as scipy_version
3032
from scipy.optimize._differentialevolution import DifferentialEvolutionSolver, minimize
3133
from scipy.special import softmax
3234
from scipy.stats import norm
@@ -373,11 +375,17 @@ def _smart_minimize(
373375
# Case of mixed-integer optimization
374376
else:
375377
ntrials = max(1, len(x_seeds) // 100)
378+
376379
for _ in range(ntrials):
377380
xinit = space.random_sample(15 * len(space.bounds), random_state=self.random_state)
378-
de = DifferentialEvolutionSolver(
379-
acq, bounds=space.bounds, init=xinit, rng=self.random_state, polish=False
380-
)
381+
382+
de_parameters = {"func": acq, "bounds": space.bounds, "polish": False, "init": xinit}
383+
if version.parse(scipy_version) < version.parse("1.15.0"):
384+
de_parameters["seed"] = self.random_state
385+
else:
386+
de_parameters["rng"] = self.random_state
387+
388+
de = DifferentialEvolutionSolver(**de_parameters)
381389
res_de: OptimizeResult = de.solve()
382390
# Check if success
383391
if not res_de.success:

0 commit comments

Comments
 (0)