22 """Module defining config classes for PipelineTask.
24 __all__ = [
"ResourceConfig",
"PipelineTaskConfig"]
33 import lsst.pex.config
as pexConfig
34 from .connections
import PipelineTaskConnections
46 """Metaclass used in the creation of PipelineTaskConfig classes
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`.
60 def __new__(cls, name, bases, dct, **kwargs):
61 if name !=
"PipelineTaskConfig":
64 if 'pipelineConnections' not in kwargs:
66 if hasattr(base,
"connections"):
67 kwargs[
'pipelineConnections'] = base.connections.dtype.ConnectionsClass
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")
77 configConnectionsNamespace = {}
78 for fieldName, obj
in connectionsClass.allConnections.items():
79 configConnectionsNamespace[fieldName] = pexConfig.Field(dtype=str,
81 f
"connection {fieldName}",
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,
91 configConnectionsNamespace[
'ConnectionsClass'] = connectionsClass
94 Connections = type(
"Connections", (pexConfig.Config,), configConnectionsNamespace)
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)
114 """Configuration class for `PipelineTask`
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`.
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.")
132 """Configuration for resource requirements.
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).
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
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.")