Skip to main content

Official implementation of the Greedy Ancestral Seach (GAS) algorithm from the paper 'On the Number of Conditional Independence Tests in Constraint-based Causal Discovery'.

Project description

Greedy Ancestral Search

Paper CI PyPI Python Version

Official implementation of the Greedy Ancestral Seach (GAS) algorithm from the paper "On the Number of Conditional Independence Tests in Constraint-based Causal Discovery".

Installation

To get started, you'll need Python 3.10 or newer. You can install greedy-ancestral-search directly from PyPI:

pip install greedy-ancestral-search

Usage

Here is a simple example of using GAS with an oracle d-separation tester to learn the essential graph from a randomly generated directed acyclic graph.

import random
import networkx as nx
from greedy_ancestral_search import greedy_ancestral_search

# 1. Define the set of nodes.
number_of_nodes = 10
nodes = set(range(number_of_nodes))

# 2. Create a random ground-truth DAG to simulate data.
edge_probability = 0.5
G = nx.DiGraph()
G.add_nodes_from(nodes)
for u in nodes:
    for v in nodes:
        if u < v and random.random() < edge_probability:
            G.add_edge(u, v)

# 3. Define a conditional independence tester function.
#    This function queries the ground-truth graph for d-separation.
#    In a real-world scenario, this would be a statistical test on data.
def oracle_tester(X, Y, condition_set):
    """Returns True if X and Y are d-separated by condition_set in G."""
    return nx.is_d_separator(G, X, Y, condition_set)

# 4. Run the GAS algorithm.
#    The function takes the set of nodes and the CI tester as input.
undirected_edges, directed_edges = greedy_ancestral_search(nodes, oracle_tester)

# The algorithm returns the edges of the learned essential graph.
print("Undirected Edges:", undirected_edges)
print("Directed Edges:", directed_edges)

Development

First, clone the repository:

git clone --recurse-submodules https://github.com/uhlerlab/greedy-ancestral-search.git
cd greedy-ancestral-search

Dependencies

This project uses uv for dependency management. For more information, see the official documentation. If you don't have uv, install it with the official script:

curl -LsSf https://astral.sh/uv/install.sh | sh

Then, install all development and runtime dependencies:

uv sync --all-groups

Tests

The test suite validates the algorithm's correctness by generating random DAGs and verifying that the algorithm output, using an oracle d-separation tester, corresponds to the correct essential graph. Tests are located in the tests/ directory.

To run the standard test suite:

uv run pytest

To run the comprehensive test suite, which uses larger graphs and more iterations (as used in our CI workflow):

export CI=1 && uv run pytest

Benchmarks

The benchmarks/ directory contains scripts for performance evaluation. To run a specific benchmark:

uv run benchmarks/<script>.py

Available scripts include:

  • benchmarks/airfoil.py
  • benchmarks/neighborhood-comparison.py
  • benchmarks/nodes-comparison.py
  • benchmarks/sample-size.py
  • benchmarks/scale-free-graphs.py
  • benchmarks/sergio.py

Citation

If you use GAS in your work, please cite:

@misc{mones2026numberconditionalindependencetests,
      title={On the Number of Conditional Independence Tests in Constraint-based Causal Discovery}, 
      author={Franquesa Mon\'{e}s, Marc and Zhang, Jiaqi and Uhler, Caroline},
      year={2026},
      eprint={2603.21844},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2603.21844}, 
}

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

greedy_ancestral_search-0.1.1.tar.gz (150.7 kB view details)

Uploaded Source

Built Distribution

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

greedy_ancestral_search-0.1.1-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file greedy_ancestral_search-0.1.1.tar.gz.

File metadata

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

File hashes

Hashes for greedy_ancestral_search-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2bdad73414a1496a06982b63ccd44bbfadc26b7b8f73b33d5979bf0d62bc3ce3
MD5 8f1c13b1290b91965c54743faa6b395b
BLAKE2b-256 b4c9d5f9ef6847d195e2e48fcddf9ef6a262a39438bb12fdfc9b8766382004bd

See more details on using hashes here.

Provenance

The following attestation bundles were made for greedy_ancestral_search-0.1.1.tar.gz:

Publisher: release.yaml on uhlerlab/greedy-ancestral-search

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

File details

Details for the file greedy_ancestral_search-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for greedy_ancestral_search-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 92c3207d8af04c8b78039aa827fae69915bdb30b9b322b6020ecb03329d825f2
MD5 7621833ee7edc2836f7a928765d616fe
BLAKE2b-256 7c3ee06bf57871fb888a4171202c3b0cea3ab6e135be2373bc24bf21607373b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for greedy_ancestral_search-0.1.1-py3-none-any.whl:

Publisher: release.yaml on uhlerlab/greedy-ancestral-search

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