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

15 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-10 03:29 -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 software is dual licensed under the GNU General Public License and also 

10# under a 3-clause BSD license. Recipients may choose which of these licenses 

11# to use; please see the files gpl-3.0.txt and/or bsd_license.txt, 

12# respectively. If you choose the GPL option then the following text applies 

13# (but note that there is still no warranty even if you opt for BSD instead): 

14# 

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

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

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

18# (at your option) any later version. 

19# 

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

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

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

23# GNU General Public License for more details. 

24# 

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

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

27 

28from __future__ import annotations 

29 

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

31 

32from abc import ABC, abstractmethod 

33from typing import TYPE_CHECKING 

34 

35from .reports import QuantumReport, Report 

36 

37if TYPE_CHECKING: 

38 from lsst.daf.butler import Quantum 

39 from lsst.pipe.base import QuantumGraph, TaskDef 

40 from lsst.pipe.base.pipeline_graph import TaskNode 

41 

42 

43class QuantumExecutor(ABC): 

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

45 

46 In general implementation should not depend on execution model and 

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

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

49 in the unit tests. 

50 """ 

51 

52 @abstractmethod 

53 def execute(self, task_node: TaskNode | TaskDef, /, quantum: Quantum) -> Quantum: 

54 """Execute single quantum. 

55 

56 Parameters 

57 ---------- 

58 task_node : `~lsst.pipe.base.TaskDef` or \ 

59 `~lsst.pipe.base.pipeline_graph.TaskNode` 

60 Task definition structure. `~lsst.pipe.base.TaskDef` support is 

61 deprecated and will be removed after v27. 

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

63 Quantum for this execution. 

64 

65 Returns 

66 ------- 

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

68 The quantum actually executed. 

69 

70 Notes 

71 ----- 

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

73 propagated to the caller of this method. 

74 """ 

75 raise NotImplementedError() 

76 

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

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

79 

80 Returns 

81 ------- 

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

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

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

85 feature. 

86 

87 Raises 

88 ------ 

89 RuntimeError 

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

91 """ 

92 return None 

93 

94 

95class QuantumGraphExecutor(ABC): 

96 """Class which abstracts QuantumGraph execution. 

97 

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

99 the `execute` method. 

100 """ 

101 

102 @abstractmethod 

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

104 """Execute whole graph. 

105 

106 Implementation of this method depends on particular execution model 

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

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

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

110 

111 Parameters 

112 ---------- 

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

114 Execution graph. 

115 """ 

116 raise NotImplementedError() 

117 

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

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