Coverage for python/lsst/ctrl/mpexec/quantumGraphExecutor.py: 89%

15 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-14 19:55 +0000

1# This file is part of ctrl_mpexec. 

2# 

3# Developed for the LSST Data Management System. 

4# This product includes software developed by the LSST Project 

5# (http://www.lsst.org). 

6# See the COPYRIGHT file at the top-level directory of this distribution 

7# for details of code ownership. 

8# 

9# This program is free software: you can redistribute it and/or modify 

10# it under the terms of the GNU General Public License as published by 

11# the Free Software Foundation, either version 3 of the License, or 

12# (at your option) any later version. 

13# 

14# This program is distributed in the hope that it will be useful, 

15# but WITHOUT ANY WARRANTY; without even the implied warranty of 

16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

17# GNU General Public License for more details. 

18# 

19# You should have received a copy of the GNU General Public License 

20# along with this program. If not, see <http://www.gnu.org/licenses/>. 

21 

22from __future__ import annotations 

23 

24__all__ = ["QuantumExecutor", "QuantumGraphExecutor"] 

25 

26from abc import ABC, abstractmethod 

27from typing import TYPE_CHECKING 

28 

29from .reports import QuantumReport, Report 

30 

31if TYPE_CHECKING: 

32 from lsst.daf.butler import Quantum 

33 from lsst.pipe.base import QuantumGraph, TaskDef 

34 

35 

36class QuantumExecutor(ABC): 

37 """Class which abstracts execution of a single Quantum. 

38 

39 In general implementation should not depend on execution model and 

40 execution should always happen in-process. Main reason for existence 

41 of this class is to provide do-nothing implementation that can be used 

42 in the unit tests. 

43 """ 

44 

45 @abstractmethod 

46 def execute(self, taskDef: TaskDef, quantum: Quantum) -> Quantum: 

47 """Execute single quantum. 

48 

49 Parameters 

50 ---------- 

51 taskDef : `~lsst.pipe.base.TaskDef` 

52 Task definition structure. 

53 quantum : `~lsst.daf.butler.Quantum` 

54 Quantum for this execution. 

55 

56 Returns 

57 ------- 

58 quantum : `~lsst.daf.butler.Quantum` 

59 The quantum actually executed. 

60 

61 Notes 

62 ----- 

63 Any exception raised by the task or code that wraps task execution is 

64 propagated to the caller of this method. 

65 """ 

66 raise NotImplementedError() 

67 

68 def getReport(self) -> QuantumReport | None: 

69 """Return execution report from last call to `execute`. 

70 

71 Returns 

72 ------- 

73 report : `~lsst.ctrl.mpexec.QuantumReport` 

74 Structure describing the status of the execution of a quantum. 

75 `None` is returned if implementation does not support this 

76 feature. 

77 

78 Raises 

79 ------ 

80 RuntimeError 

81 Raised if this method is called before `execute`. 

82 """ 

83 return None 

84 

85 

86class QuantumGraphExecutor(ABC): 

87 """Class which abstracts QuantumGraph execution. 

88 

89 Any specific execution model is implemented in sub-class by overriding 

90 the `execute` method. 

91 """ 

92 

93 @abstractmethod 

94 def execute(self, graph: QuantumGraph) -> None: 

95 """Execute whole graph. 

96 

97 Implementation of this method depends on particular execution model 

98 and it has to be provided by a subclass. Execution model determines 

99 what happens here; it can be either actual running of the task or, 

100 for example, generation of the scripts for delayed batch execution. 

101 

102 Parameters 

103 ---------- 

104 graph : `~lsst.pipe.base.QuantumGraph` 

105 Execution graph. 

106 """ 

107 raise NotImplementedError() 

108 

109 def getReport(self) -> Report | None: 

110 """Return execution report from last call to `execute`. 

111 

112 Returns 

113 ------- 

114 report : `~lsst.ctrl.mpexec.Report`, optional 

115 Structure describing the status of the execution of a quantum 

116 graph. `None` is returned if implementation does not support 

117 this feature. 

118 

119 Raises 

120 ------ 

121 RuntimeError 

122 Raised if this method is called before `execute`. 

123 """ 

124 return None