Skip to content

Commit

Permalink
Address Review comments
Browse files Browse the repository at this point in the history
Address the review comments surrounding comments, documentation, and
typos.
  • Loading branch information
natelust committed Mar 22, 2023
1 parent 34dad40 commit c0d1e5b
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 20 deletions.
42 changes: 41 additions & 1 deletion doc/lsst.pex.config/field-types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Types of configuration fields
.. TODO: improve this page to summarize the purpose of each field, and then have a dedicated section for each field. https://jira.lsstcorp.org/browse/DM-17196
Attributes of the configuration object must be subclasses of `Field`.
A number of these are predefined: `Field`, `RangeField`, `ChoiceField`, `ListField`, `ConfigField`, `ConfigChoiceField`, `RegistryField` and `ConfigurableField`.
A number of these are predefined: `Field`, `RangeField`, `ChoiceField`, `ListField`, `ConfigField`, `ConfigChoiceField`, `RegistryField`, `ConfigurableField`, `ConfigurableActionField`, and `ConfigurableActionStructField`.

Example of `RangeField`:

Expand Down Expand Up @@ -78,3 +78,43 @@ Examples of `ChoiceField` and `ConfigField` and the use of the `Config` object's
if self.doComputeApCorr and not self.doPsf:
raise ValueError("Cannot compute aperture correction "
"without doing PSF determination.")
Examples of `ConfigurableActionField` and `ConfigurableActionStructField` making use of `ConfigurableAction`\ s in a `Config` object.

.. code-block:: python
class ExampleAction(pexConfig.configurableActions.ConfigurableAction):
"""A ConfigurableAction that performs a simple calculation"""
numerator = pexConfig.Field[float](doc="Numerator for division operation")
divisor = pexConfig.Field[float](doc="Divisor for division operation")
def __call__(self, **kwargs):
return self.numerator / self.divisor
class ExampleConfig(pexConfig.Config):
"""An example Config class which contains multiple `ConfigurableAction`\ s."""
divideAction = pexConfig.configurableActions.ConfigurableActionField(
doc="A field which points to a single action"
default=ExampleAction
)
multipleDivisionActions = pexConfig.configurableActions.ConfigurableActionStructField(
doc="A field which acts as a struct, referring to multiple ConfigurableActions"
)
def setDefaults(self):
"""Example of setting multiple default configurations with `ConfigurableAction`\ s.
"""
self.divideAction.numerator = 1
self.divideAction.divisor = 2
self.multipleDivisionActions.subDivide1 = ExampleAction()
self.multipleDivisionActions.subDivide1.numerator = 5
self.multipleDivisionActions.subDivide1.divisor = 10
self.multipleDivisionActions.subDivide2 = ExampleAction()
self.multipleDivisionActions.subDivide2.numerator = 7
self.multipleDivisionActions.subDivide2.divisor = 8
12 changes: 12 additions & 0 deletions doc/lsst.pex.config/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,15 @@ Alternatively, if you wish to locate another configuration file using LSST infra
from lsst.utils import getPackageDir
config.load(os.path.join(getPackageDir("product_x"), "config", "otherconfig.py"))
Specialized Config subclasses
=============================

There exists a subclass of `Config` which is designed to be configurable like a standard config, but have a runtime call interface.
These specialized subclasses are named `~lsst.pex.config.configurableActions.ConfigurableAction`\ s, or actions for short.
These actions are not intended to replace other runtime components, but compliment them.
They provide configuration time mechanics to a simple runtime function.
This interface allows for both configuration of an action as well as making which action to run configurable.
These configurations are serialized out in a standard way, and thus allow complete functional states to be completely restored.
The selection (thus configuration) of which `~lsst.pex.config.configurableActions.ConfigurableAction`\ s to run is made possible through the use of special `Field`\ s named `~lsst.pex.config.configurableActions.ConfigurableActionField` and `~lsst.pex.config.configurableActions.ConfigurableActionStructField`.
See :doc:`field-types` for more details and examples of both `ConfigurableAction`\ s and the corresponding fields.
2 changes: 1 addition & 1 deletion python/lsst/pex/config/configurableActions/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down Expand Up @@ -34,7 +34,7 @@ class ConfigurableAction(Config):
`lsst.pex.config.Config` class to include a `__call__` method.
This interface is designed to create an action that can be used at
runtime with state that is determined during the configuration stage. A
runtime with a state that is determined during the configuration stage. A
single action thus may be assigned multiple times, each with different
configurations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down Expand Up @@ -33,12 +33,12 @@

class ConfigurableActionField(ConfigField[ActionTypeVar]):
"""`ConfigurableActionField` is a subclass of `~lsst.pex.config.Field` that
allows a single `ConfigurableAction` (or a subclass of thus) to be
assigned to it. The `ConfigurableAction` is then accessed through this
field for further configuration.
allows a single `ConfigurableAction` (or a subclass) to be assigned to it.
The `ConfigurableAction` is then accessed through this field for further
configuration.
Any configuration that is done prior to reasignment to a new
`ConfigurableAction` is forgotten.
Any configuration of this field that is done prior to having a new
`ConfigurableAction` assigned to it is forgotten.
"""

# These attributes are dynamically assigned when constructing the base
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down Expand Up @@ -78,7 +78,7 @@ def __get__(self, instance, objtype=None) -> None:


class ConfigurableActionStructRemover:
"""This descriptor exists to abstract the logic of removing an interable
"""This descriptor exists to abstract the logic of removing an iterable
of action names from a ConfigurableActionStruct at one time using
attribute assignment. This is useful in the context of setting
configuration through pipelines or on the command line.
Expand Down Expand Up @@ -120,15 +120,15 @@ class ConfigurableActionStruct(Generic[ActionTypeVar]):
Each action is then available to be individually configured as a normal
`lsst.pex.config.Config` object.
ConfigurableActionStruct supports two special convenance attributes.
ConfigurableActionStruct supports two special convenience attributes.
The first is `update`. You may assign a dict of `ConfigurableActions` or
The first is ``update``. You may assign a dict of `ConfigurableActions` or
a `ConfigurableActionStruct` to this attribute which will update the
`ConfigurableActionStruct` on which the attribute is invoked such that it
will be updated to contain the entries specified by the structure on the
right hand side of the equals sign.
The second convenience attribute is named remove. You may assign an
The second convenience attribute is named ``remove``. You may assign an
iterable of strings which correspond to attribute names on the
`ConfigurableActionStruct`. All of the corresponding attributes will then
be removed. If any attribute does not exist, an `AttributeError` will be
Expand Down Expand Up @@ -246,9 +246,9 @@ class ConfigurableActionStructField(Field[ActionTypeVar]):
`~lsst.pex.config.Config` class in a manner similar to how a
`~lsst.pipe.base.Struct` works.
This class implements a `ConfigurableActionStruct` as an intermediary
object to organize the `ConfigurableActions`. See it's documentation for
futher information.
This class uses a `ConfigurableActionStruct` as an intermediary
object to organize the `ConfigurableActions`. See its documentation for
further information.
"""
# specify StructClass to make this more generic for potential future
# inheritance
Expand Down
2 changes: 1 addition & 1 deletion python/lsst/pex/config/configurableActions/tests.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down
2 changes: 1 addition & 1 deletion tests/test_configurableActions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is part of pipe_tasks.
# This file is part of pex_config.
#
# Developed for the LSST Data Management System.
# This product includes software developed by the LSST Project
Expand Down

0 comments on commit c0d1e5b

Please sign in to comment.