LSSTApplications  19.0.0-10-g920eed2,19.0.0-11-g48a0200+2,19.0.0-18-gfc4e62b+13,19.0.0-2-g3b2f90d+2,19.0.0-2-gd671419+5,19.0.0-20-g5a5a17ab+11,19.0.0-21-g2644856+13,19.0.0-23-g84eeccb+1,19.0.0-24-g878c510+1,19.0.0-25-g6c8df7140,19.0.0-25-gb330496+1,19.0.0-3-g2b32d65+5,19.0.0-3-g8227491+12,19.0.0-3-g9c54d0d+12,19.0.0-3-gca68e65+8,19.0.0-3-gcfc5f51+5,19.0.0-3-ge110943+11,19.0.0-3-ge74d124,19.0.0-3-gfe04aa6+13,19.0.0-30-g9c3fd16+1,19.0.0-4-g06f5963+5,19.0.0-4-g3d16501+13,19.0.0-4-g4a9c019+5,19.0.0-4-g5a8b323,19.0.0-4-g66397f0+1,19.0.0-4-g8278b9b+1,19.0.0-4-g8557e14,19.0.0-4-g8964aba+13,19.0.0-4-ge404a01+12,19.0.0-5-g40f3a5a,19.0.0-5-g4db63b3,19.0.0-5-gfb03ce7+13,19.0.0-6-gbaebbfb+12,19.0.0-61-gec4c6e08+1,19.0.0-7-g039c0b5+11,19.0.0-7-gbea9075+4,19.0.0-7-gc567de5+13,19.0.0-71-g41c0270,19.0.0-9-g2f02add+1,19.0.0-9-g463f923+12,w.2020.22
LSSTDataManagementBasePackage
config.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 config classes for PipelineTask.
23 """
24 __all__ = ["ResourceConfig", "PipelineTaskConfig"]
25 
26 # -------------------------------
27 # Imports of standard modules --
28 # -------------------------------
29 
30 # -----------------------------
31 # Imports for other modules --
32 # -----------------------------
33 import lsst.pex.config as pexConfig
34 from .connections import PipelineTaskConnections
35 
36 # ----------------------------------
37 # Local non-exported definitions --
38 # ----------------------------------
39 
40 # ------------------------
41 # Exported definitions --
42 # ------------------------
43 
44 
45 class PipelineTaskConfigMeta(pexConfig.ConfigMeta):
46  """Metaclass used in the creation of PipelineTaskConfig classes
47 
48  This metaclass ensures a `PipelineTaskConnections` class is specified in
49  the class construction parameters with a parameter name of
50  pipelineConnections. Using the supplied connection class, this metaclass
51  constructs a `lsst.pex.config.Config` instance which can be used to
52  configure the connections class. This config is added to the config class
53  under declaration with the name "connections" used as an identifier. The
54  connections config also has a reference to the connections class used in
55  its construction associated with an atttribute named `ConnectionsClass`.
56  Finally the newly constructed config class (not an instance of it) is
57  assigned to the Config class under construction with the attribute name
58  `ConnectionsConfigClass`.
59  """
60  def __new__(cls, name, bases, dct, **kwargs):
61  if name != "PipelineTaskConfig":
62  # Verify that a connection class was specified and the argument is an instance of
63  # PipelineTaskConfig
64  if 'pipelineConnections' not in kwargs:
65  for base in bases:
66  if hasattr(base, "connections"):
67  kwargs['pipelineConnections'] = base.connections.dtype.ConnectionsClass
68  break
69  if 'pipelineConnections' not in kwargs:
70  raise NameError("PipelineTaskConfig or a base class must be defined with connections class")
71  connectionsClass = kwargs['pipelineConnections']
72  if not issubclass(connectionsClass, PipelineTaskConnections):
73  raise ValueError("Can only assign a PipelineTaskConnections Class to pipelineConnections")
74 
75  # Create all the fields that will be used in the newly created sub config
76  # (under the attribute name "connections")
77  configConnectionsNamespace = {}
78  for fieldName, obj in connectionsClass.allConnections.items():
79  configConnectionsNamespace[fieldName] = pexConfig.Field(dtype=str,
80  doc=f"name for "
81  f"connection {fieldName}",
82  default=obj.name)
83  # If there are default templates also add them as fields to configure the template values
84  if hasattr(connectionsClass, 'defaultTemplates'):
85  docString = "Template parameter used to format corresponding field template parameter"
86  for templateName, default in connectionsClass.defaultTemplates.items():
87  configConnectionsNamespace[templateName] = pexConfig.Field(dtype=str,
88  doc=docString,
89  default=default)
90  # add a reference to the connection class used to create this sub config
91  configConnectionsNamespace['ConnectionsClass'] = connectionsClass
92 
93  # Create a new config class with the fields defined above
94  Connections = type("Connections", (pexConfig.Config,), configConnectionsNamespace)
95  # add it to the Config class that is currently being declared
96  dct['connections'] = pexConfig.ConfigField(dtype=Connections,
97  doc='Configurations describing the'
98  ' connections of the PipelineTask to datatypes')
99  dct['ConnectionsConfigClass'] = Connections
100  dct['ConnectionsClass'] = connectionsClass
101  inst = super().__new__(cls, name, bases, dct)
102  return inst
103 
104  def __init__(self, name, bases, dct, **kwargs):
105  # This overrides the default init to drop the kwargs argument. Python
106  # metaclasses will have this argument set if any kwargs are passes at
107  # class construction time, but should be consumed before calling
108  # __init__ on the type metaclass. This is in accordance with python
109  # documentation on metaclasses
110  super().__init__(name, bases, dct)
111 
112 
113 class PipelineTaskConfig(pexConfig.Config, metaclass=PipelineTaskConfigMeta):
114  """Configuration class for `PipelineTask`
115 
116  This Configuration class functions in largely the same manner as any other
117  derived from `lsst.pex.config.Config`. The only difference is in how it is
118  declared. `PipelineTaskConfig` children need to be declared with a
119  pipelineConnections argument. This argument should specify a child class of
120  `PipelineTaskConnections`. During the declaration of a `PipelineTaskConfig`
121  a config class is created with information from the supplied connections
122  class to allow configuration of the connections class. This dynamically
123  created config class is then attached to the `PipelineTaskConfig` via a
124  `~lsst.pex.config.ConfigField` with the attribute name `connections`.
125  """
126  saveMetadata = pexConfig.Field(
127  dtype=bool, default=True, optional=False,
128  doc="Flag to enable/disable metadata saving for a task, enabled by default.")
129 
130 
131 class ResourceConfig(pexConfig.Config):
132  """Configuration for resource requirements.
133 
134  This configuration class will be used by some activators to estimate
135  resource use by pipeline. Additionally some tasks could use it to adjust
136  their resource use (e.g. reduce the number of threads).
137 
138  For some resources their limit can be estimated by corresponding task,
139  in that case task could set the field value. For many fields defined in
140  this class their associated resource used by a task will depend on the
141  size of the data and is not known in advance. For these resources their
142  value will be configured through overrides based on some external
143  estimates.
144  """
145  minMemoryMB = pexConfig.Field(dtype=int, default=None, optional=True,
146  doc="Minimal memory needed by task, can be None if estimate is unknown.")
147  minNumCores = pexConfig.Field(dtype=int, default=1,
148  doc="Minimal number of cores needed by task.")
lsst.pipe.base.config.ResourceConfig
Definition: config.py:131
lsst.pipe.base.config.PipelineTaskConfig
Definition: config.py:113
lsst.pipe.base.config.PipelineTaskConfigMeta.__new__
def __new__(cls, name, bases, dct, **kwargs)
Definition: config.py:60
type
table::Key< int > type
Definition: Detector.cc:163
lsst.pipe.base.config.PipelineTaskConfigMeta
Definition: config.py:45
lsst.pipe.base.config.PipelineTaskConfigMeta.__init__
def __init__(self, name, bases, dct, **kwargs)
Definition: config.py:104