WillianFuks / tfcausalimpact

Python Causal Impact Implementation Based on Google's R Package. Built using TensorFlow Probability.
Apache License 2.0
593 stars 70 forks source link

Running the causal impact algorithm leaks memory. #100

Open Wopple opened 1 month ago

Wopple commented 1 month ago

Running the causal impact algorithm appears to leak memory.

Reproduction code:

import gc
import pandas as pd
from causalimpact import CausalImpact

data = pd.read_csv('https://raw.githubusercontent.com/WillianFuks/tfcausalimpact/master/tests/fixtures/arma_data.csv')[['y', 'X']]
data.iloc[70:, 0] += 5

pre_period = [0, 69]
post_period = [70, 99]

def run_causal_impact():
    ci = CausalImpact(data, pre_period, post_period)
    print(ci.summary())
    print(ci.summary(output='report'))

for _ in range(10):
    run_causal_impact()
    gc.collect()

Dependencies:

[tool.poetry.dependencies]
python = "=3.11.4"
pandas = "=2.2"
tensorflow = "=2.16.1"
tfcausalimpact = "=0.0.15"
pyarrow = "=15.0.2"

I run the program and watch the activity monitor, and each iteration leaks ~80mb or so.