python - ray中的Cython类初始化
问题描述
我正在使用 Ray ( https://github.com/ray-project/ray ) 和 Cython 0.29 来并行化一些现有代码,我决定使用我的 Cython 函数之一定义一个 cdef 类作为其方法来简化运行并行的多个Actor的代码。我遇到的问题是,当我在 cython_simple.py (example6 )之后创建我的类的实例时,我得到一个“__init__ 错误的参数太多”。
我有几个问题,但第一个问题是当我的类实例被 ray.remote 修饰时,如何正确地为其提供参数。
我一直在尝试这种方法,其中 Test 是导入的类:
import ray
from cython_test.cython_test import Test
ray.init()
Test1 = ray.remote(Test)
#Instatiate an actor
args = (img, 10, 10)
a1 = Test1.remote(*args)
但我回来了:
Traceback (most recent call last):
File "test_ray_cython.py", line 25, in <module>
a1 = Test1.remote(*args)
File "/local/data/home/gmosby/.local/lib/python3.7/site-packages/ray/actor.py", line 282, in remote
return self._remote(args=args, kwargs=kwargs)
File "/local/data/home/gmosby/.local/lib/python3.7/site-packages/ray/actor.py", line 384, in _remote
kwargs)
File "/local/data/home/gmosby/.local/lib/python3.7/site-packages/ray/signature.py", line 221, in extend_args
.format(function_name))
Exception: Too many arguments were passed to the function '__init__'
附加信息:这里的 Cython 类被初始化为def __init__(self, img, nx, ny)
如果我想将 Cython 类与 Ray 一起使用,它是否必须没有任何初始化参数?
发现的解决方法:在 __init__ 方法中使用位置参数装饰 Cython 类确实失败了,但我决定将一些类成员的设置移动到单独的函数中。在此处查看此问题的说明和解决方法 ( https://github.com/astrophysaxist/cython_test )
解决方案
发现的解决方法:在 __init__ 方法中使用位置参数装饰 Cython 类确实失败了,但我决定将一些类成员的设置移动到单独的函数中。在此处查看此问题的说明和解决方法 ( https://github.com/astrophysaxist/cython_test )
推荐阅读
- python - 未找到:/style.css/,django
- linux - 我正在尝试从文件中读取内容,但没有得到准确的输出
- c# - UWP 在设置中存储和加载视频编码属性
- flutter - Flutter - 未处理的异常:在 dispose() 之后调用 setState()
- c# - 有没有办法运行使用操作系统身份验证来运行 RMAN 备份作为 systemd 的 .NET Core 服务?
- c - 整数的用户输入无限循环,直到用户输入字符 (C)
- php - 使用 laravel 查询生成器嵌套选择?
- r - 选择包含值 x 或值 y 的 df
- android - android导航UI组件内存泄漏
- angular - 同时在多个字段上进行 Mat-autocomplete 搜索