MCPcopy
hub / github.com/dask/dask / test_culling_changes_layer_names

Function test_culling_changes_layer_names

dask/tests/test_highgraph.py:325–364  ·  view source on GitHub ↗

Test that culling changes the layer names in the graph.

()

Source from the content-addressed store, hash-verified

323
324
325def test_culling_changes_layer_names():
326 """Test that culling changes the layer names in the graph."""
327 dsk = MaterializedLayer({"x": 1, "y": (inc, "x"), "z": (dec, "x")})
328 hg = HighLevelGraph({"a": dsk}, {"a": set()})
329
330 # This construction of Delayed objects is similar to array.to_delayed
331 y = Delayed("y", hg, layer="a")
332 z = Delayed("z", hg, layer="a")
333
334 from dask.delayed import optimize
335
336 # This is roughly what dask.optimize is doing
337 # The exception is that collection_to_dsk takes the Delayed object and
338 # extracts the layer as a low level graph in which case we're losing the
339 # layer name, i.e. all internal manipulations of the graphs with and without
340 # optimization could be affected but triggering this with user APIs is
341 # almost impossible
342 yopt_hlg = optimize(y._dask, ["y"])
343 assert isinstance(yopt_hlg, HighLevelGraph)
344 layers = yopt_hlg.layers
345 # This test doesn't care about there being a single layer but after
346 # optimization we no longer want to hardcode the delayed layer key
347 assert len(layers) == 1
348 layer_key = next(iter(layers))
349 yopt = Delayed("y", yopt_hlg, layer=layer_key)
350
351 zopt_hlg = optimize(z._dask, ["z"])
352 assert isinstance(zopt_hlg, HighLevelGraph)
353 layers = zopt_hlg.layers
354 # This test doesn't care about there being a single layer but after
355 # optimization we no longer want to hardcode the delayed layer key
356 assert len(layers) == 1
357 layer_key = next(iter(layers))
358 zopt = Delayed("z", zopt_hlg, layer=layer_key)
359
360 # This internally merged the HLG graphs i.e. if layer names are not
361 # deduplicated we will loose keys.
362 expr_opt = collections_to_expr([yopt, zopt]).optimize()
363 dsk_out = expr_opt.__dask_graph__()
364 assert set(dsk_out) == set("xyz")

Callers

nothing calls this directly

Calls 8

MaterializedLayerClass · 0.90
HighLevelGraphClass · 0.90
DelayedClass · 0.90
optimizeFunction · 0.90
collections_to_exprFunction · 0.90
setClass · 0.85
optimizeMethod · 0.45
__dask_graph__Method · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…