MCPcopy
hub / github.com/dask/dask / fuse_linear_task_spec

Function fuse_linear_task_spec

dask/_task_spec.py:1105–1185  ·  view source on GitHub ↗

keys are the keys from the graph that are requested by a computation. We can't fuse those together.

(dsk, keys)

Source from the content-addressed store, hash-verified

1103
1104
1105def fuse_linear_task_spec(dsk, keys):
1106 """
1107 keys are the keys from the graph that are requested by a computation. We
1108 can't fuse those together.
1109 """
1110 from dask.core import reverse_dict
1111 from dask.optimization import default_fused_keys_renamer
1112
1113 keys = set(keys)
1114 dependencies = DependenciesMapping(dsk)
1115 dependents = reverse_dict(dependencies)
1116
1117 seen = set()
1118 result = {}
1119
1120 for key in dsk:
1121 if key in seen:
1122 continue
1123
1124 seen.add(key)
1125
1126 deps = dependencies[key]
1127 dependents_key = dependents[key]
1128
1129 if len(deps) != 1 and len(dependents_key) != 1 or dsk[key].block_fusion:
1130 result[key] = dsk[key]
1131 continue
1132
1133 linear_chain = [dsk[key]]
1134 top_key = key
1135
1136 # Walk towards the leafs as long as the nodes have a single dependency
1137 # and a single dependent, we can't fuse two nodes of an intermediate node
1138 # is the source for 2 dependents
1139 while len(deps) == 1:
1140 (new_key,) = deps
1141 if new_key in seen:
1142 break
1143 seen.add(new_key)
1144 if new_key not in dsk:
1145 # This can happen if a future is in the graph, the dependency mapping
1146 # adds the key that is referenced by the future as a dependency
1147 # see test_futures_to_delayed_array
1148 break
1149 if (
1150 len(dependents[new_key]) != 1
1151 or dsk[new_key].block_fusion
1152 or new_key in keys
1153 ):
1154 result[new_key] = dsk[new_key]
1155 break
1156 # backwards comp for new names, temporary until is_rootish is removed
1157 linear_chain.insert(0, dsk[new_key])
1158 deps = dependencies[new_key]
1159
1160 # Walk the tree towards the root as long as the nodes have a single dependent
1161 # and a single dependency, we can't fuse two nodes if node has multiple
1162 # dependencies

Callers 10

optimizeFunction · 0.90
optimizeFunction · 0.90
test_linear_fusionFunction · 0.90
test_block_io_fusionFunction · 0.90
test_data_producerFunction · 0.90
optimizerFunction · 0.90
optimizeFunction · 0.90

Calls 8

reverse_dictFunction · 0.90
setClass · 0.85
DependenciesMappingClass · 0.85
AliasClass · 0.85
popMethod · 0.80
addMethod · 0.45
fuseMethod · 0.45

Tested by 7

test_linear_fusionFunction · 0.72
test_block_io_fusionFunction · 0.72
test_data_producerFunction · 0.72
optimizerFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…