Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client_kwargs option and fix datasets_from_delayed #103

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
9 changes: 8 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ History

.. current developments

v1.3
------
New features:
* Add `client_kwargs` option when starting a cluster with ``rhg_compute_tools.kubernetes.get_*_cluster``

Bug fixes:
* Fix typo preventing ``rhg_compute_tools.xarray.datasets_from_delayed`` from executing

v1.2.1
------
Bug fixes:
Expand All @@ -14,7 +22,6 @@ v1.2
New features:
* Adds google storage directory marker utilities and rctools gcs mkdirs command line app


v1.1.4
------
* Add ``dask_kwargs`` to the ``rhg_compute_tools.xarray`` functions
Expand Down
16 changes: 12 additions & 4 deletions rhg_compute_tools/kubernetes.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,19 @@ def decorator(func):
return decorator


def _get_cluster_dask_gateway(**kwargs):
def _get_cluster_dask_gateway(client_kwargs={}, **kwargs):
"""
Start dask.kubernetes cluster and dask.distributed client

All arguments are optional. If not provided, defaults will be used. To view
defaults, instantiate a :class:`dask_gateway.Gateway` object and call
`gateway.cluster_options()`.
`gateway.cluster_options()`. Kwargs are passed to the
:class:`dask_gateway.GatewayCluster` object, except for ``client_kwargs`` which are
passed to the :class:`distributed.Client` object.

Parameters
----------
client
name : str, optional
Name of worker image to use (e.g. ``rhodium/worker:latest``). If ``None``
(default), default to worker specified in ``template_path``.
Expand Down Expand Up @@ -166,7 +169,7 @@ def _get_cluster_dask_gateway(**kwargs):
elif k == "extra_pod_tolerations":
if (
"keep_default_tolerations" in kwargs.keys()
and kwargs["keep_default_tolerations"] == False
and not kwargs["keep_default_tolerations"]
):
base_tols = {}
else:
Expand All @@ -191,7 +194,12 @@ def _get_cluster_dask_gateway(**kwargs):
del new_kwargs["tag"]

cluster = gateway.new_cluster(**new_kwargs)
client = cluster.get_client()

# this snippet replicates the GatewayCluster.get_client functionality but with the
# option to pass extra kwargs to the Client instantiation
client = dd.Client(cluster, **client_kwargs)
if not cluster.asynchronous:
cluster._clients.add(client)

return client, cluster

Expand Down
2 changes: 1 addition & 1 deletion rhg_compute_tools/xarray.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def datasets_from_delayed(futures, client=None, **client_kwargs):

delayed_arrays = [
{
k: client.submit(lambda x: x[k].data, futures[i], client_kwargs)
k: client.submit(lambda x: x[k].data, futures[i], **client_kwargs)
for k in data_var_keys[i]
}
for i in range(len(futures))
Expand Down