Skip to content

Commit

Permalink
Handle dask distributed progress (#614)
Browse files Browse the repository at this point in the history
* distributed progress

* test local cluster
  • Loading branch information
alimanfoo authored Sep 20, 2024
1 parent 68ff103 commit 628f198
Show file tree
Hide file tree
Showing 5 changed files with 592 additions and 39 deletions.
11 changes: 8 additions & 3 deletions malariagen_data/anoph/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
LoggingHelper,
check_colab_location,
check_types,
distributed_client,
get_gcp_region,
hash_params,
init_filesystem,
Expand Down Expand Up @@ -174,9 +175,13 @@ def _dask_progress(self, desc=None, leave=False, **kwargs): # pragma: no cover
# Progress doesn't mix well with debug logging.
show_progress = self._show_progress and not self._debug
if show_progress:
return TqdmCallback(
desc=desc, leave=leave, tqdm_class=self._tqdm_class, **kwargs
)
if distributed_client():
# Cannot easily show progress, fall back to spinner.
return self._spinner(desc=desc)
else:
return TqdmCallback(
desc=desc, leave=leave, tqdm_class=self._tqdm_class, **kwargs
)
else:
return nullcontext()

Expand Down
10 changes: 10 additions & 0 deletions malariagen_data/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1423,3 +1423,13 @@ def hash_columns(x):
v = x[i, j]
out[j] = out[j] * 33 + v
return out


def distributed_client():
from distributed import get_client

try:
client = get_client()
except ValueError:
client = None
return client
Loading

0 comments on commit 628f198

Please sign in to comment.