I'm using Ray (https://github.com/ray-project/ray) and Cython 0.29 to parallelize some existing code, and I decided to define a cdef class with one of my Cython functions as its method to ease running the code for multiple Actors in paralell. The problem I've run into is that when I create an instance of my class following the cython_simple.py (example6), I get a "Too many arguments to __init__ error".
I have a few questions, but the first is how to correctly give my class instance its arguments when it gets decorated by ray.remote.
I've been trying this method where Test is the imported class:
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)
But I get back:
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__'
Additional Info: The Cython class here was initialized as def __init__(self, img, nx, ny)
Is it the case that if I want to use a Cython class with Ray it must not have any initialization arguments?
WORKAROUND found: It does appear decorating Cython classes with positional arguments in their __init__ methods fails, but I’ve decided to just move the setting of some class members to a separate function. See illustration of this issue and workaround here (https://github.com/astrophysaxist/cython_test)