smttask.base.Task#
- class smttask.base.Task(arg0=None, *, reason=None, **taskinputs)#
Task format: Use RecordedTask or MemoizedTask as base class Note that input types must always be a Union which includes the Task type. This is taken care of by the decorator.
Note
The definition of Inputs and Outputs classes, and of the _run method, is taken care of by the function decorators. In any case we’ve conceived, the decorators are an easier, more concise way of contructing Tasks.
class MyTask(RecordedTask): class Inputs(TaskInput): a: Union[Task,int], b: Union[Task, str, float] class Outputs(TaskOutput): c: str @staticmethod def _run(a, b): c = a*b return str(c)
- Inputs: TaskInput (subclass of pydantic.BaseModel)
Dictionary of varname: type pairs. Types can be wrapped as a tuple. Inputs will (should?) be validated against these types. Certain types (like DataFile) are treated differently. TODO: document which types and how.
- outputs: TaskOutput (subclass of pydantic.BaseModel)
Dictionary of varname: format. The type is passed on to io.save() and io.load() to determine the data format. format may be either a type or format name registered in iotools.defined_formats or iotools._format_types. (See the smttask.iotools docs for more information.) If you don’t need to specify the output types, can also be a list. Not however that the order is important, so an unordered mapping like a set will lead to errors.
- _run:
Method signature must match the parameters names defined by Inputs. Since a task should be stateless, _run() should not depend on self and therefore can be defined as a staticmethod.
- __init__(arg0=None, *, reason=None, **taskinputs)#
- Parameters:
arg0 (ParameterSet-like) – ParameterSet, or something which can be cast to a ParameterSet (like a dict or filename). The result will be parsed for task arguments defined in self.Inputs.
reason (str) – Arbitrary string included in the Sumatra record for the run. Serves the same purpose as a version control commit message, and simarly essential.
**taskinputs – Task parameters can also be specified as keyword arguments, and will override those in :param:arg0.
Methods
__init__([arg0, reason])bind(**kwargs)Bind task parameters to given values.
clear()If the result of a previous run was cached, deallocate it.
describe([indent, type_join_str, ...])A more human-friendly representation of the Task parameters.
draw(*args, **kwargs)Draw the dependency graph.
from_desc(desc[, on_fail])Instantiate a class from the description returned by 'desc'.
get_desc(taskinputs[, reason])get_output([name])Return the value of the output associated with name name; if the Task has only one unnamed output, specifying the name is not necessary.
load_inputs()Return a copy of self.taskinputs, with all lazy inputs resolved:
parse_result(result)Parse the task result as an object of type cls.Outputs.
partial(**kwargs)Bind task parameters to given values.
save(path[, allow_overwrite])Save a task description.
schematic()Display an ascii-art schematic of the task inputs and outputs.
taskname()validate(value)Attributes
cachedescdigestgraphReturn a dependency graph.
has_runReturns True if a cached result (either in memory or on disk) exists and would be used on a call to run().
hashed_digestinput_filesinrootRoot of the input datastore.
loggernameorig_taskinputsoutputpathsPermanent paths to which task results are saved.
outrootRoot of the output datastore.
relative_outputpathsresultpathsPaths from which task results are retrieved.
saved_to_datastoreReturn True if the outputs are saved to the _output_ data store.
saved_to_input_datastoreReturn True if links matching the outputs exist the _input_ data store.
taskinputsunhashed_digests