Coverage for credoai/prism/task.py: 88%

17 statements  

« prev     ^ index     » next       coverage.py v7.1.0, created at 2023-02-13 21:56 +0000

1""" 

2Abstract Class for Prism tasks. 

3""" 

4from abc import ABC, abstractclassmethod 

5from typing import List 

6from credoai.lens import Lens 

7 

8 

9class Task(ABC): 

10 """ 

11 Abstract class for prism tasks. 

12 

13 A task is any operation that can be run on a set of Lens objects or their results. 

14 

15 Tasks can be run by prism directly, or they can cross reference. For example, 

16 a task could: 

17 

18 1. Create multiple instances of Lens objects, e.g., by sampling the assessment dataset 

19 2. Call another task to compare or extract statistics from the resulting Lens runs. 

20 """ 

21 

22 def __init__(self): 

23 self.pipelines: List[Lens] = [] 

24 

25 @abstractclassmethod 

26 def _validate(self): 

27 """ 

28 Method encompassing any form of task parameters validation. 

29 """ 

30 ... 

31 

32 @abstractclassmethod 

33 def _setup(self): 

34 """ 

35 This method holds any setup procedure necessary for the task to run effectively. 

36 """ 

37 ... 

38 

39 def __call__(self, **kwargs): 

40 """ 

41 This method is used internally by Prism to pass lens pipelines to a task. 

42 """ 

43 self.__dict__.update(kwargs) 

44 self._validate() 

45 self._setup() 

46 return self