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.Methods
__init__
(*, graph, targets[, scheduler])compute
([targets])Compute the result of the graph.
keys
()Iterate over all keys of the graph.
Serialize the graph to JSON.
visualize
([compact, mode, cluster_generics, ...])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` oftypes
,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.
- serialize()[source]#
Serialize the graph to JSON.
See the user guide on Serializing Providers.
- visualize(compact=False, mode='data', cluster_generics=True, cluster_color='#f0f0ff', **kwargs)[source]#
Return a graphviz Digraph object representing the graph.
- Parameters:
compact (bool, default:
False
) – If True, parameter-table-dependent branches are collapsed into a single copy of the branch. Recommended for large graphs with long parameter tables.mode (Literal[‘data’, ‘task’, ‘both’], default:
'data'
) – If ‘data’, only data nodes are shown. If ‘task’, only task nodes and input data nodes are shown. If ‘both’, all nodes are shown.cluster_generics (bool, default:
True
) – If True, generic products are grouped into clusters.cluster_color (str | None, default:
'#f0f0ff'
) – Background color of clusters. If None, clusters are dotted.kwargs (Any) – Keyword arguments passed to
graphviz.Digraph
.
- Return type:
graphviz.Digraph