task_hierarchy_builder

This module contains the mosaic-orchestrator framework core functionality

class mosaic_orchestrator.task_hierarchy_builder.TaskHierarchyBuilder[source]

A builder for a task hierarchy with a specific root task type.

Use the check method to discover missing/invalid dependencies or task inputs. When all errors are resolved use build to retrieve the instance of the root task.

abstract build() T[source]

builds the task hierarchy and returns the instance of the root task.

Use the check method to test if build is going to be successful.

Returns:

the root task instance.

Raises:

MosaicException – in case of a missing dependency or an unsuccessful validation.

abstract check() CheckResult[source]

checks dependencies and task inputs and performs validation.

This method can be called repeatedly to find remaining errors.

Returns:

A CheckResult object containing a list of all settable inputs as well as a list of remaining errors.

abstract register(key: Union[Type, str], value: any, overwrite: bool = False) TaskHierarchyBuilder[T][source]

registers a dependency based on its type or its path in the hierarchy.

This is the intended way to make tool implementations available for tasks. Subsequent calls with the same key overwrite the initial value.

Parameters:
  • keyvalue will be injected into all tasks that have members annotated with this type. When key is str it is expected to be a path to a task input; in this case value is set to this input.

  • value – this object will be injected when key matches

  • overwrite – Overwrite tool/object if it has already been registered

Returns:

a self reference to allow method chaining.

abstract with_cache_directory(path: Path) TaskHierarchyBuilder[T][source]

sets the cache directory for this hierarchy.

Parameters:

path – a path to the target folder. The folder will be created if it does not exist.

Returns:

a self reference to allow method chaining.

abstract with_cfg(config: Union[Config, Path]) TaskHierarchyBuilder[T][source]

loads a Config either from an object or from a python script.

This method can be called repeatedly to merge multiple configurations.

Parameters:

config – a Config object that will be applied to this hierarchy. Alternatively, pass a path to a python script containing a MosaicConfig class; This class will be automatically isntantiated and loaded.

Returns:

a self reference to allow method chaining.

abstract with_inputs(inputs: Dict[str, object]) TaskHierarchyBuilder[T][source]

sets inputs for this hierarchy.

Can be called repeatedly; however, when the same paths are provided any prior values are overwritten.

Parameters:

inputs – a dict that contains paths as keys and input values as values. Values that are not Input instances will be wrapped automatically.

Returns:

a self reference to allow method chaining.

abstract with_pdk(pdk: PDK) TaskHierarchyBuilder[T][source]

sets the pdk for this hierarchy. Subsequent calls overwrite the inital value.

Parameters:

pdk – the instantiated pdk object.

Returns:

a self reference to allow method chaining.

abstract with_run_directory(path: Path) TaskHierarchyBuilder[T][source]

sets the run directory for this hierarchy.

Parameters:

path – a path to the target folder. The folder will be created if it does not exist.

Returns:

a self reference to allow method chaining.