C++ port of CMU's Tetrad causal discovery library with Python bindings
Project description
tetrad-port
C++ port of CMU's Tetrad causal inference library, with Python bindings via nanobind.
Algorithms
| Algorithm | Type | Output | Latent Confounders |
|---|---|---|---|
| PC | Constraint-based (Fisher Z) | CPDAG | No |
| FGES | Score-based (BIC) | CPDAG | No |
| GFCI | Hybrid (FGES + FCI rules) | PAG | Yes |
| BOSS | Permutation-based (BIC) | CPDAG | No |
| BOSS-FCI | BOSS + FCI rules | PAG | Yes |
| GRaSP | Permutation-based (tuck DFS) | CPDAG | No |
| GRaSP-FCI | GRaSP + FCI rules | PAG | Yes |
All algorithms support background knowledge: temporal tiers, forbidden edges, and required edges.
Quick Start
pip install -e ".[dev]"
import pandas as pd
from tetrad_port import TetradPort, Knowledge
tp = TetradPort()
df = pd.read_csv("data.csv")
# Run PC (constraint-based)
results, graph_info = tp.run_pc(df, alpha=0.05)
# Run FGES (score-based, faster for large graphs)
results, graph_info = tp.run_fges(df, penalty_discount=1.0)
# Run GFCI (handles latent confounders)
results, graph_info = tp.run_gfci(df, alpha=0.05)
# Run BOSS (permutation-based, often faster than FGES)
results, graph_info = tp.run_boss(df, penalty_discount=1.0)
# Run GRaSP (permutation-based with DFS tucks)
results, graph_info = tp.run_grasp(df, penalty_discount=1.0)
# Run BOSS-FCI or GRaSP-FCI (latent confounders)
results, graph_info = tp.run_boss_fci(df, alpha=0.05)
results, graph_info = tp.run_grasp_fci(df, alpha=0.05)
# Add background knowledge
k = Knowledge()
k.set_tier(0, ["Age", "Genetics"]) # Cannot be caused by later variables
k.set_tier(1, ["Exercise", "Diet"])
k.set_forbidden("Exercise", "Cholesterol")
k.set_required("Smoking", "BP")
results, graph_info = tp.run_pc(df, alpha=0.05, knowledge=k)
Building from Source
C++ standalone
cmake -B build -DCMAKE_BUILD_TYPE=Release
cmake --build build
./build/tetrad_tests # Run all C++ tests
./build/run_pc # Example CLI
Python package
pip install -e ".[dev]"
pytest tests/test_python_bindings.py -v
Documentation
- Python API Reference
- Examples
- Causal Discovery Tutorial — PC, FGES, and GFCI comparison
- Knowledge Tutorial — Temporal tiers, forbidden/required edges
Architecture
The C++ core lives in src/ under namespace tetrad:
src/graph/— Node, Edge, Graph (EdgeListGraph with TAIL/ARROW/CIRCLE endpoints)src/data/— DataSet (Eigen matrix wrapper), Knowledge (tiers, forbidden/required edges)src/search/— PC, FAS, MeekRules, FGES, FciOrient, GFCI, BOSS, BOSS-FCI, GRaSP, GRaSP-FCI, IndTestFisherZ, SemBicScore, GrowShrinkTreesrc/util/— ChoiceGenerator, SublistGenerator
Python bindings (bindings/tetrad_bindings.cpp) expose algorithms via nanobind. The TetradPort facade class (python/tetrad_port/__init__.py) provides a pandas-friendly API with SEM fitting helpers.
Dependencies
C++ (auto-fetched via CMake FetchContent):
- Eigen 3.4.0 — linear algebra
- Catch2 v3.5.2 — testing
- nanobind 2.0+ — Python bindings
Python:
- numpy, pandas (required)
- semopy (optional, SEM fitting)
Reference
Ported from Tetrad 7.6.8 (Java). This version contains critical FciOrient correctness fixes reviewed by Peter Spirtes.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tetrad_port-0.2.2.tar.gz.
File metadata
- Download URL: tetrad_port-0.2.2.tar.gz
- Upload date:
- Size: 168.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96da0765d229826cc35c7d62aa4aab0d0d6d99becd9b99e2bab55a7eb3866089
|
|
| MD5 |
cdb284c699574d1bdedc0aae0605789d
|
|
| BLAKE2b-256 |
faf73ed2971491c1bfa833f73a7bcd1c700ce8630815d1ab79cac243b93da31f
|
Provenance
The following attestation bundles were made for tetrad_port-0.2.2.tar.gz:
Publisher:
publish.yml on kelvinlim/tetrad-port
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tetrad_port-0.2.2.tar.gz -
Subject digest:
96da0765d229826cc35c7d62aa4aab0d0d6d99becd9b99e2bab55a7eb3866089 - Sigstore transparency entry: 1075468297
- Sigstore integration time:
-
Permalink:
kelvinlim/tetrad-port@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/kelvinlim
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tetrad_port-0.2.2-cp312-cp312-win_amd64.whl.
File metadata
- Download URL: tetrad_port-0.2.2-cp312-cp312-win_amd64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.12, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c24708a688df988892b2609a390a8cea51875e4936c3e9041e088ead4735953
|
|
| MD5 |
13e28f6531abe2eba588d742b4cdffb4
|
|
| BLAKE2b-256 |
ed6ba5389397797576621183dcc6e8a621077329b4f1e84c3323c9dd31715df7
|
Provenance
The following attestation bundles were made for tetrad_port-0.2.2-cp312-cp312-win_amd64.whl:
Publisher:
publish.yml on kelvinlim/tetrad-port
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tetrad_port-0.2.2-cp312-cp312-win_amd64.whl -
Subject digest:
2c24708a688df988892b2609a390a8cea51875e4936c3e9041e088ead4735953 - Sigstore transparency entry: 1075468417
- Sigstore integration time:
-
Permalink:
kelvinlim/tetrad-port@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/kelvinlim
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tetrad_port-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tetrad_port-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.12, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c99020b56d165fa751666633e9829a536b9d8ef1b4022676aa0dd37462245f8d
|
|
| MD5 |
0d9bc9c96c296c2b1951d52c944890af
|
|
| BLAKE2b-256 |
efd4a13dd8696d4de44f870818e748d4cdeb0e203b73e67efe1f5cd87cc851b9
|
Provenance
The following attestation bundles were made for tetrad_port-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl:
Publisher:
publish.yml on kelvinlim/tetrad-port
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tetrad_port-0.2.2-cp312-cp312-musllinux_1_2_x86_64.whl -
Subject digest:
c99020b56d165fa751666633e9829a536b9d8ef1b4022676aa0dd37462245f8d - Sigstore transparency entry: 1075468627
- Sigstore integration time:
-
Permalink:
kelvinlim/tetrad-port@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/kelvinlim
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tetrad_port-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: tetrad_port-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 2.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
83216432d1c2c2728db405e12cc5f9f69628c18893e117e8293a5620e1174142
|
|
| MD5 |
e28c1a47f3a5558a849c4d3df644256a
|
|
| BLAKE2b-256 |
295b40451b8c57dd7d1c836c12c20add89c5b9c54338056d453949a93c988d10
|
Provenance
The following attestation bundles were made for tetrad_port-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish.yml on kelvinlim/tetrad-port
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tetrad_port-0.2.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
83216432d1c2c2728db405e12cc5f9f69628c18893e117e8293a5620e1174142 - Sigstore transparency entry: 1075468747
- Sigstore integration time:
-
Permalink:
kelvinlim/tetrad-port@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/kelvinlim
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Trigger Event:
release
-
Statement type:
File details
Details for the file tetrad_port-0.2.2-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: tetrad_port-0.2.2-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 2.2 MB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c1593f03ff12fee760e97ee623f7aec83f5f9bf1d44ce56b38be271d5e0c845
|
|
| MD5 |
1e55a614756fa907234285042a27ca70
|
|
| BLAKE2b-256 |
3658935e92c54f7647f5834907fd7c434271ffbdc35c534694378d14e84940e5
|
Provenance
The following attestation bundles were made for tetrad_port-0.2.2-cp312-cp312-macosx_11_0_arm64.whl:
Publisher:
publish.yml on kelvinlim/tetrad-port
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tetrad_port-0.2.2-cp312-cp312-macosx_11_0_arm64.whl -
Subject digest:
3c1593f03ff12fee760e97ee623f7aec83f5f9bf1d44ce56b38be271d5e0c845 - Sigstore transparency entry: 1075468507
- Sigstore integration time:
-
Permalink:
kelvinlim/tetrad-port@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Branch / Tag:
refs/tags/v0.2.2 - Owner: https://github.com/kelvinlim
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@705fa615b9ad20e690d40a39cd7f240f869c4053 -
Trigger Event:
release
-
Statement type: