Deserializing Tasks

An instance of a concrete implementation of TaskBase can be loaded from a directory. This process deserializes a task by reading its inputs, outputs, and metadata from files. The behaviour is defined in the PathLoadable interface, which implementations of TaskBase must adhere to by defining a from_directory() method. Implementations of this function can assume that the source directory argument will point to a directory containing an inputs JSON and a metadata file.

from pathlib import Path
from autojob.tasks.task import Task

task = Task.from_directory(Path(...))

An important function for Task instances is Task.load_magic() which can change the type of task returned depending on the task_class (set in Task.task_metadata). This function can be called directly or it can be activated by setting magic_mode=True when calling Task.from_directory().

Note

In order for this feature to work with custom TaskBase implementations, you must register your task.

Under the hood, task outputs are loaded by harvesters. Harvesters are callables that receive a task directory as an argument and return a dictionary of results as an output. autojob defines several harvesters to load calculator-specific results, but users can also define custom harvesters to retrieve the results of analyses.

See also

For creating tasks within the workflow infrastructure, opt for the initialize_task() function.

harvest(): harvest multiple tasks from directories

harvesters: autojob implementations of HarvesterBase

How to Write a Harvester Plugin (WIP)