sciline.TaskGraph#

class sciline.TaskGraph(*, graph, targets, scheduler=None)[source]#

Holds a concrete task graph and keys to compute.

Task graphs are typically created by sciline.Pipeline.build. They allow for computing all or a subset of the results in the graph.

__init__(*, graph, targets, scheduler=None)[source]#

Methods

__init__(*, graph, targets[, scheduler])

compute([targets])

Compute the result of the graph.

keys()

Iterate over all keys of the graph.

serialize()

Serialize the graph to JSON.

visualize(**kwargs)

Return a graphviz Digraph object representing the graph.

compute(targets=None)[source]#

Compute the result of the graph.

Parameters:

targets (Union[Hashable, tuple[Hashable, ...], None], default: None) – Optional list of keys to compute. This can be used to override the keys stored in the graph instance. Note that the keys must be present in the graph as intermediate results, otherwise KeyError is raised.

Returns:

Any – * If ``targets` is a single type`, returns the single result that was computed. * If ``targets` is a tuple` of types, returns a dictionary with type as keys * and the corresponding results as values.

keys()[source]#

Iterate over all keys of the graph.

Yields all keys, i.e., the types of values that can be computed or are provided as parameters.

Returns:

Generator[type, None, None] – Iterable over keys.

serialize()[source]#

Serialize the graph to JSON.

See the user guide on Serializing Providers.

Returns:

dict[str, dict[str, Json] | list[Json] | str | int | float | bool | None] – A JSON object representing the graph.

visualize(**kwargs)[source]#

Return a graphviz Digraph object representing the graph.

Parameters:

kwargs (Any) – Keyword arguments passed to graphviz.Digraph.

Return type:

graphviz.Digraph