LSSTApplications  19.0.0-14-gb0260a2+b89439f59d,20.0.0+126303c00d,20.0.0+2f3d0e5c40,20.0.0+36ef800059,20.0.0+6ab788e194,20.0.0+a788ff1d83,20.0.0+b545961afb,20.0.0+bebc1f60e8,20.0.0+e2e26847c2,20.0.0+ec00f03e9c,20.0.0-1-g10df615+b92a01c08d,20.0.0-1-g253301a+36ef800059,20.0.0-1-g2b7511a+bebc1f60e8,20.0.0-1-g4d801e7+7c74587066,20.0.0-1-g5b95a8c+3e2d406de1,20.0.0-1-g660595b+f45b7d88f4,20.0.0-1-gc96f8cb+665e8551f1,20.0.0-1-gd1c87d7+85c46248f3,20.0.0-1-gedffbd8+ca2c461684,20.0.0-14-g1ce627f+450400e286,20.0.0-16-g111fe95+665e8551f1,20.0.0-16-g233ea98+b7ef15a6f8,20.0.0-17-ga9337b4+235318a901,20.0.0-2-g4dae9ad+665e8551f1,20.0.0-2-g7818986+85c46248f3,20.0.0-2-gec03fae+ff10c6d78d,20.0.0-25-g38d2b7ae+6870ac0cf6,20.0.0-3-g4cc78c6+63636aeed8,20.0.0-3-g6a8623c+450400e286,20.0.0-3-g750bffe+50c7740d2d,20.0.0-4-gfea843c+f45b7d88f4,20.0.0-48-gd64a390+cf2ddfd0ca,20.0.0-5-g357b56b+f45b7d88f4,20.0.0-5-gfcebe35+806271b712,20.0.0-7-gc818c6e6+7d435f9f99,20.0.0-7-gcda7bf1+1884c7ddc6,20.0.0-9-g61a2a9a3d+14f89e4eca,w.2020.39
LSSTDataManagementBasePackage
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.graph.QuantumGraph Class Reference
Inheritance diagram for lsst.pipe.base.graph.QuantumGraph:

Public Member Functions

def __init__ (self, iterable=None)
 
def load (cls, file, universe)
 
def save (self, file)
 
def quanta (self)
 
def quantaAsQgraph (self)
 
def countQuanta (self)
 
def traverse (self)
 

Public Attributes

 initInputs
 
 initIntermediates
 
 initOutputs
 

Detailed Description

QuantumGraph is a sequence of `QuantumGraphTaskNodes` objects.

Typically the order of the tasks in the list will be the same as the
order of tasks in a pipeline (obviously depends on the code which
constructs graph).

Parameters
----------
iterable : iterable of `QuantumGraphTaskNodes`, optional
    Initial sequence of per-task nodes.

Definition at line 120 of file graph.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.graph.QuantumGraph.__init__ (   self,
  iterable = None 
)

Definition at line 132 of file graph.py.

132  def __init__(self, iterable=None):
133  list.__init__(self, iterable or [])
134  self.initInputs = NamedKeyDict()
135  self.initIntermediates = NamedKeyDict()
136  self.initOutputs = NamedKeyDict()
137 

Member Function Documentation

◆ countQuanta()

def lsst.pipe.base.graph.QuantumGraph.countQuanta (   self)
Return total count of quanta in a graph.

Returns
-------
count : `int`
    Number of quanta in a graph.

Definition at line 239 of file graph.py.

239  def countQuanta(self):
240  """Return total count of quanta in a graph.
241 
242  Returns
243  -------
244  count : `int`
245  Number of quanta in a graph.
246  """
247  return sum(len(taskNodes.quanta) for taskNodes in self)
248 

◆ load()

def lsst.pipe.base.graph.QuantumGraph.load (   cls,
  file,
  universe 
)
Read QuantumGraph from a file that was made by `save`.

Parameters
----------
file : `io.BufferedIOBase`
    File with pickle data open in binary mode.
universe: `~lsst.daf.butler.DimensionUniverse`
    DimensionUniverse instance, not used by the method itself but
    needed to ensure that registry data structures are initialized.

Returns
-------
graph : `QuantumGraph`
    Resulting QuantumGraph instance.

Raises
------
TypeError
    Raised if pickle contains instance of a type other than
    QuantumGraph.

Notes
-----
Reading Quanta from pickle requires existence of singleton
DimensionUniverse which is usually instantiated during Registry
initializaion. To make sure that DimensionUniverse exists this method
accepts dummy DimensionUniverse argument.

Definition at line 160 of file graph.py.

160  def load(cls, file, universe):
161  """Read QuantumGraph from a file that was made by `save`.
162 
163  Parameters
164  ----------
165  file : `io.BufferedIOBase`
166  File with pickle data open in binary mode.
167  universe: `~lsst.daf.butler.DimensionUniverse`
168  DimensionUniverse instance, not used by the method itself but
169  needed to ensure that registry data structures are initialized.
170 
171  Returns
172  -------
173  graph : `QuantumGraph`
174  Resulting QuantumGraph instance.
175 
176  Raises
177  ------
178  TypeError
179  Raised if pickle contains instance of a type other than
180  QuantumGraph.
181 
182  Notes
183  -----
184  Reading Quanta from pickle requires existence of singleton
185  DimensionUniverse which is usually instantiated during Registry
186  initializaion. To make sure that DimensionUniverse exists this method
187  accepts dummy DimensionUniverse argument.
188  """
189  qgraph = pickle.load(file)
190  if not isinstance(qgraph, QuantumGraph):
191  raise TypeError(f"QuantumGraph pickle file has contains unexpected object type: {type(qgraph)}")
192  return qgraph
193 

◆ quanta()

def lsst.pipe.base.graph.QuantumGraph.quanta (   self)
Iterator over quanta in a graph.

Quanta are returned in unspecified order.

Yields
------
taskDef : `TaskDef`
    Task definition for a Quantum.
quantum : `~lsst.daf.butler.Quantum`
    Single quantum.

Definition at line 207 of file graph.py.

207  def quanta(self):
208  """Iterator over quanta in a graph.
209 
210  Quanta are returned in unspecified order.
211 
212  Yields
213  ------
214  taskDef : `TaskDef`
215  Task definition for a Quantum.
216  quantum : `~lsst.daf.butler.Quantum`
217  Single quantum.
218  """
219  for taskNodes in self:
220  taskDef = taskNodes.taskDef
221  for quantum in taskNodes.quanta:
222  yield taskDef, quantum
223 

◆ quantaAsQgraph()

def lsst.pipe.base.graph.QuantumGraph.quantaAsQgraph (   self)
Iterator over quanta in a graph.

QuantumGraph containing individual quanta are returned.

Yields
------
graph : `QuantumGraph`

Definition at line 224 of file graph.py.

224  def quantaAsQgraph(self):
225  """Iterator over quanta in a graph.
226 
227  QuantumGraph containing individual quanta are returned.
228 
229  Yields
230  ------
231  graph : `QuantumGraph`
232  """
233  for qdata in self.traverse():
234  node = QuantumGraphTaskNodes(qdata.taskDef, [qdata.quantum],
235  qdata.quantum.initInputs, qdata.quantum.outputs)
236  graph = QuantumGraph([node])
237  yield graph
238 

◆ save()

def lsst.pipe.base.graph.QuantumGraph.save (   self,
  file 
)
Save QuantumGraph to a file.

Presently we store QuantumGraph in pickle format, this could
potentially change in the future if better format is found.

Parameters
----------
file : `io.BufferedIOBase`
    File to write pickle data open in binary mode.

Definition at line 194 of file graph.py.

194  def save(self, file):
195  """Save QuantumGraph to a file.
196 
197  Presently we store QuantumGraph in pickle format, this could
198  potentially change in the future if better format is found.
199 
200  Parameters
201  ----------
202  file : `io.BufferedIOBase`
203  File to write pickle data open in binary mode.
204  """
205  pickle.dump(self, file)
206 

◆ traverse()

def lsst.pipe.base.graph.QuantumGraph.traverse (   self)
Return topologically ordered Quanta and their dependencies.

This method iterates over all Quanta in topological order, enumerating
them during iteration. Returned `QuantumIterData` object contains
Quantum instance, its ``index`` and the ``index`` of all its
prerequsites (Quanta that produce inputs for this Quantum):

- the ``index`` values are generated by an iteration of a
  QuantumGraph, and are not intrinsic to the QuantumGraph
- during iteration, each ID will appear in index before it ever
  appears in dependencies.

Yields
------
quantumData : `QuantumIterData`

Definition at line 249 of file graph.py.

249  def traverse(self):
250  """Return topologically ordered Quanta and their dependencies.
251 
252  This method iterates over all Quanta in topological order, enumerating
253  them during iteration. Returned `QuantumIterData` object contains
254  Quantum instance, its ``index`` and the ``index`` of all its
255  prerequsites (Quanta that produce inputs for this Quantum):
256 
257  - the ``index`` values are generated by an iteration of a
258  QuantumGraph, and are not intrinsic to the QuantumGraph
259  - during iteration, each ID will appear in index before it ever
260  appears in dependencies.
261 
262  Yields
263  ------
264  quantumData : `QuantumIterData`
265  """
266 
267  def orderedTaskNodes(graph):
268  """Return topologically ordered task nodes.
269 
270  Yields
271  ------
272  nodes : `QuantumGraphTaskNodes`
273  """
274  # Tasks in a graph are probably topologically sorted already but there
275  # is no guarantee for that. Just re-construct Pipeline and order tasks
276  # in a pipeline using existing method.
277  nodesMap = {id(item.taskDef): item for item in graph}
278  pipeline = orderPipeline([item.taskDef for item in graph])
279  for taskDef in pipeline:
280  yield nodesMap[id(taskDef)]
281 
282  index = 0
283  outputs = {} # maps (DatasetType.name, dataId) to its producing quantum index
284  for nodes in orderedTaskNodes(self):
285  for quantum in nodes.quanta:
286 
287  # Find quantum dependencies (must be in `outputs` already)
288  prereq = []
289  for dataRef in chain.from_iterable(quantum.predictedInputs.values()):
290  # if data exists in butler then `id` is not None
291  if dataRef.id is None:
292  # Get the base name if this is a component
293  name, component = dataRef.datasetType.nameAndComponent()
294  key = (name, dataRef.dataId)
295  try:
296  prereq.append(outputs[key])
297  except KeyError:
298  # The Quantum that makes our inputs is not in the graph,
299  # this could happen if we run on a "split graph" which is
300  # usually just one quantum. Check for number of Quanta
301  # in a graph and ignore error if it's just one.
302  # TODO: This code has to be removed or replaced with
303  # something more generic
304  if not (len(self) == 1 and len(self[0].quanta) == 1):
305  raise
306 
307  # Update `outputs` with this quantum outputs
308  for dataRef in chain.from_iterable(quantum.outputs.values()):
309  key = (dataRef.datasetType.name, dataRef.dataId)
310  outputs[key] = index
311 
312  yield QuantumIterData(index=index, quantum=quantum, taskDef=nodes.taskDef,
313  dependencies=frozenset(prereq))
314  index += 1

Member Data Documentation

◆ initInputs

lsst.pipe.base.graph.QuantumGraph.initInputs

Definition at line 134 of file graph.py.

◆ initIntermediates

lsst.pipe.base.graph.QuantumGraph.initIntermediates

Definition at line 135 of file graph.py.

◆ initOutputs

lsst.pipe.base.graph.QuantumGraph.initOutputs

Definition at line 136 of file graph.py.


The documentation for this class was generated from the following file:
id
table::Key< int > id
Definition: Detector.cc:162
lsst.pipe.base.pipeTools.orderPipeline
def orderPipeline(pipeline)
Definition: pipeTools.py:135