pipefunc.resources module#
Provides the pipefunc.resources module, containing the Resources class.
- class pipefunc.resources.Resources(cpus=None, cpus_per_node=None, nodes=None, memory=None, gpus=None, time=None, partition=None, extra_args=<factory>, parallelization_mode='external')[source]#
Bases:
objectA dataclass representing computational resources for a job.
- Parameters:
cpus (
int|None) β The number of CPUs required for the job. Must be a positive integer.cpus_per_node (
int|None) β The number of CPUs per node required for the job. Must be a positive integer.nodes (
int|None) β The number of nodes required for the job. Must be a positive integer.memory (
str|None) β The memory required for the job. Must be a valid string (e.g.,'2GB','500MB').gpus (
int|None) β The number of GPUs required for the job. Must be a non-negative integer.time (
str|None) β The time required for the job. Must be a valid string (e.g.,'2:00:00','48:00:00').partition (
str|None) β The partition to submit the job to.extra_args (
dict[str,Any]) β Extra arguments for the job. Default is an empty dictionary.parallelization_mode (
Literal['internal','external']) β Specifies how parallelization should be handled. βinternalβ: The function should use the resources (e.g., cpus) to handle its own parallelization. βexternalβ: The function should operate on a single core, with parallelization managed externally. Default is βexternalβ.
- Raises:
ValueError β If any of the input parameters do not meet the specified constraints.
Notes
cpus_per_nodemust be specified withnodes.
Examples
>>> resources = Resources(cpus=4, memory='16GB', time='2:00:00') >>> resources.cpus 4 >>> resources.memory '16GB' >>> resources.time '2:00:00'
- static maybe_from_dict(resources)[source]#
Create a Resources instance from a dictionary, if not already an instance and not None.
- to_slurm_options()[source]#
Convert the Resources instance to SLURM options.
- Returns:
A string containing the SLURM options.
- Return type:
- static combine_max(resources_list)[source]#
Combine multiple Resources instances by taking the maximum value for each attribute.
- with_defaults(default_resources)[source]#
Combine the Resources instance with default resources.
- Return type: