Coverage for python / lsst / pipe / base / execution_graph_fixup.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 08:18 +0000

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/>. 

27 

28__all__ = ["ExecutionGraphFixup"] 

29 

30import uuid 

31from abc import ABC 

32from collections.abc import Mapping 

33 

34import networkx 

35 

36from lsst.daf.butler import DataCoordinate 

37 

38from .graph import QuantumGraph 

39 

40 

41class ExecutionGraphFixup(ABC): 

42 """Interface for classes which update quantum graphs before execution. 

43 

44 Notes 

45 ----- 

46 The primary goal of this class is to modify quanta dependencies which may 

47 not be possible to reflect in a quantum graph using standard tools. One 

48 known use case for that is to guarantee particular execution order of 

49 visits in CI jobs for cases when outcome depends on the processing order of 

50 visits (e.g. AP association pipeline). 

51 

52 Instances of this class receive a preliminary graph and are allowed to 

53 add edges, as long as those edges do not result in a cycle. Edges and 

54 nodes may not be removed. 

55 

56 New subclasses should implement only `fixup_graph`, which will always be 

57 called first. `fixupQuanta` is only called if `fixup_graph` raises 

58 `NotImplementedError`. 

59 """ 

60 

61 def fixupQuanta(self, graph: QuantumGraph) -> QuantumGraph: 

62 """Update quanta in a graph. 

63 

64 Parameters 

65 ---------- 

66 graph : `.QuantumGraph` 

67 Quantum Graph that will be executed by the executor. 

68 

69 Returns 

70 ------- 

71 graph : `.QuantumGraph` 

72 Modified graph. 

73 

74 Notes 

75 ----- 

76 This hook is provided for backwards compatibility only. 

77 """ 

78 raise NotImplementedError() 

79 

80 def fixup_graph( 

81 self, xgraph: networkx.DiGraph, quanta_by_task: Mapping[str, Mapping[DataCoordinate, uuid.UUID]] 

82 ) -> None: 

83 """Update a networkx graph of quanta in place by adding edges to 

84 further constrain the ordering. 

85 

86 Parameters 

87 ---------- 

88 xgraph : `networkx.DiGraph` 

89 A directed acyclic graph of quanta to modify in place. Node keys 

90 are quantum UUIDs, and attributes include ``task_label`` (`str`) 

91 and ``data_id`` (a full `lsst.daf.butler.DataCoordinate`, without 

92 dimension records attached). Edges may be added, but not removed. 

93 Nodes may not be modified. 

94 quanta_by_task : `~collections.abc.Mapping` [ `str`,\ 

95 `~collections.abc.Mapping` [ `lsst.daf.butler.DataCoordinate`,\ 

96 `uuid.UUID` ] ] 

97 All quanta in the graph, grouped first by task label and then by 

98 data ID. 

99 """ 

100 raise NotImplementedError()