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

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)

# 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, IndTestFisherZ, SemBicScore
  • 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.1.0.tar.gz (112.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.1.0-cp312-cp312-win_amd64.whl (2.2 MB view details)

Uploaded CPython 3.12Windows x86-64

tetrad_port-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl (2.8 MB view details)

Uploaded CPython 3.12musllinux: musl 1.2+ x86-64

tetrad_port-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

tetrad_port-0.1.0-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.1.0.tar.gz.

File metadata

  • Download URL: tetrad_port-0.1.0.tar.gz
  • Upload date:
  • Size: 112.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.1.0.tar.gz
Algorithm Hash digest
SHA256 97287c1efd4b9c176149a1e0cd8cf35e0d0c485babf4dc16402fc4f8b418e942
MD5 4c38c6e5dac98792de3a0a743abf9733
BLAKE2b-256 90b2206766b52c14114ddcf55e32cce89719bd449b5c3f214fa537a2b25fd06b

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.1.0.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.1.0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.1.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 aaf01de02e2b6996fc6c3ec8675fbd9f5708a6ed1d7f2dfbdcca72ba5516b771
MD5 e256dc75dfc4a4e486819fb6855a3847
BLAKE2b-256 35e06c280254efcf69e027dd6b4529e8f53c330716449e65e88ee492175efbd1

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.1.0-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.1.0-cp312-cp312-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.1.0-cp312-cp312-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 2c5aa9c334bc3755cb8eb4335ce59d71dda6b600cb2117d5de58701ee06d6ea0
MD5 d800d52b90de69406d33e75bb5b825a3
BLAKE2b-256 4b78f5d5abe6227415fff63bbc38f38765bd84054bc701a6252ed7e305c337da

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.1.0-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.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.1.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7fe32f56644f7308272a5ec2aedaf12123127d34d80c8c306617386e8e15d745
MD5 68da04955773445c9e92ad98990cbbab
BLAKE2b-256 a43c1959953e4cf7200597f04e153b855edfd82e58e91e292c0bfecd34735d0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.1.0-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.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for tetrad_port-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 260febf23a7b0016407acabd6a53ea92a68fc431124f148d3555995a9e873f92
MD5 d0352f0202d1c20de9a5839c4d35a9a4
BLAKE2b-256 ac96fced6d1f006c9b9f411db2392c722990ccb2a04ef0113ca41ec8705146be

See more details on using hashes here.

Provenance

The following attestation bundles were made for tetrad_port-0.1.0-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