Custom types

See the related page in the Getting Started guide.

SumatraTask provides a few custom types to deal with the certain special cases relevant for tasks (such as serializing the output of a task with multiple outputs).

The scityping package provides serializable versions of many common types used in scientific applications, such as NumPy arrays.

class smttask.typing.SeparateOutputs

This class returns values with two properties:

  • They verify isinstance(v, tuple) and are equivalent to tuple.

  • They have a type distinct from tuple, so that smttask can recognize and treat them differently from a tuple.

smttask.typing.normalize_input_path(path)

Dereference links: links may change, so in the db record we want to save paths to actual files Typically these are files in the output datastore, but we save paths relative to the input datastore.root, because that’s the root we use to execute the task.

smttask.typing.separate_outputs(item_type: Type[T], get_names: Callable[[...], List[str]])

In terms of typing, equivalent to Tuple[T,…], but indicates to smttask to save each element separately. This was conceived for two use cases:

  1. When the number of outputs is dependent on the input variables.

  2. When some or all of the outputs may be very large. For example, we may have a Task which allows different recorder objects to track quantities during a simulation.

Parameters:

get_names

Function used to determine the names under which name each value is saved. Takes any number of arguments, but their names must match the name of a task input. Returns a list of strings. E.g., if the associated Task defines inputs ‘freq’ and ‘phase’, then the get_names function may have any one of these signatures:

  • get_names () -> List[str]

  • get_names (freq) -> List[str]

  • get_names (phase) -> List[str]

  • get_names (freq, phase) -> List[str]

This allows the output names to depend on any of the Task parameters. CAVEAT: Currently Task values are not supported, so in the example above, if freq may be provided as a Task instance, it should not be used in get_names.