eolearn.core.eoworkflow¶
The eoworkflow module, together with eotask and eodata, provides core building blocks for specifying and executing workflows.
A workflow is a directed (acyclic) graph composed of instances of EOTask objects. Each task may take as input the results of other tasks and external arguments. The external arguments are passed anew each time the workflow is executed. The workflow builds the computational graph, performs dependency resolution, and executes the tasks. If the input graph is cyclic, the workflow raises a CyclicDependencyError.
The result of a workflow execution is an immutable mapping from tasks to results. The result contains tasks with zero out-degree (i.e. terminal tasks).
The workflow can be exported to a DOT description language and visualized.
-
exception
eolearn.core.eoworkflow.
CyclicDependencyError
[source]¶ Bases:
ValueError
This error is raised when trying to initialize EOWorkflow with a cyclic dependency graph
-
class
eolearn.core.eoworkflow.
EOWorkflow
(dependencies, task_names=None)[source]¶ Bases:
object
A basic eo-learn object for building workflows from a list of task dependencies
Example:
workflow = EOWorkflow([ # task1, task2, task3 are initialized EOTasks (task1, [], 'My first task'), (task2, []), (task3, [task1, task2], 'Task that depends on previous 2 tasks') ])
- Parameters
dependencies (list(tuple or Dependency)) – A list of dependencies between tasks, specifying the computational graph.
-
create_dag
(dependencies)[source]¶ Creates a directed graph from dependencies
- Parameters
dependencies (list(Dependency)) – A list of Dependency objects
- Returns
A directed graph of the workflow
- Return type
-
execute
(input_args=None, monitor=False)[source]¶ Executes the workflow
- Parameters
input_args (dict(EOTask: dict(str: object) or tuple(object))) – External input arguments to the workflow. They have to be in a form of a dictionary where each key is an EOTask used in the workflow and each value is a dictionary or a tuple of arguments.
monitor (bool) – If True workflow execution will be monitored
- Returns
An immutable mapping containing results of terminal tasks
- Return type
-
static
parse_input_args
(input_args)[source]¶ Parses EOWorkflow input arguments provided by user and raises an error if something is wrong. This is done automatically in the process of workflow execution
-
get_tasks
()[source]¶ Returns an ordered dictionary {task_name: task} of all tasks within this workflow
- Returns
Ordered dictionary with key being task_name (str) and an instance of a corresponding task from this workflow. The order of tasks is the same as in which they will be executed.
- Return type
OrderedDict
-
get_dot
()[source]¶ Generates the DOT description of the underlying computational graph
- Returns
The DOT representation of the computational graph
- Return type
Digraph
-
dependency_graph
(filename=None)[source]¶ Visualize the computational graph
- Parameters
filename (str) – Filename of the output image together with file extension. Supported formats: png, jpg, pdf, … . Check graphviz Python package for more options
- Returns
The DOT representation of the computational graph, with some more formatting
- Return type
Digraph
-
class
eolearn.core.eoworkflow.
LinearWorkflow
(*tasks, **kwargs)[source]¶ Bases:
eolearn.core.eoworkflow.EOWorkflow
A linear version of EOWorkflow where each tasks only gets results of the previous task
Example:
workflow = LinearWorkflow(task1, task2, task3)
- Parameters
tasks (*EOTask) – Tasks in the order of execution
-
class
eolearn.core.eoworkflow.
Dependency
(task=None, inputs=NOTHING, name=None)[source]¶ Bases:
object
Class representing a node in EOWorkflow graph
- Parameters
Method generated by attrs for class Dependency.
-
class
eolearn.core.eoworkflow.
WorkflowResults
(results)[source]¶ Bases:
collections.abc.Mapping
The result of a workflow is an (immutable) dictionary mapping [1] from EOTasks to results of the workflow.
When an EOTask is passed as an index, its UUID, assigned during workflow execution, is used as the key (as opposed to the result of invoking __repr__ on the EO task). This ensures that indexing by task works even after pickling, and makes dealing with checkpoints more convenient.
[1] https://docs.python.org/3.6/library/collections.abc.html#collections-abstract-base-classes