MCPcopy Index your code
hub / github.com/dask/dask / fuse_linear

Function fuse_linear

dask/optimization.py:86–228  ·  view source on GitHub ↗

Return new dask graph with linear sequence of tasks fused together. If specified, the keys in ``keys`` keyword argument are *not* fused. Supply ``dependencies`` from output of ``cull`` if available to avoid recomputing dependencies. **This function is mostly superseded by ``fuse``*

(dsk, keys=None, dependencies=None, rename_keys=True)

Source from the content-addressed store, hash-verified

84
85
86def fuse_linear(dsk, keys=None, dependencies=None, rename_keys=True):
87 """Return new dask graph with linear sequence of tasks fused together.
88
89 If specified, the keys in ``keys`` keyword argument are *not* fused.
90 Supply ``dependencies`` from output of ``cull`` if available to avoid
91 recomputing dependencies.
92
93 **This function is mostly superseded by ``fuse``**
94
95 Parameters
96 ----------
97 dsk: dict
98 keys: list
99 dependencies: dict, optional
100 {key: [list-of-keys]}. Must be a list to provide count of each key
101 This optional input often comes from ``cull``
102 rename_keys: bool or func, optional
103 Whether to rename fused keys with ``default_fused_linear_keys_renamer``
104 or not. Renaming fused keys can keep the graph more understandable
105 and comprehensive, but it comes at the cost of additional processing.
106 If False, then the top-most key will be used. For advanced usage, a
107 func is also accepted, ``new_key = rename_keys(fused_key_list)``.
108
109 Examples
110 --------
111 >>> def inc(x):
112 ... return x + 1
113
114 >>> def add(x, y):
115 ... return x + y
116
117 >>> d = {'a': 1, 'b': (inc, 'a'), 'c': (inc, 'b')}
118 >>> dsk, dependencies = fuse(d)
119 >>> dsk # doctest: +SKIP
120 {'a-b-c': (inc, (inc, 1)), 'c': 'a-b-c'}
121 >>> dsk, dependencies = fuse(d, rename_keys=False)
122 >>> dsk # doctest: +ELLIPSIS
123 {'c': (<function inc at ...>, (<function inc at ...>, 1))}
124 >>> dsk, dependencies = fuse(d, keys=['b'], rename_keys=False)
125 >>> dsk # doctest: +ELLIPSIS
126 {'b': (<function inc at ...>, 1), 'c': (<function inc at ...>, 'b')}
127
128 Returns
129 -------
130 dsk: output graph with keys fused
131 dependencies: dict mapping dependencies after fusion. Useful side effect
132 to accelerate other downstream optimizations.
133 """
134 if keys is not None and not isinstance(keys, set):
135 if not isinstance(keys, list):
136 keys = [keys]
137 keys = set(flatten(keys))
138
139 if dependencies is None:
140 dependencies = {k: get_dependencies(dsk, k, as_list=True) for k in dsk}
141
142 # locate all members of linear chains
143 child2parent = {}

Callers 1

fuse2Function · 0.90

Calls 8

flattenFunction · 0.90
get_dependenciesFunction · 0.90
subsFunction · 0.90
setClass · 0.85
popMethod · 0.80
removeMethod · 0.80
addMethod · 0.45
itemsMethod · 0.45

Tested by 1

fuse2Function · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…