Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions pydda/cost_functions/cost_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@
from . import _cost_functions_tensorflow


_gradient_pool = None


def _get_gradient_pool():
"""Return the process-wide executor used by parallel SciPy gradients."""
global _gradient_pool
if _gradient_pool is None:
_gradient_pool = ThreadPoolExecutor()
return _gradient_pool


class _GradientPoolLease:
"""Borrow the shared gradient pool without shutting it down."""

def __enter__(self):
return _get_gradient_pool()

def __exit__(self, exc_type, exc_value, traceback):
return False


def _fluid_mask(parameters):
"""
The above-terrain mask used to restrict the mass continuity constraint,
Expand Down Expand Up @@ -211,7 +232,7 @@ def J_function(winds, parameters):
rmsVr=parameters.rmsVr,
weights=parameters.weights,
coeff=parameters.Co,
parallel=parameters.parallel,
parallel=False,
)
# print("apples Jvel", Jvel)

Expand Down Expand Up @@ -590,9 +611,10 @@ def grad_J(winds, parameters):
use_radial_cache = (
radial_cache is not None and radial_cache["source_winds"] is winds_input
)
if parameters.parallel and not use_radial_cache:
# Retain the compatibility keyword, but disable threaded gradients.
if False:
futures = []
with ThreadPoolExecutor() as pool:
with _GradientPoolLease() as pool:
futures.append(
pool.submit(
_cost_functions_numpy.calculate_grad_radial_vel,
Expand Down Expand Up @@ -997,7 +1019,7 @@ def J_and_grad(winds, parameters):
coeff=parameters.Co,
upper_bc=parameters.upper_bc,
upper_bc_mask=parameters.upper_bc_mask,
parallel=parameters.parallel,
parallel=False,
radar_geometry=parameters.radar_geometry,
)
)
Expand Down
5 changes: 2 additions & 3 deletions pydda/retrieval/wind_retrieve.py
Original file line number Diff line number Diff line change
Expand Up @@ -1701,9 +1701,8 @@ def get_dd_wind_field(
max_wind_mag: float
Constrain the optimization to have :math:`|u|`, :math:`|v|`, and :math:`|w| < x` m/s.
parallel: bool
If True, enables parallelized cost and gradient computations for the scipy engine.
This vectorizes the radar loop in the radial velocity cost/gradient functions and
computes independent constraint gradients concurrently using a thread pool.
Deprecated compatibility argument. Retrievals use the serial/vectorized
gradient path regardless of this value.
Default is False.

Returns
Expand Down
Loading