Coverage for python / lsst / pipe / base / quantum_graph_executor.py: 92%
13 statements
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 01:22 -0800
« prev ^ index » next coverage.py v7.13.1, created at 2026-01-09 01:22 -0800
1# This file is part of pipe_base.
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/>.
28from __future__ import annotations
30__all__ = ["QuantumExecutor", "QuantumGraphExecutor"]
32from abc import ABC, abstractmethod
33from typing import TYPE_CHECKING
35from .quantum_reports import QuantumReport, Report
37if TYPE_CHECKING:
38 import uuid
40 from lsst.daf.butler import Quantum
42 from .graph import QuantumGraph
43 from .pipeline_graph import TaskNode
44 from .quantum_graph import PredictedQuantumGraph
47class QuantumExecutor(ABC):
48 """Class which abstracts execution of a single Quantum.
50 In general implementation should not depend on execution model and
51 execution should always happen in-process. Main reason for existence
52 of this class is to provide do-nothing implementation that can be used
53 in the unit tests.
54 """
56 @abstractmethod
57 def execute(
58 self, task_node: TaskNode, /, quantum: Quantum, quantum_id: uuid.UUID | None = None
59 ) -> tuple[Quantum, QuantumReport | None]:
60 """Execute single quantum.
62 Parameters
63 ----------
64 task_node : `~.pipeline_graph.TaskNode`
65 Task definition structure.
66 quantum : `~lsst.daf.butler.Quantum`
67 Quantum for this execution.
68 quantum_id : `uuid.UUID` or `None`, optional
69 The ID of the quantum to be executed.
71 Returns
72 -------
73 quantum : `~lsst.daf.butler.Quantum`
74 The quantum actually executed.
75 report : `~.quantum_reports.QuantumReport`
76 Structure describing the status of the execution of a quantum.
77 `None` is returned if implementation does not support this
78 feature.
80 Notes
81 -----
82 Any exception raised by the task or code that wraps task execution is
83 propagated to the caller of this method.
84 """
85 raise NotImplementedError()
88class QuantumGraphExecutor(ABC):
89 """Class which abstracts QuantumGraph execution.
91 Any specific execution model is implemented in sub-class by overriding
92 the `execute` method.
93 """
95 @abstractmethod
96 def execute(self, graph: QuantumGraph | PredictedQuantumGraph) -> None:
97 """Execute whole graph.
99 Implementation of this method depends on particular execution model
100 and it has to be provided by a subclass. Execution model determines
101 what happens here; it can be either actual running of the task or,
102 for example, generation of the scripts for delayed batch execution.
104 Parameters
105 ----------
106 graph : `.QuantumGraph`
107 Execution graph.
108 """
109 raise NotImplementedError()
111 def getReport(self) -> Report | None:
112 """Return execution report from last call to `execute`.
114 Returns
115 -------
116 report : `~.quantum_reports.Report`, optional
117 Structure describing the status of the execution of a quantum
118 graph. `None` is returned if implementation does not support
119 this feature.
121 Raises
122 ------
123 RuntimeError
124 Raised if this method is called before `execute`.
125 """
126 return None