MCPcopy Create free account
hub / github.com/dask/dask / execute_graph

Function execute_graph

dask/_task_spec.py:1046–1084  ·  view source on GitHub ↗

Execute a given graph. The graph is executed in topological order as defined by dask.order until all leaf nodes, i.e. nodes without any dependents, are reached. The returned dictionary contains the results of the leaf nodes. If keys are required that are not part of the graph, they

(
    dsk: Iterable[GraphNode] | Mapping[KeyType, GraphNode],
    cache: MutableMapping[KeyType, object] | None = None,
    keys: Container[KeyType] | None = None,
)

Source from the content-addressed store, hash-verified

1044
1045
1046def execute_graph(
1047 dsk: Iterable[GraphNode] | Mapping[KeyType, GraphNode],
1048 cache: MutableMapping[KeyType, object] | None = None,
1049 keys: Container[KeyType] | None = None,
1050) -> MutableMapping[KeyType, object]:
1051 """Execute a given graph.
1052
1053 The graph is executed in topological order as defined by dask.order until
1054 all leaf nodes, i.e. nodes without any dependents, are reached. The returned
1055 dictionary contains the results of the leaf nodes.
1056
1057 If keys are required that are not part of the graph, they can be provided in the `cache` argument.
1058
1059 If `keys` is provided, the result will contain only values that are part of the `keys` set.
1060
1061 """
1062 if isinstance(dsk, (list, tuple, set, frozenset)):
1063 dsk = {t.key: t for t in dsk}
1064 else:
1065 assert isinstance(dsk, dict)
1066
1067 refcount: defaultdict[KeyType, int] = defaultdict(int)
1068 for vals in DependenciesMapping(dsk).values():
1069 for val in vals:
1070 refcount[val] += 1
1071
1072 cache = cache or {}
1073 from dask.order import order
1074
1075 priorities = order(dsk)
1076
1077 for key, node in sorted(dsk.items(), key=lambda it: priorities[it[0]]):
1078 cache[key] = node(cache)
1079 for dep in node.dependencies:
1080 refcount[dep] -= 1
1081 if refcount[dep] == 0 and keys and dep not in keys:
1082 del cache[dep]
1083
1084 return cache
1085
1086
1087def fuse_linear_task_spec(dsk, keys):

Callers 4

getFunction · 0.90
_execute_subgraphFunction · 0.85

Calls 4

orderFunction · 0.90
DependenciesMappingClass · 0.85
valuesMethod · 0.45
itemsMethod · 0.45

Tested by 1