Skip to content

Commit a2c0cc6

Browse files
committed
add threadpool limits
1 parent 472de87 commit a2c0cc6

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

botorch/optim/utils/timeout.py

+17-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import numpy.typing as npt
1515
from botorch.exceptions.errors import OptimizationTimeoutError
1616
from scipy import optimize
17+
from threadpoolctl import threadpool_limits
1718

1819

1920
def minimize_with_timeout(
@@ -79,20 +80,22 @@ def wrapped_callback(xk: npt.NDArray) -> None:
7980

8081
try:
8182
warnings.filterwarnings("error", message="Method .* cannot handle")
82-
return optimize.minimize(
83-
fun=fun,
84-
x0=x0,
85-
args=args,
86-
method=method,
87-
jac=jac,
88-
hess=hess,
89-
hessp=hessp,
90-
bounds=bounds,
91-
constraints=constraints,
92-
tol=tol,
93-
callback=wrapped_callback,
94-
options=options,
95-
)
83+
# To prevent slowdowns after scipy 1.15.
84+
with threadpool_limits(limits=1, user_api="blas"):
85+
return optimize.minimize(
86+
fun=fun,
87+
x0=x0,
88+
args=args,
89+
method=method,
90+
jac=jac,
91+
hess=hess,
92+
hessp=hessp,
93+
bounds=bounds,
94+
constraints=constraints,
95+
tol=tol,
96+
callback=wrapped_callback,
97+
options=options,
98+
)
9699
except OptimizationTimeoutError as e:
97100
msg = f"Optimization timed out after {e.runtime} seconds."
98101
current_fun, *_ = fun(e.current_x, *args)

0 commit comments

Comments
 (0)