cachable_task

this module contains the cachable task implementation

class mosaic_orchestrator.cachable_task.CachableTask(inputs: Optional[Dict[str, object]] = None)[source]

Results of CachableTasks are cached persistently and reused when all inputs match.

The return value of the run() method is considered to be the result of a task. The complete state of a task, including all member variables, is considered when looking up previous results. In case of a cache-hit the run() method is not executed and the cached result is returned instead. To implement custom invalidation logic (e.g. when the result of a cache is representing a file that is susceptible to change between executions) the invalidate() method can be overridden. When fine-grained control of the state representation of a class is needed the Hashable protocol can be implemented. It is used whenever it is present in a member variable of a task. To ignore a input for caching set its transient flag to True.

calc_hash(inputs: Optional, *args, **kwargs) str[source]

Calculates a hash for this task based on the runtime arguments.

Overriding this method is discouraged as it can have unexpected results when not done properly.

check_is_cache_valid(result: ResultContainer) bool[source]

This method is called when evaluating cached results.

Overwrite this method to implement custom result invalidation.

Parameters:

result – the cached result object.

Returns:

True if the result is still valid, in this case it will be reused and the task will not be executed again. When False is returned the cached result is deleted and the task is executed again. The default implementation returns True without considering the result.

class mosaic_orchestrator.cachable_task.CacheResult(result: object, sub_results: Dict[Path, str])[source]

builds the result tree of a task tree, used to evaluate the task cache

result: object
sub_results: Dict[Path, str]