LSST Applications  21.0.0+3c14b91618,21.0.0+9f51b1e3f7,21.0.0-1-ga51b5d4+6691386486,21.0.0-10-g2408eff+49d24385eb,21.0.0-10-g560fb7b+6deed7dcb5,21.0.0-10-gcf60f90+8a335ee4d8,21.0.0-15-g490e301a+3275d29b7b,21.0.0-2-g103fe59+8d3bd148b2,21.0.0-2-g1367e85+7f080822af,21.0.0-2-g45278ab+9f51b1e3f7,21.0.0-2-g5242d73+7f080822af,21.0.0-2-g7f82c8f+0446281eca,21.0.0-2-g8f08a60+e6fd6d9ff9,21.0.0-2-ga326454+0446281eca,21.0.0-2-gde069b7+66c51b65da,21.0.0-2-gecfae73+2991dc08df,21.0.0-2-gfc62afb+7f080822af,21.0.0-20-g09baf175d+b753e4a737,21.0.0-3-g357aad2+29041d4ddb,21.0.0-3-g4be5c26+7f080822af,21.0.0-3-g65f322c+910dc3add9,21.0.0-3-g7d9da8d+3c14b91618,21.0.0-3-gaa929c8+6deed7dcb5,21.0.0-3-ge02ed75+f91014d647,21.0.0-4-g3af6bfd+4bd7f27a2e,21.0.0-4-g591bb35+f91014d647,21.0.0-4-g88306b8+fb98652b4f,21.0.0-4-gccdca77+86bf7a300d,21.0.0-4-ge8a399c+950ca2ef13,21.0.0-45-g0dcdce56+90354a0300,21.0.0-5-g073e055+57e5e98977,21.0.0-6-g2d4f3f3+9f51b1e3f7,21.0.0-6-g4e60332+f91014d647,21.0.0-6-g8356267+ce55d80eb2,21.0.0-7-g6531d7b+c3c1e9b0a0,21.0.0-7-g98eecf7+3609eddee2,21.0.0-8-ga5967ee+5685175956,master-gac4afde19b+f91014d647,w.2021.09
LSST Data Management Base Package
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
63  # an instance of 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
76  # config (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
84  # configure the template values
85  if hasattr(connectionsClass, 'defaultTemplates'):
86  docString = "Template parameter used to format corresponding field template parameter"
87  for templateName, default in connectionsClass.defaultTemplates.items():
88  configConnectionsNamespace[templateName] = pexConfig.Field(dtype=str,
89  doc=docString,
90  default=default)
91  # add a reference to the connection class used to create this sub
92  # config
93  configConnectionsNamespace['ConnectionsClass'] = connectionsClass
94 
95  # Create a new config class with the fields defined above
96  Connections = type("Connections", (pexConfig.Config,), configConnectionsNamespace)
97  # add it to the Config class that is currently being declared
98  dct['connections'] = pexConfig.ConfigField(dtype=Connections,
99  doc='Configurations describing the'
100  ' connections of the PipelineTask to datatypes')
101  dct['ConnectionsConfigClass'] = Connections
102  dct['ConnectionsClass'] = connectionsClass
103  inst = super().__new__(cls, name, bases, dct)
104  return inst
105 
106  def __init__(self, name, bases, dct, **kwargs):
107  # This overrides the default init to drop the kwargs argument. Python
108  # metaclasses will have this argument set if any kwargs are passes at
109  # class construction time, but should be consumed before calling
110  # __init__ on the type metaclass. This is in accordance with python
111  # documentation on metaclasses
112  super().__init__(name, bases, dct)
113 
114 
115 class PipelineTaskConfig(pexConfig.Config, metaclass=PipelineTaskConfigMeta):
116  """Configuration class for `PipelineTask`
117 
118  This Configuration class functions in largely the same manner as any other
119  derived from `lsst.pex.config.Config`. The only difference is in how it is
120  declared. `PipelineTaskConfig` children need to be declared with a
121  pipelineConnections argument. This argument should specify a child class of
122  `PipelineTaskConnections`. During the declaration of a `PipelineTaskConfig`
123  a config class is created with information from the supplied connections
124  class to allow configuration of the connections class. This dynamically
125  created config class is then attached to the `PipelineTaskConfig` via a
126  `~lsst.pex.config.ConfigField` with the attribute name `connections`.
127  """
128  saveMetadata = pexConfig.Field(
129  dtype=bool, default=True, optional=False,
130  doc="Flag to enable/disable metadata saving for a task, enabled by default.")
131 
132 
133 class ResourceConfig(pexConfig.Config):
134  """Configuration for resource requirements.
135 
136  This configuration class will be used by some activators to estimate
137  resource use by pipeline. Additionally some tasks could use it to adjust
138  their resource use (e.g. reduce the number of threads).
139 
140  For some resources their limit can be estimated by corresponding task,
141  in that case task could set the field value. For many fields defined in
142  this class their associated resource used by a task will depend on the
143  size of the data and is not known in advance. For these resources their
144  value will be configured through overrides based on some external
145  estimates.
146  """
147  minMemoryMB = pexConfig.Field(dtype=int, default=None, optional=True,
148  doc="Minimal memory needed by task, can be None if estimate is unknown.")
149  minNumCores = pexConfig.Field(dtype=int, default=1,
150  doc="Minimal number of cores needed by task.")
def __init__(self, name, bases, dct, **kwargs)
Definition: config.py:106
def __new__(cls, name, bases, dct, **kwargs)
Definition: config.py:60
table::Key< int > type
Definition: Detector.cc:163