Coverage for src/shephex/executor/slurm/functional.py: 33%
15 statements
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-29 18:45 +0100
« prev ^ index » next coverage.py v7.6.1, created at 2025-03-29 18:45 +0100
1from pathlib import Path
2from typing import Iterable, Optional
4from shephex import Experiment
5from shephex.executor.slurm import SlurmExecutor
8def slurm_execute(experiments: Experiment | Iterable[Experiment],
9 directory: Optional[Path | str] = None,
10 profile: Optional[str] = None,
11 config: Optional[Path | str] = None,
12 **kwargs) -> None:
13 """
14 Execute experiments on a Slurm cluster.
16 Parameters
17 ----------
18 experiments : Experiment | Iterable[Experiment]
19 The experiment(s) to execute.
20 directory : Path | str, optional
21 The directory where the Slurm submission script will be written. If not
22 provided, the script will be written to the `slurm` directory within the
23 first experiment's root directory.
24 profile : str, optional
25 The name of the Slurm profile to use. If provided, the executor will be
26 created using the profile configuration.
27 config : Path | str, optional
28 The path to a Slurm configuration file. If provided, the executor will be
29 created using the configuration file.
30 **kwargs
31 Additional keyword arguments to pass to the SlurmExecutor constructor.
32 These will override any values set in the profile or configuration file.
33 If no profile or configuration file is provided, these arguments are
34 required.
35 """
37 if isinstance(experiments, Experiment):
38 experiments = [experiments]
40 if directory is None:
41 directory = experiments[0].root_path / 'slurm'
43 if profile is not None:
44 executor = SlurmExecutor.from_profile(profile, directory=directory, **kwargs)
45 elif config is not None:
46 executor = SlurmExecutor.from_config(config, directory=directory, **kwargs)
47 else:
48 executor = SlurmExecutor(directory=directory, **kwargs)
50 executor.execute(experiments)