MCPcopy
hub / github.com/dask/dask / to_task_dask

Function to_task_dask

dask/delayed.py:300–389  ·  view source on GitHub ↗

Normalize a python object and merge all sub-graphs. - Replace ``Delayed`` with their keys - Convert literals to things the schedulers can handle - Extract dask graphs from all enclosed values Parameters ---------- expr : object The object to be normalized. This func

(expr)

Source from the content-addressed store, hash-verified

298
299
300def to_task_dask(expr):
301 """Normalize a python object and merge all sub-graphs.
302
303 - Replace ``Delayed`` with their keys
304 - Convert literals to things the schedulers can handle
305 - Extract dask graphs from all enclosed values
306
307 Parameters
308 ----------
309 expr : object
310 The object to be normalized. This function knows how to handle
311 ``Delayed``s, as well as most builtin python types.
312
313 Returns
314 -------
315 task : normalized task to be run
316 dask : a merged dask graph that forms the dag for this task
317
318 Examples
319 --------
320 >>> import dask
321 >>> a = delayed(1, 'a')
322 >>> b = delayed(2, 'b')
323 >>> task, dask = to_task_dask([a, b, 3]) # doctest: +SKIP
324 >>> task # doctest: +SKIP
325 ['a', 'b', 3]
326 >>> dict(dask) # doctest: +SKIP
327 {'a': 1, 'b': 2}
328
329 >>> task, dasks = to_task_dask({a: 1, b: 2}) # doctest: +SKIP
330 >>> task # doctest: +SKIP
331 (dict, [['a', 1], ['b', 2]])
332 >>> dict(dask) # doctest: +SKIP
333 {'a': 1, 'b': 2}
334 """
335 warnings.warn(
336 "The dask.delayed.to_dask_dask function has been "
337 "Deprecated in favor of unpack_collections",
338 stacklevel=2,
339 )
340
341 if isinstance(expr, Delayed):
342 return expr.key, expr.dask
343
344 if is_dask_collection(expr):
345 expr = collections_to_expr(expr)
346 expr = FinalizeCompute(expr)
347 expr = expr.optimize()
348 (name,) = expr.__dask_keys__()
349 return name, expr.__dask_graph__()
350
351 if type(expr) is type(iter(list())):
352 expr = list(expr)
353 elif type(expr) is type(iter(tuple())):
354 expr = tuple(expr)
355 elif type(expr) is type(iter(set())):
356 expr = set(expr)
357 typ = type(expr)

Callers 2

test_to_task_daskFunction · 0.90
test_array_delayedFunction · 0.90

Calls 11

is_dask_collectionFunction · 0.90
collections_to_exprFunction · 0.90
FinalizeComputeClass · 0.90
unzipFunction · 0.90
is_namedtuple_instanceFunction · 0.90
setClass · 0.85
mergeFunction · 0.70
optimizeMethod · 0.45
__dask_keys__Method · 0.45
__dask_graph__Method · 0.45
itemsMethod · 0.45

Tested by 2

test_to_task_daskFunction · 0.72
test_array_delayedFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…