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

15 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-10-17 09:41 +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 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 

41 

42class QuantumExecutor(ABC): 

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

44 

45 In general implementation should not depend on execution model and 

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

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

48 in the unit tests. 

49 """ 

50 

51 @abstractmethod 

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

53 """Execute single quantum. 

54 

55 Parameters 

56 ---------- 

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

58 Task definition structure. 

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

60 Quantum for this execution. 

61 

62 Returns 

63 ------- 

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

65 The quantum actually executed. 

66 

67 Notes 

68 ----- 

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

70 propagated to the caller of this method. 

71 """ 

72 raise NotImplementedError() 

73 

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

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

76 

77 Returns 

78 ------- 

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

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

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

82 feature. 

83 

84 Raises 

85 ------ 

86 RuntimeError 

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

88 """ 

89 return None 

90 

91 

92class QuantumGraphExecutor(ABC): 

93 """Class which abstracts QuantumGraph execution. 

94 

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

96 the `execute` method. 

97 """ 

98 

99 @abstractmethod 

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

101 """Execute whole graph. 

102 

103 Implementation of this method depends on particular execution model 

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

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

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

107 

108 Parameters 

109 ---------- 

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

111 Execution graph. 

112 """ 

113 raise NotImplementedError() 

114 

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

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

117 

118 Returns 

119 ------- 

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

121 Structure describing the status of the execution of a quantum 

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

123 this feature. 

124 

125 Raises 

126 ------ 

127 RuntimeError 

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

129 """ 

130 return None