laszukdawid / PyEMD

Python implementation of Empirical Mode Decompoisition (EMD) method
https://pyemd.readthedocs.io/
Apache License 2.0
857 stars 222 forks source link

Why I am getting the "'Pool' object is not callable" Error from EEMD function in PyEMD when using its parallel argument? #145

Closed ashkanreisi closed 11 months ago

ashkanreisi commented 11 months ago

I have written the below code to perform parallel processing when computing IMFs through EEMD function in PyEMD library:

eemd = EEMD(parallel = True, processes = 8)
eemd.noise_seed(12345)
imfs = eemd.eemd(time_series.reshape(-1),None,8)

Running the above code, threw an error, as:

TypeError                                 Traceback (most recent call last)
Cell In[3], line 4
      2 eemd = EEMD(parallel = True, processes = 8)
      3 eemd.noise_seed(12345)
----> 4 imfs = eemd.eemd(time_series.reshape(-1),None,8)

File ~\AppData\Local\anaconda3\lib\site-packages\PyEMD\EEMD.py:189, in EEMD.eemd(self, S, T, max_imf, progress)
    187 else:
    188     map_pool = map
--> 189 all_IMFs = map_pool(self._trial_update, range(self.trials))
    191 if self.parallel:
    192     map_pool.close()

TypeError: 'Pool' object is not callable

I am not sure what causes this problem. *A note that when I tried the same code without passing parallel and processes arguments, the code works perfectly fine.

mskoenz commented 11 months ago

This fix will get it working, likely a refactoring error, or a missing test coverage:

file EEMD.py lines 183+

        # For trial number of iterations perform EMD on a signal
        # with added white noise
        if self.parallel:
            pool = Pool(processes=self.processes)
            map_pool = pool.map
        else:
            map_pool = map
        all_IMFs = map_pool(self._trial_update, range(self.trials))

        if self.parallel:
            pool.close()
laszukdawid commented 11 months ago

Thanks @mskoenz for jumping in! Really appreciate it!

Let me fix this

mskoenz commented 11 months ago

happy to help, thx for the library :)

ashkanreisi commented 10 months ago

Thank you guys.