cpdbench.control.ExecutionController

 1from abc import ABC, abstractmethod
 2
 3from cpdbench.control.CPDResult import CPDResult
 4from cpdbench.exception.UserParameterDoesNotExistException import UserParameterDoesNotExistException
 5from cpdbench.exception.ValidationException import ValidationException
 6from cpdbench.task.Task import TaskType
 7from cpdbench.task.TaskFactory import TaskFactory
 8from cpdbench.utils import Utils
 9
10
11class ExecutionController(ABC):
12    """Abstract base class for testbench run configurations.
13    Each subclass has to give an execute_run() implementation with the actual run logic.
14    """
15
16    def __init__(self, logger):
17        self._logger = logger
18
19    @abstractmethod
20    def execute_run(self, methods: dict) -> CPDResult:
21        """Executes the run implemented by this class.
22        :param methods: dictionary with all given input functions, grouped by function type.
23        :return: A result object which can be handed to the user
24        """
25        pass
26
27    def _create_tasks(self, methods: dict) -> dict:
28        """Creates task objects from the entered function handles
29        :param methods: A dictionary containing the function handles, grouped by function type
30        :return: A dictionary of task objects, which were converted from the given handles
31        """
32        task_objects = {
33            "datasets": [],
34            "algorithms": [],
35            "metrics": []
36        }
37        task_factory = TaskFactory()
38        for dataset_function in methods["datasets"]:
39            self._logger.debug(f"Creating and validating dataset task "
40                               f"for {Utils.get_name_of_function(dataset_function)}")
41            try:
42                tasks = task_factory.create_tasks_with_parameters(dataset_function, TaskType.DATASET_FETCH)
43            except UserParameterDoesNotExistException as e:
44                self._logger.exception(e)
45                self._logger.debug(f"Creating {Utils.get_name_of_function(dataset_function)} has failed")
46                continue
47            try:
48                for task in tasks:
49                    task.validate_task()
50            except ValidationException as e:
51                self._logger.exception(e)
52            else:
53                self._logger.debug(f'Validating and creating {Utils.get_name_of_function(dataset_function)} has succeeded')
54                task_objects["datasets"] += tasks
55
56        for algorithm_function in methods["algorithms"]:
57            self._logger.debug(f"Creating and validating algorithm task "
58                               f"for {Utils.get_name_of_function(algorithm_function)}")
59            try:
60                tasks = task_factory.create_tasks_with_parameters(algorithm_function, TaskType.ALGORITHM_EXECUTION)
61            except UserParameterDoesNotExistException as e:
62                self._logger.exception(e)
63                self._logger.debug(f"Creating {Utils.get_name_of_function(algorithm_function)} has failed")
64                continue
65            try:
66                for task in tasks:
67                    task.validate_task()
68            except ValidationException as e:
69                self._logger.exception(e)
70            else:
71                self._logger.debug(f'Validating {Utils.get_name_of_function(algorithm_function)} has succeeded')
72                task_objects["algorithms"] += tasks
73
74        for metric_function in methods["metrics"]:
75            self._logger.debug(f"Creating and validating metric task "
76                               f"for {Utils.get_name_of_function(metric_function)}")
77            try:
78                tasks = task_factory.create_tasks_with_parameters(metric_function, TaskType.METRIC_EXECUTION)
79            except UserParameterDoesNotExistException as e:
80                self._logger.exception(e)
81                self._logger.debug(f"Creating {Utils.get_name_of_function(metric_function)} has failed")
82                continue
83            try:
84                for task in tasks:
85                    task.validate_task()
86            except ValidationException as e:
87                self._logger.exception(e)
88            else:
89                self._logger.debug(f'Validating {Utils.get_name_of_function(metric_function)} has succeeded')
90                task_objects["metrics"] += tasks
91        return task_objects
class ExecutionController(abc.ABC):
12class ExecutionController(ABC):
13    """Abstract base class for testbench run configurations.
14    Each subclass has to give an execute_run() implementation with the actual run logic.
15    """
16
17    def __init__(self, logger):
18        self._logger = logger
19
20    @abstractmethod
21    def execute_run(self, methods: dict) -> CPDResult:
22        """Executes the run implemented by this class.
23        :param methods: dictionary with all given input functions, grouped by function type.
24        :return: A result object which can be handed to the user
25        """
26        pass
27
28    def _create_tasks(self, methods: dict) -> dict:
29        """Creates task objects from the entered function handles
30        :param methods: A dictionary containing the function handles, grouped by function type
31        :return: A dictionary of task objects, which were converted from the given handles
32        """
33        task_objects = {
34            "datasets": [],
35            "algorithms": [],
36            "metrics": []
37        }
38        task_factory = TaskFactory()
39        for dataset_function in methods["datasets"]:
40            self._logger.debug(f"Creating and validating dataset task "
41                               f"for {Utils.get_name_of_function(dataset_function)}")
42            try:
43                tasks = task_factory.create_tasks_with_parameters(dataset_function, TaskType.DATASET_FETCH)
44            except UserParameterDoesNotExistException as e:
45                self._logger.exception(e)
46                self._logger.debug(f"Creating {Utils.get_name_of_function(dataset_function)} has failed")
47                continue
48            try:
49                for task in tasks:
50                    task.validate_task()
51            except ValidationException as e:
52                self._logger.exception(e)
53            else:
54                self._logger.debug(f'Validating and creating {Utils.get_name_of_function(dataset_function)} has succeeded')
55                task_objects["datasets"] += tasks
56
57        for algorithm_function in methods["algorithms"]:
58            self._logger.debug(f"Creating and validating algorithm task "
59                               f"for {Utils.get_name_of_function(algorithm_function)}")
60            try:
61                tasks = task_factory.create_tasks_with_parameters(algorithm_function, TaskType.ALGORITHM_EXECUTION)
62            except UserParameterDoesNotExistException as e:
63                self._logger.exception(e)
64                self._logger.debug(f"Creating {Utils.get_name_of_function(algorithm_function)} has failed")
65                continue
66            try:
67                for task in tasks:
68                    task.validate_task()
69            except ValidationException as e:
70                self._logger.exception(e)
71            else:
72                self._logger.debug(f'Validating {Utils.get_name_of_function(algorithm_function)} has succeeded')
73                task_objects["algorithms"] += tasks
74
75        for metric_function in methods["metrics"]:
76            self._logger.debug(f"Creating and validating metric task "
77                               f"for {Utils.get_name_of_function(metric_function)}")
78            try:
79                tasks = task_factory.create_tasks_with_parameters(metric_function, TaskType.METRIC_EXECUTION)
80            except UserParameterDoesNotExistException as e:
81                self._logger.exception(e)
82                self._logger.debug(f"Creating {Utils.get_name_of_function(metric_function)} has failed")
83                continue
84            try:
85                for task in tasks:
86                    task.validate_task()
87            except ValidationException as e:
88                self._logger.exception(e)
89            else:
90                self._logger.debug(f'Validating {Utils.get_name_of_function(metric_function)} has succeeded')
91                task_objects["metrics"] += tasks
92        return task_objects

Abstract base class for testbench run configurations. Each subclass has to give an execute_run() implementation with the actual run logic.

@abstractmethod
def execute_run(self, methods: dict) -> cpdbench.control.CPDResult.CPDResult:
20    @abstractmethod
21    def execute_run(self, methods: dict) -> CPDResult:
22        """Executes the run implemented by this class.
23        :param methods: dictionary with all given input functions, grouped by function type.
24        :return: A result object which can be handed to the user
25        """
26        pass

Executes the run implemented by this class.

Parameters
  • methods: dictionary with all given input functions, grouped by function type.
Returns

A result object which can be handed to the user