Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-20692: update to new PipelineTask APIs #51

Merged
merged 4 commits into from
Aug 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/lsst.verify/tasks/lsst.verify.gen2tasks.MetricTask.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Subclassing
``MetricTask`` is primarily customized using the `~MetricTask.run` or `~MetricTask.adaptArgsAndRun` methods.
Each subclass must also implement the `~MetricTask.getOutputMetricName` method.

The task config should use `lsst.pipe.base.InputDatasetConfig` to identify input datasets as if it were a `~lsst.pipe.base.PipelineTask`.
Only the ``name`` field is used in a Gen 2 context, but use of `~lsst.pipe.base.InputDatasetConfig` is expected to simplify the transition to Gen 3.
The task config should use `lsst.pipe.base.PipelineTaskConnections` to identify input datasets as if it were a `~lsst.pipe.base.PipelineTask`.
Only the ``name`` field is used in a Gen 2 context, but use of `~lsst.pipe.base.PipelineTaskConnections` is expected to simplify the transition to Gen 3.

.. _lsst.verify.gen2tasks.MetricTask-indepth-errors:

Expand Down
3 changes: 2 additions & 1 deletion python/lsst/verify/gen2tasks/metricRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ class MetricRegistry:
``MetricRegistry.registry`` should be agnostic to such changes.
"""

registry = Registry(MetricTask.ConfigClass)
# Don't use MetricTask.ConfigClass, to accommodate MultiConfig
registry = Registry(Config)
"""A unique registry of ``MetricTasks`` or collections of ``MetricTasks``
(`lsst.pex.config.Registry`).
"""
17 changes: 7 additions & 10 deletions python/lsst/verify/gen2tasks/metricTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import abc

import lsst.pex.config
import lsst.pipe.base as pipeBase


Expand Down Expand Up @@ -58,7 +57,7 @@ class MetricTask(pipeBase.Task, metaclass=abc.ABCMeta):

# TODO: create a specialized MetricTaskConfig once metrics have
# Butler datasets
ConfigClass = lsst.pex.config.Config
ConfigClass = pipeBase.PipelineTaskConfig

def __init__(self, **kwargs):
super().__init__(**kwargs)
Expand Down Expand Up @@ -171,15 +170,13 @@ def getInputDatasetTypes(cls, config):

Notes
-----
The default implementation searches ``config`` for
`~lsst.pipe.base.InputDatasetConfig` fields, much like
`lsst.pipe.base.PipelineTask.getInputDatasetTypes` does.
The default implementation extracts a
`~lsst.pipe.base.PipelineTaskConnections` object from ``config``.
"""
datasets = {}
for key, value in config.items():
if isinstance(value, lsst.pipe.base.InputDatasetConfig):
datasets[key] = value.name
return datasets
# Get connections from config for backward-compatibility
connections = config.connections.ConnectionsClass(config=config)
return {name: getattr(connections, name).name
for name in connections.inputs}

@classmethod
@abc.abstractmethod
Expand Down
27 changes: 18 additions & 9 deletions python/lsst/verify/tasks/metadataMetricTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,27 @@

import abc

from lsst.pipe.base import Struct, InputDatasetField
from lsst.pipe.base import Struct, PipelineTaskConnections, connectionTypes
from lsst.verify.gen2tasks import MetricTask
from lsst.verify.tasks import MetricComputationError


class MetadataMetricConfig(MetricTask.ConfigClass):
class MetadataMetricConnections(
PipelineTaskConnections,
dimensions={"Instrument", "Exposure", "Detector"},
defaultTemplates={"taskName": ""}):
metadata = connectionTypes.Input(
name="{taskName}_metadata",
doc="The target top-level task's metadata. The name must be set to "
"the metadata's butler type, such as 'processCcd_metadata'.",
storageClass="PropertySet",
dimensions={"Instrument", "Exposure", "Detector"},
multiple=True,
)


class MetadataMetricConfig(MetricTask.ConfigClass,
pipelineConnections=MetadataMetricConnections):
"""A base class for metadata metric task configs.

Notes
Expand All @@ -37,13 +52,7 @@ class MetadataMetricConfig(MetricTask.ConfigClass):
this class as-is. Classes representing metrics of a different granularity
should use `setDefaults` to override ``metadata.dimensions``.
"""
metadata = InputDatasetField(
doc="The target top-level task's metadata. The name must be set to "
"the metadata's butler type, such as 'processCcd_metadata'.",
nameTemplate="{taskName}_metadata",
storageClass="PropertySet",
dimensions={"Instrument", "Exposure", "Detector"},
)
pass


class MetadataMetricTask(MetricTask):
Expand Down
22 changes: 15 additions & 7 deletions python/lsst/verify/tasks/ppdbMetricTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

from lsst.pex.config import Config, ConfigurableField, ConfigurableInstance, \
ConfigDictField, ConfigChoiceField, FieldValidationError
from lsst.pipe.base import Task, Struct, InputDatasetField
from lsst.pipe.base import Task, Struct, PipelineTaskConnections, \
connectionTypes
from lsst.dax.ppdb import Ppdb, PpdbConfig

from lsst.verify.gen2tasks import MetricTask
Expand Down Expand Up @@ -157,19 +158,26 @@ def run(self, config):
return Struct(ppdb=self._getPpdb(config))


class PpdbMetricConfig(MetricTask.ConfigClass):
"""A base class for PPDB metric task configs.
"""
dbInfo = InputDatasetField(
class PpdbMetricConnections(
PipelineTaskConnections,
dimensions=set(),
defaultTemplates={"taskName": ""}):
dbInfo = connectionTypes.Input(
name="{taskName}_config",
doc="The dataset from which a PPDB instance can be constructed by "
"`dbLoader`. By default this is assumed to be a top-level "
"config, such as 'processCcd_config'.",
nameTemplate="{taskName}_config",
storageClass="Config",
# One config for entire CmdLineTask run
scalar=True,
multiple=False,
dimensions=set(),
)


class PpdbMetricConfig(MetricTask.ConfigClass,
pipelineConnections=PpdbMetricConnections):
"""A base class for PPDB metric task configs.
"""
dbLoader = ConfigurableField(
target=ConfigPpdbLoader,
doc="Task for loading a database from `dbInfo`. Its run method must "
Expand Down
4 changes: 2 additions & 2 deletions tests/test_commonMetrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def makeTask(cls):
@staticmethod
def _standardConfig():
config = TimingMetricTask.ConfigClass()
config.metadata.name = DummyTask._DefaultName + "_metadata"
config.connections.taskName = DummyTask._DefaultName
config.target = DummyTask._DefaultName + ".run"
config.metric = "verify.DummyTime"
return config
Expand Down Expand Up @@ -166,7 +166,7 @@ def makeTask(cls):
@staticmethod
def _standardConfig():
config = MemoryMetricTask.ConfigClass()
config.metadata.name = DummyTask._DefaultName + "_metadata"
config.connections.taskName = DummyTask._DefaultName
config.target = DummyTask._DefaultName + ".run"
config.metric = "verify.DummyMemory"
return config
Expand Down
27 changes: 19 additions & 8 deletions tests/test_metricsController.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

import lsst.utils.tests
from lsst.pex.config import Config, FieldValidationError
from lsst.pipe.base import Task, Struct
from lsst.pipe.base import \
Task, Struct, PipelineTaskConnections, connectionTypes
from lsst.verify import Job, Name, Measurement
from lsst.verify.tasks import MetricComputationError
from lsst.verify.gen2tasks import \
Expand All @@ -45,7 +46,17 @@ def _extraMetricName2():
return "misc_tasks.RedundantMetric"


class DemoMetricConfig(MetricTask.ConfigClass):
class DemoConnections(
PipelineTaskConnections,
dimensions={}):
inputData = connectionTypes.Input(
name="metadata",
storageClass="PropertySet",
)


class DemoMetricConfig(MetricTask.ConfigClass,
pipelineConnections=DemoConnections):
metric = lsst.pex.config.Field(
dtype=str,
default=_metricName(),
Expand All @@ -64,15 +75,15 @@ class _DemoMetricTask(MetricTask):
ConfigClass = DemoMetricConfig
_DefaultName = "test"

def run(self, inputs):
nData = len(inputs)
def run(self, inputData):
nData = len(inputData)
return Struct(measurement=Measurement(
self.getOutputMetricName(self.config),
self.config.multiplier * nData * u.second))

@classmethod
def getInputDatasetTypes(cls, _config):
return {'inputs': "metadata"}
return {'inputData': "metadata"}

@classmethod
def getOutputMetricName(cls, config):
Expand All @@ -87,15 +98,15 @@ class _RepeatedMetricTask(MetricTask):
ConfigClass = DemoMetricConfig
_DefaultName = "test"

def run(self, inputs):
nData = len(inputs)
def run(self, inputData):
nData = len(inputData)
return Struct(measurement=Measurement(
self.getOutputMetricName(self.config),
self.config.multiplier * nData * u.second))

@classmethod
def getInputDatasetTypes(cls, _config):
return {'inputs': "metadata"}
return {'inputData': "metadata"}

@classmethod
def getOutputMetricName(cls, config):
Expand Down