Coverage for python/lsst/ctrl/mpexec/quantumGraphExecutor.py: 68%
20 statements
« prev ^ index » next coverage.py v7.2.6, created at 2023-05-26 02:14 -0700
« prev ^ index » next coverage.py v7.2.6, created at 2023-05-26 02:14 -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/>.
22from __future__ import annotations
24__all__ = ["QuantumExecutor", "QuantumGraphExecutor"]
26from abc import ABC, abstractmethod
27from typing import TYPE_CHECKING, Optional
29from .reports import QuantumReport, Report
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
36class QuantumExecutor(ABC):
37 """Class which abstracts execution of a single Quantum.
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 """
45 @abstractmethod
46 def execute(self, taskDef: TaskDef, quantum: Quantum) -> Quantum:
47 """Execute single quantum.
49 Parameters
50 ----------
51 taskDef : `~lsst.pipe.base.TaskDef`
52 Task definition structure.
53 quantum : `~lsst.daf.butler.Quantum`
54 Quantum for this execution.
56 Returns
57 -------
58 quantum : `Quantum`
59 The quantum actually executed.
61 Notes
62 -----
63 Any exception raised by the task or code that wraps task execution is
64 propagated to the caller of this method.
65 """
66 raise NotImplementedError()
68 def getReport(self) -> Optional[QuantumReport]:
69 """Return execution report from last call to `execute`.
71 Returns
72 -------
73 report : `~lsst.ctrl.mpexec.QuantumReport`
74 Structure describing the status of the execution of a quantum.
75 `None` is returned if implementation does not support this
76 feature.
78 Raises
79 ------
80 RuntimeError
81 Raised if this method is called before `execute`.
82 """
83 return None
86class QuantumGraphExecutor(ABC):
87 """Class which abstracts QuantumGraph execution.
89 Any specific execution model is implemented in sub-class by overriding
90 the `execute` method.
91 """
93 @abstractmethod
94 def execute(self, graph: QuantumGraph) -> None:
95 """Execute whole graph.
97 Implementation of this method depends on particular execution model
98 and it has to be provided by a subclass. Execution model determines
99 what happens here; it can be either actual running of the task or,
100 for example, generation of the scripts for delayed batch execution.
102 Parameters
103 ----------
104 graph : `~lsst.pipe.base.QuantumGraph`
105 Execution graph.
106 """
107 raise NotImplementedError()
109 def getReport(self) -> Optional[Report]:
110 """Return execution report from last call to `execute`.
112 Returns
113 -------
114 report : `~lsst.ctrl.mpexec.Report`, optional
115 Structure describing the status of the execution of a quantum
116 graph. `None` is returned if implementation does not support
117 this feature.
119 Raises
120 ------
121 RuntimeError
122 Raised if this method is called before `execute`.
123 """
124 return None