File tree 1 file changed +17
-14
lines changed
1 file changed +17
-14
lines changed Original file line number Diff line number Diff line change 14
14
import numpy .typing as npt
15
15
from botorch .exceptions .errors import OptimizationTimeoutError
16
16
from scipy import optimize
17
+ from threadpoolctl import threadpool_limits
17
18
18
19
19
20
def minimize_with_timeout (
@@ -79,20 +80,22 @@ def wrapped_callback(xk: npt.NDArray) -> None:
79
80
80
81
try :
81
82
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
+ )
96
99
except OptimizationTimeoutError as e :
97
100
msg = f"Optimization timed out after { e .runtime } seconds."
98
101
current_fun , * _ = fun (e .current_x , * args )
You can’t perform that action at this time.
0 commit comments