cpdbench.task.Task
1from abc import ABC, abstractmethod 2from enum import Enum 3import functools 4import uuid 5 6 7class TaskType(Enum): 8 """Enum of pre-defined task types needed for the CPDBench""" 9 DATASET_FETCH = 1 10 ALGORITHM_EXECUTION = 2 11 METRIC_EXECUTION = 3 12 13 14class Task(ABC): 15 """Abstract class for a Task object which is a work package to be executed by the framework. 16 A task has a name, can be validated, and executed, and can have some parameters. 17 """ 18 19 def __init__(self, function, counter=0, param_dict=None): 20 """General constructor for all task objects. 21 :param function: The function handle to be executed as task content 22 :param counter: A number which is appended to the task name. Useful if multiple tasks with the same name exist. 23 :param param_dict: An optional parameter dictionary for the task 24 """ 25 self._function = function 26 if isinstance(function, functools.partial): 27 self._function_name = function.func.__name__ 28 else: 29 self._function_name = function.__name__ 30 self._task_name = self._function_name + ":" + str(counter) 31 self._param_dict = param_dict 32 33 @abstractmethod 34 def execute(self, *args) -> any: 35 """Executes the task. Can take an arbitrary number of arguments and can produce any result.""" 36 pass 37 38 @abstractmethod 39 def validate_task(self) -> None: 40 """Validates the task statically by checking task details before running it. 41 Throws an exception if the validation fails. 42 """ 43 pass 44 45 @abstractmethod 46 def validate_input(self, *args) -> any: 47 """Validates the task in combination with some input arguments. 48 Throws an exception if the validation fails. 49 """ 50 pass 51 52 @abstractmethod 53 def get_task_name(self) -> str: 54 """Returns a descriptive name for the task. 55 :return: task name as string 56 """ 57 pass 58 59 def get_param_dict(self) -> dict: 60 """Returns the parameters this task contains. 61 :return: the parameters as dictionary 62 """ 63 return self._param_dict
class
TaskType(enum.Enum):
8class TaskType(Enum): 9 """Enum of pre-defined task types needed for the CPDBench""" 10 DATASET_FETCH = 1 11 ALGORITHM_EXECUTION = 2 12 METRIC_EXECUTION = 3
Enum of pre-defined task types needed for the CPDBench
DATASET_FETCH =
<TaskType.DATASET_FETCH: 1>
ALGORITHM_EXECUTION =
<TaskType.ALGORITHM_EXECUTION: 2>
METRIC_EXECUTION =
<TaskType.METRIC_EXECUTION: 3>
Inherited Members
- enum.Enum
- name
- value
class
Task(abc.ABC):
15class Task(ABC): 16 """Abstract class for a Task object which is a work package to be executed by the framework. 17 A task has a name, can be validated, and executed, and can have some parameters. 18 """ 19 20 def __init__(self, function, counter=0, param_dict=None): 21 """General constructor for all task objects. 22 :param function: The function handle to be executed as task content 23 :param counter: A number which is appended to the task name. Useful if multiple tasks with the same name exist. 24 :param param_dict: An optional parameter dictionary for the task 25 """ 26 self._function = function 27 if isinstance(function, functools.partial): 28 self._function_name = function.func.__name__ 29 else: 30 self._function_name = function.__name__ 31 self._task_name = self._function_name + ":" + str(counter) 32 self._param_dict = param_dict 33 34 @abstractmethod 35 def execute(self, *args) -> any: 36 """Executes the task. Can take an arbitrary number of arguments and can produce any result.""" 37 pass 38 39 @abstractmethod 40 def validate_task(self) -> None: 41 """Validates the task statically by checking task details before running it. 42 Throws an exception if the validation fails. 43 """ 44 pass 45 46 @abstractmethod 47 def validate_input(self, *args) -> any: 48 """Validates the task in combination with some input arguments. 49 Throws an exception if the validation fails. 50 """ 51 pass 52 53 @abstractmethod 54 def get_task_name(self) -> str: 55 """Returns a descriptive name for the task. 56 :return: task name as string 57 """ 58 pass 59 60 def get_param_dict(self) -> dict: 61 """Returns the parameters this task contains. 62 :return: the parameters as dictionary 63 """ 64 return self._param_dict
Abstract class for a Task object which is a work package to be executed by the framework. A task has a name, can be validated, and executed, and can have some parameters.
Task(function, counter=0, param_dict=None)
20 def __init__(self, function, counter=0, param_dict=None): 21 """General constructor for all task objects. 22 :param function: The function handle to be executed as task content 23 :param counter: A number which is appended to the task name. Useful if multiple tasks with the same name exist. 24 :param param_dict: An optional parameter dictionary for the task 25 """ 26 self._function = function 27 if isinstance(function, functools.partial): 28 self._function_name = function.func.__name__ 29 else: 30 self._function_name = function.__name__ 31 self._task_name = self._function_name + ":" + str(counter) 32 self._param_dict = param_dict
General constructor for all task objects.
Parameters
- function: The function handle to be executed as task content
- counter: A number which is appended to the task name. Useful if multiple tasks with the same name exist.
- param_dict: An optional parameter dictionary for the task
@abstractmethod
def
execute(self, *args) -> <built-in function any>:
34 @abstractmethod 35 def execute(self, *args) -> any: 36 """Executes the task. Can take an arbitrary number of arguments and can produce any result.""" 37 pass
Executes the task. Can take an arbitrary number of arguments and can produce any result.
@abstractmethod
def
validate_task(self) -> None:
39 @abstractmethod 40 def validate_task(self) -> None: 41 """Validates the task statically by checking task details before running it. 42 Throws an exception if the validation fails. 43 """ 44 pass
Validates the task statically by checking task details before running it. Throws an exception if the validation fails.
@abstractmethod
def
validate_input(self, *args) -> <built-in function any>:
46 @abstractmethod 47 def validate_input(self, *args) -> any: 48 """Validates the task in combination with some input arguments. 49 Throws an exception if the validation fails. 50 """ 51 pass
Validates the task in combination with some input arguments. Throws an exception if the validation fails.