I'm trying to use the python multiprocess package ray, to parallelise a convolution process from within a class.
This means I am setting the function using the @ray.remote
decorator to a class function.
However when I do this I get an error to do with parameter defaults.
I am new to using ray and decorators so I was wondering if anyone has some advice on where I am going wrong because I don't think this is as simple as providing the class function with an optional default parameter such as None
for example.
Here is a simplified version of the code:
import numpy as np
import psutil
import ray
from astropy.convolution import convolve
class test_class:
def __init__(self,cube):
self.cube = cube
@ray.remote
def func(self, cube, psf):
cube = convolve(cube, psf)
return cube
def calculation(self):
num_cpus = psutil.cpu_count(logical=False)
ray.shutdown()
ray.init(num_cpus=num_cpus)
filters = np.array([[0,.5,0],[.5,.7,.5],[0,.5,0]])
results = []
for i in range(self.cube.shape[2]):
results.append(self.func.remote(self.cube[:,:,i],filters))
results = np.array(ray.get(results)).T
ray.shutdown()
return results
Running the code...
cube = np.random.uniform(0,1,(100,100,10))
new_cube = test_class(cube).calculation()
And the resulting error:
TypeError: 'psf' parameter lacking default value
I found a similar post but I'm not sure if the two problems are that similar due to handling the execution of ray
differently and my naivety on the use of this package.
Many thanks in advance!