LSST Applications  22.0.1,22.0.1+01bcf6a671,22.0.1+046ee49490,22.0.1+05c7de27da,22.0.1+0c6914dbf6,22.0.1+1220d50b50,22.0.1+12fd109e95,22.0.1+1a1dd69893,22.0.1+1c910dc348,22.0.1+1ef34551f5,22.0.1+30170c3d08,22.0.1+39153823fd,22.0.1+611137eacc,22.0.1+771eb1e3e8,22.0.1+94e66cc9ed,22.0.1+9a075d06e2,22.0.1+a5ff6e246e,22.0.1+a7db719c1a,22.0.1+ba0d97e778,22.0.1+bfe1ee9056,22.0.1+c4e1e0358a,22.0.1+cc34b8281e,22.0.1+d640e2c0fa,22.0.1+d72a2e677a,22.0.1+d9a6b571bd,22.0.1+e485e9761b,22.0.1+ebe8d3385e
LSST Data Management Base Package
Public Member Functions | Public Attributes | List of all members
lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper Class Reference
Inheritance diagram for lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper:
lsst.pipe.base.graph._loadHelpers.FileLoadHelper lsst.pipe.base.graph._loadHelpers.OpenFileHandleHelper lsst.pipe.base.graph._loadHelpers.S3LoadHelper

Public Member Functions

def __init__ (self, Union[ButlerURI, io.IO[bytes]] uriObject)
 
QuantumGraph load (self, Optional[Iterable[int]] nodes=None, Optional[str] graphID=None)
 
def close (self)
 

Public Attributes

 uriObject
 
 headerSize
 
 save_version
 
 taskDefMap
 
 map
 
 buffer
 

Detailed Description

Default load helper for `QuantumGraph` save files

This class, and its subclasses, are used to unpack a quantum graph save
file. This file is a binary representation of the graph in a format that
allows individual nodes to be loaded without needing to load the entire
file.

This default implementation has the interface to load select nodes
from disk, but actually always loads the entire save file and simply
returns what nodes (or all) are requested. This is intended to serve for
all cases where there is a read method on the input parameter, but it is
unknown how to read select bytes of the stream. It is the responsibility of
sub classes to implement the method responsible for loading individual
bytes from the stream.

Parameters
----------
uriObject : `~lsst.daf.butler.ButlerURI` or `io.IO` of bytes
    This is the object that will be used to retrieve the raw bytes of the
    save.

Raises
------
ValueError
    Raised if the specified file contains the wrong file signature and is
    not a `QuantumGraph` save

Definition at line 79 of file _loadHelpers.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.__init__ (   self,
Union[ButlerURI, io.IO[bytes]]  uriObject 
)

Definition at line 107 of file _loadHelpers.py.

107  def __init__(self, uriObject: Union[ButlerURI, io.IO[bytes]]):
108  self.uriObject = uriObject
109 
110  preambleSize, taskDefSize, nodeSize = self._readSizes()
111 
112  # Recode the total header size
113  self.headerSize = preambleSize + taskDefSize + nodeSize
114 
115  self._readByteMappings(preambleSize, self.headerSize, taskDefSize)
116 

Member Function Documentation

◆ close()

def lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.close (   self)
Cleans up an instance if needed. Base class does nothing

Reimplemented in lsst.pipe.base.graph._loadHelpers.FileLoadHelper.

Definition at line 272 of file _loadHelpers.py.

272  def close(self):
273  """Cleans up an instance if needed. Base class does nothing
274  """
275  pass
276 
277 
278 @register_helper(ButlerS3URI)
def register_helper(Union[Type[ButlerURI], Type[io.IO[bytes]]] URICLass)
Definition: _loadHelpers.py:56

◆ load()

QuantumGraph lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.load (   self,
Optional[Iterable[int]]   nodes = None,
Optional[str]   graphID = None 
)
Loads in the specified nodes from the graph

Load in the `QuantumGraph` containing only the nodes specified in the
``nodes`` parameter from the graph specified at object creation. If
``nodes`` is None (the default) the whole graph is loaded.

Parameters
----------
nodes : `Iterable` of `int` or `None`
    The nodes to load from the graph, loads all if value is None
    (the default)
graphID : `str` or `None`
    If specified this ID is verified against the loaded graph prior to
    loading any Nodes. This defaults to None in which case no
    validation is done.

Returns
-------
graph : `QuantumGraph`
    The loaded `QuantumGraph` object

Raises
------
ValueError
    Raised if one or more of the nodes requested is not in the
    `QuantumGraph` or if graphID parameter does not match the graph
    being loaded.

Definition at line 163 of file _loadHelpers.py.

163  def load(self, nodes: Optional[Iterable[int]] = None, graphID: Optional[str] = None) -> QuantumGraph:
164  """Loads in the specified nodes from the graph
165 
166  Load in the `QuantumGraph` containing only the nodes specified in the
167  ``nodes`` parameter from the graph specified at object creation. If
168  ``nodes`` is None (the default) the whole graph is loaded.
169 
170  Parameters
171  ----------
172  nodes : `Iterable` of `int` or `None`
173  The nodes to load from the graph, loads all if value is None
174  (the default)
175  graphID : `str` or `None`
176  If specified this ID is verified against the loaded graph prior to
177  loading any Nodes. This defaults to None in which case no
178  validation is done.
179 
180  Returns
181  -------
182  graph : `QuantumGraph`
183  The loaded `QuantumGraph` object
184 
185  Raises
186  ------
187  ValueError
188  Raised if one or more of the nodes requested is not in the
189  `QuantumGraph` or if graphID parameter does not match the graph
190  being loaded.
191  """
192  # need to import here to avoid cyclic imports
193  from . import QuantumGraph
194  if graphID is not None and self._buildId != graphID:
195  raise ValueError('graphID does not match that of the graph being loaded')
196  # Read in specified nodes, or all the nodes
197  if nodes is None:
198  nodes = list(self.map.keys())
199  # if all nodes are to be read, force the reader from the base class
200  # that will read all they bytes in one go
201  _readBytes = functools.partial(DefaultLoadHelper._readBytes, self)
202  else:
203  # only some bytes are being read using the reader specialized for
204  # this class
205  # create a set to ensure nodes are only loaded once
206  nodes = set(nodes)
207  # verify that all nodes requested are in the graph
208  remainder = nodes - self.map.keys()
209  if remainder:
210  raise ValueError("Nodes {remainder} were requested, but could not be found in the input "
211  "graph")
212  _readBytes = self._readBytes
213  # create a container for loaded data
214  quanta: DefaultDict[TaskDef, Set[Quantum]] = defaultdict(set)
215  quantumToNodeId: Dict[Quantum, NodeId] = {}
216  loadedTaskDef = {}
217  # loop over the nodes specified above
218  for node in nodes:
219  # Get the bytes to read from the map
220  start, stop = self.map[node]
221  start += self.headerSize
222  stop += self.headerSize
223 
224  # read the specified bytes, will be overloaded by subclasses
225  # bytes are compressed, so decompress them
226  dump = lzma.decompress(_readBytes(start, stop))
227 
228  # reconstruct node
229  qNode = pickle.loads(dump)
230 
231  # read the saved node, name. If it has been loaded, attach it, if
232  # not read in the taskDef first, and then load it
233  nodeTask = qNode.taskDef
234  if nodeTask not in loadedTaskDef:
235  # Get the byte ranges corresponding to this taskDef
236  start, stop = self.taskDefMap[nodeTask]
237  start += self.headerSize
238  stop += self.headerSize
239 
240  # load the taskDef, this method call will be overloaded by
241  # subclasses.
242  # bytes are compressed, so decompress them
243  taskDef = pickle.loads(lzma.decompress(_readBytes(start, stop)))
244  loadedTaskDef[nodeTask] = taskDef
245  # Explicitly overload the "frozen-ness" of nodes to attach the
246  # taskDef back into the un-persisted node
247  object.__setattr__(qNode, 'taskDef', loadedTaskDef[nodeTask])
248  quanta[qNode.taskDef].add(qNode.quantum)
249 
250  # record the node for later processing
251  quantumToNodeId[qNode.quantum] = qNode.nodeId
252 
253  # construct an empty new QuantumGraph object, and run the associated
254  # creation method with the un-persisted data
255  qGraph = object.__new__(QuantumGraph)
256  qGraph._buildGraphs(quanta, _quantumToNodeId=quantumToNodeId, _buildId=self._buildId)
257  return qGraph
258 
daf::base::PropertyList * list
Definition: fits.cc:913
daf::base::PropertySet * set
Definition: fits.cc:912

Member Data Documentation

◆ buffer

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.buffer

Definition at line 269 of file _loadHelpers.py.

◆ headerSize

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.headerSize

Definition at line 113 of file _loadHelpers.py.

◆ map

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.map

Definition at line 161 of file _loadHelpers.py.

◆ save_version

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.save_version

Definition at line 142 of file _loadHelpers.py.

◆ taskDefMap

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.taskDefMap

Definition at line 154 of file _loadHelpers.py.

◆ uriObject

lsst.pipe.base.graph._loadHelpers.DefaultLoadHelper.uriObject

Definition at line 108 of file _loadHelpers.py.


The documentation for this class was generated from the following file: