Skip to content

Commit 2343059

Browse files
committed
fix: allow num_nodes to default to None and adjust logging for ensemble runs
1 parent 1619495 commit 2343059

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

ipsframework/services.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2469,7 +2469,7 @@ def run_ensemble(
24692469
variables: dict[str, dict[str, list[str]]],
24702470
run_dir: Union[str, os.PathLike],
24712471
name: str,
2472-
num_nodes: int,
2472+
num_nodes: int = None,
24732473
cores_per_instance: Optional[int] = None,
24742474
oversubscribe: bool = False,
24752475
hwthreads: bool = False,
@@ -2520,7 +2520,8 @@ def run_ensemble(
25202520
:param cores_per_instance: How many cores per ensemble instances?
25212521
:param num_nodes: Total number of nodes to allocate for the ensemble
25222522
runs. There will be one Dask worker assigned to each of these
2523-
nodes.
2523+
nodes. If none specified, then assign a worker to each allocated
2524+
node.
25242525
:param oversubscribe: Whether to allow oversubscription of nodes
25252526
when launching the ensemble runs. Default is False.
25262527
:param hwthreads: Whether to use hardware threads
@@ -2536,7 +2537,7 @@ def run_ensemble(
25362537

25372538
use_portal = self._should_use_portal()
25382539

2539-
self.debug(f'use portal = {use_portal!s}')
2540+
self.debug(f'run_ensemble() use portal = {use_portal!s}')
25402541

25412542
def create_driver_config_file(template,
25422543
working_dir,
@@ -2727,6 +2728,16 @@ def send_ensemble_instance_to_portal(ensemble_name: str, data_path: Path) -> Non
27272728

27282729
self.info(f'Preparing to run ensembles in {run_dir}')
27292730

2731+
# If the number of nodes is None and we're running in a Slurm
2732+
# environment, use as many nodes as has been allocated. Otherwise,
2733+
# assume we're running just on a local host.
2734+
if 'SLURM_JOB_NUM_NODES' in os.environ and num_nodes is None:
2735+
num_nodes = int(os.environ['SLURM_JOB_NUM_NODES'])
2736+
elif num_nodes is None:
2737+
num_nodes = 1
2738+
self.debug(f'run_ensemble() num_nodes = {num_nodes}')
2739+
2740+
27302741
# Ensure that we create a unique task pool name for this using the
27312742
# instance prefix `name`
27322743
# check this first to ensure uniqueness of `name` parameter

0 commit comments

Comments
 (0)