DaskClusterFactory
Purpose
This is the recommended API for most users.
The DaskClusterFactory chooses the right cluster implementation at runtime.
It checks SLURM_JOB_ID to detect whether batchlet is running inside an
existing SLURM allocation.
If
SLURM_JOB_IDis set: it createsDaskSlurmClusterand waits for all workers.Otherwise: it creates a local dask cluster via
DaskLocalCluster.
This makes application code portable across local development and SLURM-backed execution without changing cluster-creation logic.
Usage
from ska_sdp_batchlet import DaskClusterFactory
dask_params = {
"workers_per_node": 2,
"threads_per_worker": 2,
"memory_per_worker": "4GB",
"resources_per_worker": "GPU=1,CPU=2",
}
with DaskClusterFactory.get_cluster(dask_params) as cluster:
client = cluster.get_client()
# run dask code using client
API
- class ska_sdp_batchlet.DaskClusterFactory[source]
A factory class which returns a new instance of a SpecCluster based dask cluster instance.
This factory current supports 2 kinds of clusters: 1. Slurm-based cluster using via
DaskSlurmCluster2. Local cluster using viaDaskLocalCluster()- classmethod get_cluster(dask_cluster_params)[source]
Create and return a dask cluster based on the execution environment.
- Parameters:
dask_cluster_params (
dict) -- User provided dask cluster parameters. These are forwarded as is to the constructor of the dask cluster classes.- Return type:
- Returns:
Cluster instance which inherits
SpecCluster.