22 """Module defining config classes for PipelineTask.
24 __all__ = [
"ResourceConfig",
"PipelineTaskConfig"]
29 from numbers
import Number
35 from .connections
import PipelineTaskConnections
47 """This Field is specialized for use with connection templates.
48 Specifically it treats strings or numbers as valid input, as occasionally
49 numbers are used as a cycle counter in templates.
51 The reason for the specialized field, is that when numbers are involved
52 with the config override system through pipelines or from the command line,
53 sometimes the quoting to get appropriate values as strings gets
54 complicated. This will simplify the process greatly.
56 def _validateValue(self, value):
60 if not (isinstance(value, str)
or isinstance(value, Number)):
61 raise TypeError(f
"Value {value} is of incorrect type {pexConfig.config._typeStr(value)}."
62 f
" Expected type str or a number")
63 if self.check
is not None and not self.check(value):
64 ValueError(
"Value {value} is not a valid value")
66 def __set__(self, instance, value, at=None, label='assignment'):
71 super().
__set__(instance, value, at, label)
75 """Metaclass used in the creation of PipelineTaskConfig classes
77 This metaclass ensures a `PipelineTaskConnections` class is specified in
78 the class construction parameters with a parameter name of
79 pipelineConnections. Using the supplied connection class, this metaclass
80 constructs a `lsst.pex.config.Config` instance which can be used to
81 configure the connections class. This config is added to the config class
82 under declaration with the name "connections" used as an identifier. The
83 connections config also has a reference to the connections class used in
84 its construction associated with an atttribute named `ConnectionsClass`.
85 Finally the newly constructed config class (not an instance of it) is
86 assigned to the Config class under construction with the attribute name
87 `ConnectionsConfigClass`.
89 def __new__(cls, name, bases, dct, **kwargs):
90 if name !=
"PipelineTaskConfig":
93 if 'pipelineConnections' not in kwargs:
95 if hasattr(base,
"connections"):
96 kwargs[
'pipelineConnections'] = base.connections.dtype.ConnectionsClass
98 if 'pipelineConnections' not in kwargs:
99 raise NameError(
"PipelineTaskConfig or a base class must be defined with connections class")
100 connectionsClass = kwargs[
'pipelineConnections']
101 if not issubclass(connectionsClass, PipelineTaskConnections):
102 raise ValueError(
"Can only assign a PipelineTaskConnections Class to pipelineConnections")
106 configConnectionsNamespace = {}
107 for fieldName, obj
in connectionsClass.allConnections.items():
108 configConnectionsNamespace[fieldName] = pexConfig.Field(dtype=str,
110 f
"connection {fieldName}",
114 if hasattr(connectionsClass,
'defaultTemplates'):
115 docString =
"Template parameter used to format corresponding field template parameter"
116 for templateName, default
in connectionsClass.defaultTemplates.items():
117 configConnectionsNamespace[templateName] =
TemplateField(dtype=str,
122 configConnectionsNamespace[
'ConnectionsClass'] = connectionsClass
125 Connections =
type(
"Connections", (pexConfig.Config,), configConnectionsNamespace)
127 dct[
'connections'] = pexConfig.ConfigField(dtype=Connections,
128 doc=
'Configurations describing the'
129 ' connections of the PipelineTask to datatypes')
130 dct[
'ConnectionsConfigClass'] = Connections
131 dct[
'ConnectionsClass'] = connectionsClass
132 inst = super().
__new__(cls, name, bases, dct)
145 """Configuration class for `PipelineTask`
147 This Configuration class functions in largely the same manner as any other
148 derived from `lsst.pex.config.Config`. The only difference is in how it is
149 declared. `PipelineTaskConfig` children need to be declared with a
150 pipelineConnections argument. This argument should specify a child class of
151 `PipelineTaskConnections`. During the declaration of a `PipelineTaskConfig`
152 a config class is created with information from the supplied connections
153 class to allow configuration of the connections class. This dynamically
154 created config class is then attached to the `PipelineTaskConfig` via a
155 `~lsst.pex.config.ConfigField` with the attribute name `connections`.
157 saveMetadata = pexConfig.Field(
158 dtype=bool, default=
True, optional=
False,
159 doc=
"Flag to enable/disable metadata saving for a task, enabled by default.")
163 """Configuration for resource requirements.
165 This configuration class will be used by some activators to estimate
166 resource use by pipeline. Additionally some tasks could use it to adjust
167 their resource use (e.g. reduce the number of threads).
169 For some resources their limit can be estimated by corresponding task,
170 in that case task could set the field value. For many fields defined in
171 this class their associated resource used by a task will depend on the
172 size of the data and is not known in advance. For these resources their
173 value will be configured through overrides based on some external
176 minMemoryMB = pexConfig.Field(dtype=int, default=
None, optional=
True,
177 doc=
"Minimal memory needed by task, can be None if estimate is unknown.")
178 minNumCores = pexConfig.Field(dtype=int, default=1,
179 doc=
"Minimal number of cores needed by task.")
def __set__(self, instance, value, at=None, label='assignment')
def _validateValue(self, value)