Hello everyone! I try to use scipy minimize to solve a minimization functions. My objective function and gradient function require multi-threaded computation. However, when calling these functions, there is no parallel or multithreaded execution, where there is when I run them not in scipy minimization. Here is my code:
def objective_and_gradient(ks_flat):
u_now, data_error_norm = heat_solver(k, t, T, num_steps, Lx, Ly, nx, ny,
k0, ks_flat, alpha, zero_source,
U_initial, u_data)
r_delta, ks_delta, k0_delta = D_adjoint(k, t, T, num_steps, Lx, Ly,
nx, ny, k0, ks_flat, alpha,
u_now, U_initial, u_data)
grad = ks_delta / np.linalg.norm(ks_delta) * np.linalg.norm(ks_flat) * 0.001
return data_error_norm, grad
result = minimize(
fun=objective_and_gradient,
x0=ks_initial,
method='BFGS',
jac=True,
options={'maxiter': N_k, 'disp': True}
)
Here the functions heat_solver
and D_adjoint
are multithreaded.
I want to know that if scipy minimization is able to run in a multithreaded way. If it is, how to do it?