laszukdawid / PyEMD

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

Issues about parallel computation #143

Closed Devilbean000 closed 11 months ago

Devilbean000 commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Two issues:

  1. When I turn on parallel parameter, I get TypeError.
  2. I get different results when I turn on and off the parallel computation. Does parallel computation influence results?

To Reproduce Short code showing how to reproduce the issue. S = f t = np.arange(1970,2020,1)

EEMD options

max_imf=3

Prepare and run EEMD

eemd = EEMD(trials=10000, FIXE_H=10, DTYPE=np.float16, noise_width=0.2, parallel=True) #max_imfs=10) eemd.noise_seed(6021)

Execute EEMD on S

eIMFs = eemd.eemd(S, t, max_imf)

Expected behavior A clear and concise description of what you expected to happen. I get TypeError: 'Pool' object is not callable

Details: 'TypeError Traceback (most recent call last) Cell In[4], line 12 9 eemd.noise_seed(6021) 11 # Execute EEMD on S ---> 12 eIMFs = eemd.eemd(S, t, max_imf)

File ~/.conda/envs/eemd/lib/python3.11/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()'

Screenshots If applicable, add screenshots to help explain your problem. Screenshot 2023-08-03 at 17 27 21

Running environment Provide operating system (OS) information, PyEMD version and describe virtual environment (if any). Python 3.11.4, latest PyEMD

Additional context Add any other context about the problem here. I used parallel computation before, now I have new python and conda environment. Then I can't turn on the parallel parameter, therefore I turn it off. But it's strange that I get different results with same manuscript. Does parallel computation influence results?

sebhinck commented 12 months ago

Can be solved by changing https://github.com/laszukdawid/PyEMD/blob/7361a883e21bf92a9a62abfeaceffc38e91955b9/PyEMD/EEMD.py#L185-L192 to

        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

This should be fixed in the latest 1.5.2 version