async def test_TaskGraph_order(c, s, a, b): x = c.submit(inc, 1) y = c.submit(div, 1, 0) await wait(y) gp = TaskGraph(s) gp.update() assert gp.node_source.data["state"][gp.layout.index[y.key]] == "erred"
def test_TaskGraph_complex(c, s, a, b): da = pytest.importorskip("dask.array") gp = TaskGraph(s) x = da.random.random((2000, 2000), chunks=(1000, 1000)) y = ((x + x.T) - x.mean(axis=0)).persist() yield wait(y) gp.update() assert len(gp.layout.index) == len(gp.node_source.data["x"]) assert len(gp.layout.index) == len(s.tasks) z = (x - y).sum().persist() yield wait(z) gp.update() assert len(gp.layout.index) == len(gp.node_source.data["x"]) assert len(gp.layout.index) == len(s.tasks) del z yield gen.sleep(0.2) gp.update() assert len(gp.layout.index) == sum(v == "True" for v in gp.node_source.data["visible"]) assert len(gp.layout.index) == len(s.tasks) assert max(gp.layout.index.values()) < len(gp.node_source.data["visible"]) assert gp.layout.next_index == len(gp.node_source.data["visible"]) gp.update() assert set(gp.layout.index.values()) == set(range(len(gp.layout.index))) visible = gp.node_source.data["visible"] keys = list(map(tokey, flatten(y.__dask_keys__()))) assert all(visible[gp.layout.index[key]] == "True" for key in keys)
def test_TaskGraph(c, s, a, b): gp = TaskGraph(s) futures = c.map(inc, range(5)) total = c.submit(sum, futures) yield total gp.update() assert set(map(len, gp.node_source.data.values())) == {6} assert set(map(len, gp.edge_source.data.values())) == {5} json.dumps(gp.edge_source.data) json.dumps(gp.node_source.data) da = pytest.importorskip("dask.array") x = da.random.random((20, 20), chunks=(10, 10)).persist() y = (x + x.T) - x.mean(axis=0) y = y.persist() yield wait(y) gp.update() gp.update() yield c.compute((x + y).sum()) gp.update() future = c.submit(inc, 10) future2 = c.submit(inc, future) yield wait(future2) key = future.key del future, future2 while key in s.tasks: yield gen.sleep(0.01) assert "memory" in gp.node_source.data["state"] gp.update() gp.update() assert not all(x == "False" for x in gp.edge_source.data["visible"])
async def test_TaskGraph_limit(c, s, a, b): gp = TaskGraph(s) def func(x): return x f1 = c.submit(func, 1) await wait(f1) gp.update() assert len(gp.node_source.data["x"]) == 1 f2 = c.submit(func, 2) await wait(f2) gp.update() assert len(gp.node_source.data["x"]) == 2 f3 = c.submit(func, 3) await wait(f3) gp.update() assert len(gp.node_source.data["x"]) == 2
async def test_TaskGraph_clear(c, s, a, b): gp = TaskGraph(s) futures = c.map(inc, range(5)) total = c.submit(sum, futures) await total gp.update() del total, futures while s.tasks: await asyncio.sleep(0.01) gp.update() gp.update() start = time() while any(gp.node_source.data.values()) or any(gp.edge_source.data.values()): await asyncio.sleep(0.1) gp.update() assert time() < start + 5
def test_TaskGraph_limit(c, s, a, b): gp = TaskGraph(s) def func(x): return x f1 = c.submit(func, 1) yield wait(f1) gp.update() assert len(gp.node_source.data["x"]) == 1 f2 = c.submit(func, 2) yield wait(f2) gp.update() assert len(gp.node_source.data["x"]) == 2 f3 = c.submit(func, 3) yield wait(f3) gp.update() assert len(gp.node_source.data["x"]) == 2 del f1 del f2 del f3 _ = c.submit(func, 1) async_wait_for(lambda: len(gp.node_source.data["x"]) == 1, timeout=1)