在自定义Dask图中包括关键字参数(kwargs) [英] Including keyword arguments (kwargs) in custom Dask graphs

查看:90
本文介绍了在自定义Dask图中包括关键字参数(kwargs)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Dask的一项操作构建自定义图形。熟悉如何在Dask图中将参数传递给函数,并已阅读 docs 。但是,似乎仍然缺少某些东西。



在Dask图中使用的函数之一带有关键字参数。尽管对于如何将关键字参数传递给它感到困惑。其中一些关键字参数代表Dask对象,因此它们必须明确地位于图形中(即 functools.partial 无效)。可以看到以下选项。


  1. 尝试以正确的位置顺序传递任何关键字参数。 (不适用于通用 ** kwargs 或仅关键字参数)

  2. 编写一个包装程序,该包装程序将位置参数转换为关键字参数,并在图中使用它。 (可以,但有一些开销)

  3. 以某种方式直接将它们包括在图形中? (理想,但不清楚如何做)

有人对如何最好地做到这一点有什么想法?

解决方案

常见的解决方法是使用 apply 函数



<$来自dask.compatibility import的p $ p> 导入apply
task =(apply,func,args,kwargs)#func(* args,** kwargs)


Am building a custom graph for one operation with Dask. Am familiar with how to pass arguments to a function in Dask graph and have read up on the docs. However still seem to be missing something.

One of the functions used in the Dask graph takes keyword arguments. Though am confused as to how the keyword arguments can be passed to it. Some of these keyword arguments represent Dask objects so they must be in the graph explicitly (i.e. functools.partial won't work). Can see the following options.

  1. Try to pass any keyword arguments in the correct positional order. (won't work for generic **kwargs or keyword only arguments)
  2. Write a wrapper that converts positional arguments to keywords arguments and use that in the graph. (works ok, but has some overhead)
  3. Include them directly in the graph somehow? (ideal, but unclear how)

Any thoughts on how best to do this?

解决方案

A common workaround is to use the apply function

from dask.compatibility import apply
task = (apply, func, args, kwargs)  # func(*args, **kwargs)

这篇关于在自定义Dask图中包括关键字参数(kwargs)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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