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

20 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2023-02-02 14:38 +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, 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 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 : `Quantum` 

59 The quantum actually executed. At present this quantum will 

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

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

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

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

64 objects. 

65 

66 Notes 

67 ----- 

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

69 propagated to the caller of this method. 

70 """ 

71 raise NotImplementedError() 

72 

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

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

75 

76 Returns 

77 ------- 

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

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

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

81 feature. 

82 

83 Raises 

84 ------ 

85 RuntimeError 

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

87 """ 

88 return None 

89 

90 

91class QuantumGraphExecutor(ABC): 

92 """Class which abstracts QuantumGraph execution. 

93 

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

95 the `execute` method. 

96 """ 

97 

98 @abstractmethod 

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

100 """Execute whole graph. 

101 

102 Implementation of this method depends on particular execution model 

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

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

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

106 

107 Parameters 

108 ---------- 

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

110 Execution graph. 

111 """ 

112 raise NotImplementedError() 

113 

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

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

116 

117 Returns 

118 ------- 

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

120 Structure describing the status of the execution of a quantum 

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

122 this feature. 

123 

124 Raises 

125 ------ 

126 RuntimeError 

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

128 """ 

129 return None