Are class methods pure in dask?


Are class methods pure in dask?



Is this a valid use of pure in Dask?


pure



Lets assume that bar is never changed during the computation, but it may change while I setup the computation.


bar


from dask import delayed


class a:
def __init__(self):
self.bar = 1
def foo(self, b):
return self.bar + b
def dask_foo(self, b):
return delayed(self.foo, pure=True)(b)




1 Answer
1



Yes, this is valid use: you are effectively asserting that the bar attribute, which is not an argument to the delayed function, will not change for any subsequent calls. When you say something is "pure", then Dask assumes that calling with argument b=5 will get the same result each time.
Notice that if you call dask_foo with the same value of b multiple times, the key of the resulting delayed object will be the same every time. If you have pure=False, you get a random UUID part to the key each time.


bar


b=5


dask_foo


b


pure=False



In this case you are obviously able to break your own assertion by changing the value of bar: don't do that!


bar





So it can change before the graph is executed, but not while it is executing. Thanks!
– hmaarrfk
Jun 30 at 16:52






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to input without newline? (Python)

C++ thread error: no type named ‘type’ MINGW

Analog for TagView in flutter