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

20 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-10-21 02:05 -0700

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, Optional 

28 

29from .reports import QuantumReport, Report 

30 

31if TYPE_CHECKING: 31 ↛ 32line 31 didn't jump to line 32, because the condition on line 31 was never true

32 from lsst.daf.butler import Butler, 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, butler: Butler) -> 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 butler : `~lsst.daf.butler.Butler` 

56 Data butler instance 

57 

58 Returns 

59 ------- 

60 quantum : `Quantum` 

61 The quantum actually executed. At present this quantum will 

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

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

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

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

66 objects. 

67 

68 Notes 

69 ----- 

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

71 propagated to the caller of this method. 

72 """ 

73 raise NotImplementedError() 

74 

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

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

77 

78 Returns 

79 ------- 

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

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

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

83 feature. 

84 

85 Raises 

86 ------ 

87 RuntimeError 

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

89 """ 

90 return None 

91 

92 

93class QuantumGraphExecutor(ABC): 

94 """Class which abstracts QuantumGraph execution. 

95 

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

97 the `execute` method. 

98 """ 

99 

100 @abstractmethod 

101 def execute(self, graph: QuantumGraph, butler: Butler) -> None: 

102 """Execute whole graph. 

103 

104 Implementation of this method depends on particular execution model 

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

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

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

108 

109 Parameters 

110 ---------- 

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

112 Execution graph. 

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

114 Data butler instance 

115 """ 

116 raise NotImplementedError() 

117 

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

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

120 

121 Returns 

122 ------- 

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

124 Structure describing the status of the execution of a quantum 

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

126 this feature. 

127 

128 Raises 

129 ------ 

130 RuntimeError 

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

132 """ 

133 return None