LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
pipeline.py
Go to the documentation of this file.
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 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/>.
21 
22 """Module defining Pipeline class and related methods.
23 """
24 
25 __all__ = ["Pipeline", "TaskDef"]
26 
27 # -------------------------------
28 # Imports of standard modules --
29 # -------------------------------
30 
31 # -----------------------------
32 # Imports for other modules --
33 # -----------------------------
34 
35 # ----------------------------------
36 # Local non-exported definitions --
37 # ----------------------------------
38 
39 # ------------------------
40 # Exported definitions --
41 # ------------------------
42 
43 
44 class TaskDef:
45  """TaskDef is a collection of information about task needed by Pipeline.
46 
47  The information includes task name, configuration object and optional
48  task class. This class is just a collection of attributes and it exposes
49  all of them so that attributes could potentially be modified in place
50  (e.g. if configuration needs extra overrides).
51 
52  Attributes
53  ----------
54  taskName : `str`
55  `PipelineTask` class name, currently it is not specified whether this
56  is a fully-qualified name or partial name (e.g. ``module.TaskClass``).
57  Framework should be prepared to handle all cases.
58  config : `lsst.pex.config.Config`
59  Instance of the configuration class corresponding to this task class,
60  usually with all overrides applied.
61  taskClass : `type` or ``None``
62  `PipelineTask` class object, can be ``None``. If ``None`` then
63  framework will have to locate and load class.
64  label : `str`, optional
65  Task label, usually a short string unique in a pipeline.
66  """
67  def __init__(self, taskName, config, taskClass=None, label=""):
68  self.taskName = taskName
69  self.config = config
70  self.taskClass = taskClass
71  self.label = label
72 
73  def __str__(self):
74  rep = "TaskDef(" + self.taskName
75  if self.label:
76  rep += ", label=" + self.label
77  rep += ")"
78  return rep
79 
80 
81 class Pipeline(list):
82  """Pipeline is a sequence of `TaskDef` objects.
83 
84  Pipeline is given as one of the inputs to a supervising framework
85  which builds execution graph out of it. Pipeline contains a sequence
86  of `TaskDef` instances.
87 
88  Main purpose of this class is to provide a mechanism to pass pipeline
89  definition from users to supervising framework. That mechanism is
90  implemented using simple serialization and de-serialization via
91  `pickle`. Note that pipeline serialization is not guaranteed to be
92  compatible between different versions or releases.
93 
94  In current implementation Pipeline is a list (it inherits from `list`)
95  and one can use all list methods on pipeline. Content of the pipeline
96  can be modified, it is up to the client to verify that modifications
97  leave pipeline in a consistent state. One could modify container
98  directly by adding or removing its elements.
99 
100  Parameters
101  ----------
102  pipeline : iterable of `TaskDef` instances, optional
103  Initial sequence of tasks.
104  """
105  def __init__(self, iterable=None):
106  list.__init__(self, iterable or [])
107 
108  def labelIndex(self, label):
109  """Return task index given its label.
110 
111  Parameters
112  ----------
113  label : `str`
114  Task label.
115 
116  Returns
117  -------
118  index : `int`
119  Task index, or -1 if label is not found.
120  """
121  for idx, taskDef in enumerate(self):
122  if taskDef.label == label:
123  return idx
124  return -1
125 
126  def __str__(self):
127  infos = [str(tdef) for tdef in self]
128  return "Pipeline({})".format(", ".join(infos))
def __init__(self, taskName, config, taskClass=None, label="")
Definition: pipeline.py:67
def __init__(self, iterable=None)
Definition: pipeline.py:105
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:168
daf::base::PropertyList * list
Definition: fits.cc:833