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

16 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-06-01 12:17 +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 

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

23 

24from abc import ABC, abstractmethod 

25from typing import Optional 

26 

27from .reports import QuantumReport, Report 

28 

29 

30class QuantumExecutor(ABC): 

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

32 

33 In general implementation should not depend on execution model and 

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

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

36 in the unit tests. 

37 """ 

38 

39 @abstractmethod 

40 def execute(self, taskDef, quantum, butler): 

41 """Execute single quantum. 

42 

43 Parameters 

44 ---------- 

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

46 Task definition structure. 

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

48 Quantum for this execution. 

49 butler : `~lsst.daf.butler.Butler` 

50 Data butler instance 

51 

52 Returns 

53 ------- 

54 quantum : `Quantum` 

55 The quantum actually executed. At present this quantum will 

56 contain only unresolved `DatasetRef` instances for output datasets, 

57 reflecting the state of the quantum just before it was run (but 

58 after any adjustments for predicted but now missing inputs). This 

59 may change in the future to include resolved output `DatasetRef` 

60 objects. 

61 

62 Notes 

63 ----- 

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

65 propagated to the caller of this method. 

66 """ 

67 raise NotImplementedError() 

68 

69 def getReport(self) -> Optional[QuantumReport]: 

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

71 

72 Returns 

73 ------- 

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

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

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

77 feature. 

78 

79 Raises 

80 ------ 

81 RuntimeError 

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

83 """ 

84 return None 

85 

86 

87class QuantumGraphExecutor(ABC): 

88 """Class which abstracts QuantumGraph execution. 

89 

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

91 the `execute` method. 

92 """ 

93 

94 @abstractmethod 

95 def execute(self, graph, butler): 

96 """Execute whole graph. 

97 

98 Implementation of this method depends on particular execution model 

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

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

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

102 

103 Parameters 

104 ---------- 

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

106 Execution graph. 

107 butler : `~lsst.daf.butler.Butler` 

108 Data butler instance 

109 """ 

110 raise NotImplementedError() 

111 

112 def getReport(self) -> Optional[Report]: 

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

114 

115 Returns 

116 ------- 

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

118 Structure describing the status of the execution of a quantum 

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

120 this feature. 

121 

122 Raises 

123 ------ 

124 RuntimeError 

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

126 """ 

127 return None