Metadata-Version: 2.4
Name: causalts
Version: 0.28.1
Summary: Causal discovery (structure learning) for stationary and nonstationary multivariate time series in Python
Author: Mohammad Fesanghary, Achintya Gopal, Agathe Sadeghi
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/bloomberg/causal-ts
Project-URL: Documentation, https://causal-ts.readthedocs.io/en/latest/
Project-URL: Paper, https://arxiv.org/abs/2607.24673
Project-URL: Repository, https://github.com/bloomberg/causal-ts
Project-URL: Issues, https://github.com/bloomberg/causal-ts/issues
Project-URL: Changelog, https://github.com/bloomberg/causal-ts/blob/main/CHANGELOG.md
Keywords: causal-discovery,causal-inference,structure-learning,causal-graphs,causality,causal-machine-learning,graphical-models,time-series,time-series-analysis,multivariate-time-series,nonstationary,conditional-independence,granger-causality,pytorch,gpu
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: numpy>=1.24
Requires-Dist: pandas>=1.5
Requires-Dist: torch>=2.0
Requires-Dist: scipy>=1.10
Requires-Dist: networkx>=3.0
Requires-Dist: causal-learn>=0.1.3
Requires-Dist: dcor>=0.6
Requires-Dist: tqdm>=4.60
Requires-Dist: scikit-learn>=1.2
Requires-Dist: statsmodels>=0.14
Requires-Dist: numba>=0.57
Requires-Dist: matplotlib>=3.7
Requires-Dist: pytorch-lightning>=2.0
Requires-Dist: click>=8.0
Provides-Extra: dowhy
Requires-Dist: dowhy>=0.11; extra == "dowhy"
Provides-Extra: tigramite
Requires-Dist: tigramite; extra == "tigramite"
Provides-Extra: parquet
Requires-Dist: pyarrow>=10.0; extra == "parquet"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0; extra == "dev"
Requires-Dist: black>=23.0; extra == "dev"
Requires-Dist: isort>=5.12; extra == "dev"
Requires-Dist: flake8>=6.0; extra == "dev"
Requires-Dist: ipykernel>=6.0; extra == "dev"
Requires-Dist: jupytext==1.19.6; extra == "dev"
Dynamic: license-file

# Causal-TS

**Causal discovery for stationary and nonstationary multivariate time series
in Python.**

[![PyPI](https://img.shields.io/pypi/v/causalts)](https://pypi.org/project/causalts/)
[![Python](https://img.shields.io/pypi/pyversions/causalts)](https://pypi.org/project/causalts/)
[![arXiv](https://img.shields.io/badge/arXiv-2607.24673-b31b1b.svg)](https://arxiv.org/abs/2607.24673)
[![Documentation](https://img.shields.io/readthedocs/causal-ts/latest?label=docs)](https://causal-ts.readthedocs.io/en/latest/)
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/bloomberg/causal-ts/badge)](https://scorecard.dev/viewer/?uri=github.com/bloomberg/causal-ts)
[![Lint](https://github.com/bloomberg/causal-ts/actions/workflows/lint.yml/badge.svg?branch=main)](https://github.com/marketplace/actions/super-linter)
[![Tests](https://github.com/bloomberg/causal-ts/actions/workflows/test.yml/badge.svg)](https://github.com/bloomberg/causal-ts/actions/workflows/test.yml)
[![Contributor-Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-fbab2c.svg)](https://github.com/bloomberg/causal-ts/blob/main/CODE_OF_CONDUCT.md)

## About the Project

📚 **[Full documentation is on Read the Docs](https://causal-ts.readthedocs.io/en/latest/)** — algorithm deep-dives, CI test guide, CLI reference, and worked example notebooks.

Causal-TS (`causalts` on PyPI) is an open-source Python library for causal
discovery (also called causal structure learning) from stationary and
nonstationary multivariate time series. It learns lagged and contemporaneous
causal graphs with constraint-based, score-based and hybrid methods;
provides linear and nonlinear conditional-independence tests on CPU and GPU;
and supports graph refinement, regime discovery, latent-confounder correction,
missing and mixed data, and optional causal effect estimation and
counterfactual analysis through DoWhy.

**Algorithms:**

- **CDNOTS** — Constraint-based discovery handling nonstationarity via a time-index node.
- **CDNOTS+** — PCMCI+-style two-phase skeleton (MCI conditioning on discovered parents), avoiding over-conditioning on dense graphs.
- **CEDAR** — Pairwise discovery for autoregressive processes using minimum-lag selection. O(d²) pairs.
- **GRACE / REAP** — Hybrid grow-shrink refinement of a directed candidate graph (CDNOTS by default, or any method's graph), by neural L0 gates (GRACE) or by regression (REAP).
- **Score-based** — LGES, TGES and GES (BIC score search over lag-embedded data), plus Lasso-VAR, VARLiNGAM and Granger causality.

**Also:** `causal-ts inspect` / `inspect_df` recommend a configuration from the data; LUCID corrects a discovered graph for latent confounders; effect estimation, SCMs and counterfactuals through DoWhy; regime discovery; missing and mixed discrete-continuous data; PCMCI/PCMCI+/LPCMCI through tigramite.

**CI Tests:** Run `causal-ts ci-test-info` for a full selection guide.

| Test | Type | Speed |
|------|------|-------|
| `parcorr-gpu` | Linear | instant |
| `gcmi` | Monotone nonlinear | instant |
| `raft` / `rift` | Random-feature F-test (conditional mean) | fast |
| `rcot` | Nonlinear (RFF, full CI) | fast |
| `splitkci` | Nonlinear (kernel) | moderate |
| `linsig` | Path-space (linear signature) | moderate |
| `kci` | Nonlinear (kernel) | slow |
| `dfcit` | Distribution-free | moderate |
| `gcm` | Residual score (regression) | fast |
| `wgcm` / `pcm` | Residual score (regression) | moderate |
| `cmiknn-gpu` | Nonparametric (k-NN) | slow |
| `cmiknn-mixed-gpu` | Mixed discrete-continuous (k-NN) | slow |


## Getting Started

### Installation

Install the latest release from PyPI with pip or
[uv](https://docs.astral.sh/uv/):

```bash
# Option 1: pip
pip install causalts

# Option 2 (recommended): uv
uv venv  # create a virtual env
uv pip install causalts
```

For development, clone the repository:

```bash
git clone https://github.com/bloomberg/causal-ts.git
cd causal-ts
```

```bash
# Option 1: pip
pip install -e ".[dev,dowhy,tigramite]"

# Option 2 (recommended): uv
uv venv  # create a virtual env
uv pip install -e ".[dev,dowhy,tigramite]"
```

PyTorch is installed automatically. CUDA and Apple MPS are auto-detected at
runtime; CPU is the fallback.

To let a coding agent drive causal-ts, run `causal-ts install-skill` — see the
[CLI reference](https://causal-ts.readthedocs.io/en/latest/cli.html#install-skill).

## Quick Start

On your own data (a CSV with one column per variable, rows in time order):

```bash
causal-ts inspect data.csv                                       # data health + recommended settings
causal-ts discover data.csv -a cdnots --ci-test raft --max-lag 3 # learn the causal graph
```

Use the CI test and settings that `inspect` recommends; `raft` is a fast
nonlinear choice, while the default `parcorr-gpu` assumes linear relations.

### Reproducible example with known ground truth

```python
from causalts.synthetic_data.synthetic_datasets import load_dataset
from causalts.ci_tests import RAFTCI
from causalts import run_cdnots
from causalts.utils import evaluate_graph
from causalts.plotting import compare_graphs

# 1. Load a built-in dataset (ex1: 5-var nonlinear)
data = load_dataset("ex1", seed=42, T=500)
df, ground_truth = data["df"], data["ground_truth"]

# 2. Run CDNOTS causal discovery
ci_test = RAFTCI(df.values)   # fast nonlinear (conditional-mean) test
res = run_cdnots(
    df=df, indep_test=ci_test, num_lags=data["max_lag"],
    include_C=True, alpha=0.05, stable=True,
)

# 3. Evaluate (exclude C dimension for shape match with ground truth)
d = ground_truth.shape[0]
metrics = evaluate_graph(res.cg_tig[:d, :d, :], ground_truth)
print(f"F1={metrics['F1']:.3f}, SHD={metrics['SHD']}")

# 4. Visualize
res.plot()
compare_graphs(ground_truth, res.cg_tig[:d, :d, :], var_names=list(df.columns))
```

## Roadmap

See the [open issues](https://github.com/bloomberg/causal-ts/issues) for a list
of proposed features (and known issues).

## Contributing

Contributions are what make the open source community such an amazing place to
learn, inspire, and create. Any contributions you make are **greatly
appreciated**. For detailed contributing guidelines, please see
[CONTRIBUTING.md](https://github.com/bloomberg/causal-ts/blob/main/CONTRIBUTING.md).

## License

Distributed under the `GPL-3.0-or-later` License. See [LICENSE](https://github.com/bloomberg/causal-ts/blob/main/LICENSE) for
more information.

This project includes modified code from third-party packages. See
[NOTICE](https://github.com/bloomberg/causal-ts/blob/main/NOTICE) for details on original authorship and licensing.

## Contact

Mohammad Fesanghary - [@fesanghary](https://twitter.com/fesanghary)

Project Link:
[https://github.com/bloomberg/causal-ts](https://github.com/bloomberg/causal-ts)

## Acknowledgements

We thank the open source contributors to Tigramite and causal-learn whose implementations informed parts of Causal-TS’s design. This template was adapted from [Best-README-Template](https://github.com/othneildrew/Best-README-Template).

## Citations

If you use causal-ts in your research, please cite the following papers:

1. **Causal-TS: A Python Library for Causal Discovery in Stationary and Nonstationary Time Series**
   Mohammad Fesanghary
   arXiv preprint [arXiv:2607.24673](https://arxiv.org/abs/2607.24673), 2026.

2. **CEDAR: Causal Edge Discovery for Autoregressive Processes**
   Mohammad Fesanghary
   arXiv preprint [arXiv:2607.20696](https://arxiv.org/abs/2607.20696), 2026.

3. **GRACE: Gated Refinement for Accurate Causal Edge Discovery in High-Dimensional Time Series**
   Mohammad Fesanghary, Abhinav Havaldar
   arXiv preprint [arXiv:2606.23880](https://arxiv.org/abs/2606.23880), 2026.

4. **LUCID: Learning Under Confounding for Inference and Discovery in Time Series**
   Mohammad Fesanghary
   arXiv preprint [arXiv:2609.31315](https://arxiv.org/abs/2609.31315), 2026.

5. **Causal Discovery from Nonstationary Time Series**
   Agathe Sadeghi, Achintya Gopal, Mohammad Fesanghary
   *International Journal of Data Science and Analytics*, 19, pp. 33–59, 2025.
   [doi:10.1007/s41060-024-00679-7](https://doi.org/10.1007/s41060-024-00679-7)

<details>
<summary>BibTeX entries</summary>

```bibtex
@article{fesanghary2026causalts,
  title={Causal-TS: A Python Library for Causal Discovery in Stationary and Nonstationary Time Series},
  author={Fesanghary, Mohammad},
  journal={arXiv preprint arXiv:2607.24673},
  year={2026}
}

@article{fesanghary2026cedar,
  title={CEDAR: Causal Edge Discovery for Autoregressive Processes},
  author={Fesanghary, Mohammad},
  journal={arXiv preprint arXiv:2607.20696},
  year={2026}
}

@article{fesanghary2026grace,
  title={GRACE: Gated Refinement for Accurate Causal Edge Discovery in High-Dimensional Time Series},
  author={Fesanghary, Mohammad and Havaldar, Abhinav},
  journal={arXiv preprint arXiv:2606.23880},
  year={2026}
}

@article{fesanghary2026lucid,
  title={LUCID: Learning Under Confounding for Inference and Discovery in Time Series},
  author={Fesanghary, Mohammad},
  journal={arXiv preprint arXiv:2609.31315},
  year={2026}
}

@article{sadeghi2025cdnots,
  title={Causal Discovery from Nonstationary Time Series},
  author={Sadeghi, Agathe and Gopal, Achintya and Fesanghary, Mohammad},
  journal={International Journal of Data Science and Analytics},
  volume={19},
  pages={33--59},
  year={2025},
  publisher={Springer},
  doi={10.1007/s41060-024-00679-7}
}
```

</details>

## Contributors

Thanks goes to these wonderful people
([emoji key](https://allcontributors.org/en/reference/emoji-key/)):

<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
  <tbody>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/fesanghary"><img src="https://avatars.githubusercontent.com/u/12377980?s=100" width="100px;" alt="Mohammad Fesanghary"/><br /><sub><b>Mohammad Fesanghary</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=fesanghary" title="Code">💻</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=fesanghary" title="Documentation">📖</a> <a href="#example-fesanghary" title="Examples">💡</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=fesanghary" title="Tests">⚠️</a> <a href="#infra-fesanghary" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="#maintenance-fesanghary" title="Maintenance">🚧</a> <a href="https://github.com/bloomberg/causal-ts/pulls?q=is%3Apr+reviewed-by%3Afesanghary" title="Reviewed Pull Requests">👀</a> <a href="https://github.com/bloomberg/causal-ts/issues?q=author%3Afesanghary" title="Bug reports">🐛</a> <a href="#ideas-fesanghary" title="Ideas, Planning, & Feedback">🤔</a> <a href="#promotion-fesanghary" title="Promotion">📣</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/Arun-Verma"><img src="https://avatars.githubusercontent.com/u/5639113?s=100" width="100px;" alt="Arun Verma"/><br /><sub><b>Arun Verma</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=Arun-Verma" title="Documentation">📖</a> <a href="#example-Arun-Verma" title="Examples">💡</a> <a href="#promotion-Arun-Verma" title="Promotion">📣</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/fbourgey"><img src="https://avatars.githubusercontent.com/u/10298716?s=100" width="100px;" alt="Florian Bourgey"/><br /><sub><b>Florian Bourgey</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=fbourgey" title="Documentation">📖</a> <a href="#maintenance-fbourgey" title="Maintenance">🚧</a> <a href="#ideas-fbourgey" title="Ideas, Planning, & Feedback">🤔</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/mittal-aakriti"><img src="https://avatars.githubusercontent.com/u/31776192?s=100" width="100px;" alt="Aakriti Mittal"/><br /><sub><b>Aakriti Mittal</b></sub></a><br /><a href="#tutorial-mittal-aakriti" title="Tutorials">✅</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/chaimhaas"><img src="https://avatars.githubusercontent.com/u/29457495?s=100" width="100px;" alt="Chaim Haas"/><br /><sub><b>Chaim Haas</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=chaimhaas" title="Documentation">📖</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/ChakriCherukuri"><img src="https://avatars.githubusercontent.com/u/5638994?s=100" width="100px;" alt="Chakri Cherukuri"/><br /><sub><b>Chakri Cherukuri</b></sub></a><br /><a href="#example-ChakriCherukuri" title="Examples">💡</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/hemv-857"><img src="https://avatars.githubusercontent.com/u/218273197?s=100" width="100px;" alt="Hemang Varshney"/><br /><sub><b>Hemang Varshney</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=hemv-857" title="Code">💻</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=hemv-857" title="Tests">⚠️</a> <a href="#infra-hemv-857" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
    </tr>
    <tr>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/jmlinx"><img src="https://avatars.githubusercontent.com/u/30658965?s=100" width="100px;" alt="Jimin Lin"/><br /><sub><b>Jimin Lin</b></sub></a><br /><a href="#tutorial-jmlinx" title="Tutorials">✅</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/kudala-bharani"><img src="https://avatars.githubusercontent.com/u/121555407?s=100" width="100px;" alt="Kudala Bharani Kumar Reddy"/><br /><sub><b>Kudala Bharani Kumar Reddy</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=kudala-bharani" title="Code">💻</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=kudala-bharani" title="Tests">⚠️</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/mikemikimike"><img src="https://avatars.githubusercontent.com/u/186855910?s=100" width="100px;" alt="mikemikimike"/><br /><sub><b>mikemikimike</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=mikemikimike" title="Code">💻</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=mikemikimike" title="Tests">⚠️</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=mikemikimike" title="Documentation">📖</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/jmes2build"><img src="https://avatars.githubusercontent.com/u/156470182?s=100" width="100px;" alt="James Lee"/><br /><sub><b>James Lee</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=jmes2build" title="Documentation">📖</a></td>
      <td align="center" valign="top" width="14.28%"><a href="https://github.com/lbarrosby"><img src="https://avatars.githubusercontent.com/u/70347936?s=100" width="100px;" alt="Lucas Barros"/><br /><sub><b>Lucas Barros</b></sub></a><br /><a href="https://github.com/bloomberg/causal-ts/commits?author=lbarrosby" title="Code">💻</a> <a href="https://github.com/bloomberg/causal-ts/commits?author=lbarrosby" title="Tests">⚠️</a> <a href="https://github.com/bloomberg/causal-ts/issues?q=author%3Albarrosby" title="Bug reports">🐛</a></td>
    </tr>
  </tbody>
</table>

<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->

<!-- ALL-CONTRIBUTORS-LIST:END -->
