Skip to main content

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

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, GrowShrinkTree
  • src/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

tetrad_port-0.2.3.tar.gz (169.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

tetrad_port-0.2.3-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12Windows x86-64

tetrad_port-0.2.3-cp312-cp312-musllinux_1_2_x86_64.whl (2.9 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

tetrad_port-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tetrad_port-0.2.3-cp312-cp312-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file tetrad_port-0.2.3.tar.gz.

File metadata

  • Download URL: tetrad_port-0.2.3.tar.gz
  • Upload date:
  • Size: 169.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for tetrad_port-0.2.3.tar.gz
Algorithm Hash digest
SHA256 98403a3db549ebc24d844c3d374926d86f76d1d44dffe9ccc46bd5438a28fb18
MD5 479c0053887359b20b74e928cef10b44
BLAKE2b-256 84210ec3c5408c2818a2949f8f8094e868af27cc644c8477f0c7d1e58abd717b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.2.3.tar.gz:

Publisher: publish.yml on kelvinlim/tetrad-port

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tetrad_port-0.2.3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.2.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 445905d49b7d525e5280f2531188e6227f70d2d4cc59e32e843ea58fb71a157e
MD5 613caa185fd7fc79e7b5880e77223157
BLAKE2b-256 3403a55943c03a06b630f82a6f4be3ca15b4e144aa1d10ec5ff61385e76c5137

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.2.3-cp312-cp312-win_amd64.whl:

Publisher: publish.yml on kelvinlim/tetrad-port

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tetrad_port-0.2.3-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.2.3-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 b3f107949593aeded93393c6cc3a04334b5e6f3bfa0c4c1c77bfcbe88d0ae0ef
MD5 bcb90407deb9ad10b91a9fc77ab90a2a
BLAKE2b-256 0b0f7b7f6908ebb465c3e73c837129138206e50a09b267407831825391acd9cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.2.3-cp312-cp312-musllinux_1_2_x86_64.whl:

Publisher: publish.yml on kelvinlim/tetrad-port

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tetrad_port-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 73d57220b01aa46fbb820350706d5495aa4ae6cc989e1e5a08e36771e3ddc6a7
MD5 7e12fcd41d58fc6131dc6fbfdab0acbf
BLAKE2b-256 43bd685f74fc7e5b23f835056a5ae98e70fe77510c8e2f5814ff9a2e71267d43

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.2.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: publish.yml on kelvinlim/tetrad-port

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file tetrad_port-0.2.3-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.2.3-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dad016bd095708ea074289ac8ddc99e95a5f6aef43b75a64678eaa287ba248c4
MD5 28aa5ceed75e17342029553cd744f10f
BLAKE2b-256 3e9a0aca520fc1f42f0c9b9fbe704728686e02dd03b3ad63f52830849e6ea56c

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.2.3-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: publish.yml on kelvinlim/tetrad-port

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page