Skip to content

Running the causal impact algorithm leaks memory. #100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Wopple opened this issue Jun 14, 2024 · 1 comment
Open

Running the causal impact algorithm leaks memory. #100

Wopple opened this issue Jun 14, 2024 · 1 comment

Comments

@Wopple
Copy link

Wopple commented Jun 14, 2024

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.

@Wopple Wopple changed the title Running the causal impact leaks memory. Running the causal impact algorithm leaks memory. Jun 14, 2024
@JamesStratford
Copy link

JamesStratford commented Feb 11, 2025

Can confirm this issue, running multiple causal impacts in a single script can leak to out of memory errors

I've resorted to using Multiprocessing and running each CI in a separate process. This ensures that the memory is freed so no more kernel crashes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants