dask.delayed如何处理可变输入? [英] How does dask.delayed handle mutable inputs?

查看:281
本文介绍了dask.delayed如何处理可变输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个可变对象,例如一个字典,那么dask如何处理将其作为输入传递给延迟函数?

If I have an mutable object, let's say for example a dict, how does dask handle passing that as an input to delayed functions? Specifically if I make updates to the dict between delayed calls?

我具体尝试了以下示例,该示例似乎表明正在进行某些复制,但是您能详细说明一下究竟是什么吗?

I tried the following example which seems to suggest that some copying is going on but can you elaborate what exactly dask is doing?

In [3]: from dask import delayed

In [4]: x = {}

In [5]: foo = delayed(print)

In [6]: foo(x)
Out[6]: Delayed('print-73930550-94a6-43f9-80ab-072bc88c2b88')

In [7]: foo(x).compute()
{}

In [8]: p1 = foo(x)

In [9]: x['a'] = 1

In [10]: p2 = foo(x)

In [11]: p1.compute()
{}

In [12]: p2.compute()
{'a': 1}


推荐答案

Dask不支持可变输入。达斯克希望输入不变。 Dask还希望函数不会在适当位置改变输入。

Dask does not support mutable inputs. Dask expects inputs to not change. Dask also expects functions to not mutate inputs inplace.

事实证明很难同时支持突变和弹性。

It turns out to be hard to support both mutation and resilience at the same time.

看起来dask已将您的字典解构为另一个对象。在这种情况下,词典是特殊的。对于大多数可变对象,我不会期望这种行为。

In this case it looks like dask has deconstructed your dictionary into another object. Dictionaries are special in this case. I would not expect this behavior for most mutable objects

In [1]: from dask import delayed

In [2]: x = {}

In [3]: foo = delayed(print)

In [4]: p1 = foo(x)

In [5]: dict(p1.__dask_graph__())
Out[5]: {'print-26d52543-57fc-4873-9722-1a8fd2f1641c': (<function print>, (dict, []))}

这篇关于dask.delayed如何处理可变输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆