Retargeting subtasks of tasks

Subtasks of tasks are dynamically retargetable, meaning that you can configure which task class is run by a parent class. Subtask retargeting is a special case of task configuration.

A common use of retargeting is to change a default subtask for a camera-specific one. For example:

How you retarget a subtask and override its config parameters depends on whether the task is specified as an lsst.pex.config.ConfigurableField (the most common case) or as an lsst.pex.config.RegistryField. Both scenarios are described on this page.

How to retarget a subtask configured as a ConfigurableField with a configuration file

To retarget a subtask specified as an lsst.pex.config.ConfigurableField, you must use a configuration file. Inside a configuration file, retargeting is done in two steps:

  1. Import the Task class you intend to use.

  2. Assign that class to to the subtask configuration using the retarget method.

For example, to retarget the subtask named configurableSubtask with a class FooTask, this configuration file should contain:

from ... import FooTask


Once a subtask is retargeted, you can configure it as normal by setting attributes to configuration parameters. For example:

config.configurableSubtask.subtaskParam1 = newValue


When you retarget a task specified by an lsst.pex.config.ConfigurableField you lose all configuration overrides for both the old and new task. This limitation is not shared by lsst.pex.config.RegistryField.

How to retarget a subtask configured as a RegistryField with a configuration file

To retarget a subtask specified as an lsst.pex.config.RegistryField, set the field’s name attribute in a configuration file. Here is an example that assumes a task FooTask is defined in module .../ and registered using name foo:

import .../ = "foo"

Besides retargeting the registry subtask, there are two ways to configure parameters for tasks in a registry:

These configuration methods are described next.

Configure the active subtask configured as a RegistryField

You may configure the retargeted subtask in a configuration file by setting the subtask configuration’s active attribute. For example: = newValue

These configurations can also be specified directly on the command line if using pipetask as a --config argument. For example:


Configure any subtask in a registry

Alternatively, you can then configure parameters for any subtask in the registry using key-value access. For example:

config.registrySubtask["foo"].subtaskParam1 = newValue