intive-DataScience / tbats

BATS and TBATS forecasting methods
MIT License
178 stars 19 forks source link

Computation freezes console #10

Closed BerriJ closed 4 years ago

BerriJ commented 4 years ago

Hi there, I'm trying to estimate a TBATS model. Since this wasn't working, I've tried the sample code from the repository description.

from tbats import TBATS
import numpy as np

# required on windows for multi-processing,
# see https://docs.python.org/2/library/multiprocessing.html#windows
if __name__ == '__main__':
    np.random.seed(2342)
    t = np.array(range(0, 160))
    y = 5 * np.sin(t * 2 * np.pi / 7) + 2 * np.cos(t * 2 * np.pi / 30.5) + \
        ((t / 20) ** 1.5 + np.random.normal(size=160) * t / 50) + 10

    # Create estimator
    estimator = TBATS(seasonal_periods=[14, 30.5])

    # Fit model
    fitted_model = estimator.fit(y)

    # Forecast 14 steps ahead
    y_forecasted = fitted_model.forecast(steps=14)

    # Summarize fitted model
    print(fitted_model.summary())

Unfortunately, this isn't working. There is no error or warning, but the computation never completes the estimator.fit() call. My machine is busy for approx 30 sec. but then CPU usage drops to zero, but the console stays busy. I've tried this on:

I've attached my conda environments (I had to rename the .yml files to .txt to upload them here).

Any help is much appreciated. Thanks in advance.

thesis_gas_lnx.txt thesis_gas_mac_os.txt

cotterpl commented 4 years ago

After investigation I confirm the issue. It gets stuck doing multithreading where it idfinetly waits for lock release. The issue lies somewhere in python 3.7.5. I don't know when or even if the bug will be fixed. I have checked that it works correctly with python 3.7.6. Is it possible for you to upgrade python from 3.7.5 to 3.7.6 as a workaround?

BerriJ commented 4 years ago

Upgrading would be possible but, unfortunately, I wasn't able to fix my problem by upgrading. First I updated from 3.7.5 to 3.7.6. After this I set up a new test environment with a minimum of packages installed, just to test TBATS but no luck for me. I attached the environment file again. This was on Manjaro Linux, I will try MacOS soon.

test.txt

cotterpl commented 4 years ago

Unfortunately your yaml is tied to linux and I don't have time at this moment to verify this on linux. I will do so later.

I have created platform independent mimial version: test2.txt and it works at least on macos.

Please try it.

If the first case does not work - I have also added new release where I modified the code so that when you provide n_jobs=1 it will not span any subprocess and will not use paralelization. This kind of a fix works even in python 3.7.5

Please update to tbats=1.0.9 and modify code in your example so that the following parameters enter TBATS:

estimator = TBATS(seasonal_periods=[14, 30.5], n_jobs=1)

It will be slow (no parallelisation) but should work now.

BerriJ commented 4 years ago

Thank you so much. I took some time and tested the following:

Your minimal environment with:

My initial environment with python 3.7.5 or 3.7.6 with tbats 1.0.9:

So I guess there is still some problem with a package version of my initial environment. But it works for now. If I somehow stumble across the root of this problem I'll definitely post here but for now, I think this can be closed.

Thank you again.