Skip to content

Commit

Permalink
Merge branch 'main' into aryan_valid_pag
Browse files Browse the repository at this point in the history
  • Loading branch information
aryan26roy authored Jan 6, 2024
2 parents f8b07e1 + 6c3ee23 commit 4015667
Show file tree
Hide file tree
Showing 22 changed files with 1,037 additions and 28 deletions.
19 changes: 10 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python 3.9
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.9"
architecture: "x64"
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v2.3.0
uses: abatilo/actions-poetry@v2.4.0
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
Expand Down Expand Up @@ -69,12 +69,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: "x64"
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v2.3.0
uses: abatilo/actions-poetry@v2.4.0
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
Expand All @@ -92,7 +92,7 @@ jobs:
run: poetry build
- name: Upload package distribution files
if: ${{ matrix.os == 'ubuntu' && matrix.python-version == '3.11' }}
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: package
path: dist
Expand Down Expand Up @@ -130,12 +130,12 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
architecture: "x64"
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/actions-poetry@v2.3.0
uses: abatilo/actions-poetry@v2.4.0
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
Expand All @@ -158,6 +158,7 @@ jobs:
if: "matrix.os == 'ubuntu'"
shell: bash
run: |
sudo apt-get update
sudo apt-get install nvidia-cuda-toolkit nvidia-cuda-toolkit-gcc
- name: Run pytest # headless via Xvfb on linux
Expand All @@ -180,7 +181,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.9
architecture: "x64"
Expand All @@ -193,7 +194,7 @@ jobs:
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Download package distribution files
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: package
path: dist
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ To install the package from github, clone the repository and then `cd` into the

Pywhy-Graphs is always looking for new contributors to help make the package better, whether it is algorithms, documentation, examples of graph usage, and more! Contributing to Pywhy-Graphs will be rewarding because you will contribute to a much needed package for causal inference.

See our [contributing guide](https://github.com/py-why/pywhy-graphs/CONTRIBUTING.md) for more details.
See our [contributing guide](https://github.com/py-why/pywhy-graphs/blob/main/CONTRIBUTING.md) for more details.

# Citing

Expand Down
22 changes: 22 additions & 0 deletions doc/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,28 @@ causal graph operations.
find_connected_pairs
add_all_snode_combinations
compute_invariant_domains_per_node
is_semi_directed_path
all_semi_directed_paths

:mod:`pywhy_graphs.algorithms`: Algorithms for dealing with CPDAGs
==================================================================
With Markov equivalence classes of DAGs in a Markovian SCM setting, we obtain
a potentially directed acyclic graph (PDAG), which may be completed (CPDAG).
We may want to generate a consistent DAG extension (i.e. Markov equivalent) of a CPDAG
then we may use some of the algorithms described here. Or perhaps one may want to
convert a DAG to its corresponding CPDAG.

.. currentmodule:: pywhy_graphs.algorithms

.. autosummary::
:toctree: generated/

pdag_to_dag
dag_to_cpdag
pdag_to_cpdag
order_edges
label_edges


Conversions between other package's causal graphs
=================================================
Expand Down
8 changes: 5 additions & 3 deletions doc/installation.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Installation
============

**pywhy-graphs** supports Python >= 3.8.
**pywhy-graphs** closely follows the NetworkX dependencies and thus supports Python >= 3.9.

## Installing with ``pip``
Installing with ``pip``
-----------------------

**pywhy-graphs** is available [on PyPI](https://pypi.org/project/pywhy-graphs/). Just run

Expand All @@ -12,7 +13,8 @@ Installation
# or if you use poetry which is recommended
poetry add pywhy-graphs

## Installing from source
Installing from source
----------------------

To install **pywhy-graphs** from source, first clone [the repository](https://github.com/py-why/pywhy-graphs):

Expand Down
12 changes: 12 additions & 0 deletions doc/reference/algorithms/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ Algorithms for handling acyclicity
:toctree: ../../generated/

acyclification


***************************************
Semi-directed (possibly-directed) Paths
***************************************

.. automodule:: pywhy_graphs.algorithms.semi_directed_paths
.. autosummary::
:toctree: ../../generated/

all_semi_directed_paths
is_semi_directed_path
10 changes: 10 additions & 0 deletions doc/references.bib
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ @article{bareinboim_causal_2016
pages = {7345--7352}
}

@article{chickering2002learning,
title = {Learning equivalence classes of Bayesian-network structures},
author = {Chickering, David Maxwell},
journal = {The Journal of Machine Learning Research},
volume = {2},
pages = {445--498},
year = {2002},
publisher = {JMLR}
}

@article{Colombo2012,
author = {Diego Colombo and Marloes H. Maathuis and Markus Kalisch and Thomas S. Richardson},
title = {{Learning high-dimensional directed acyclic graphs with latent and selection variables}},
Expand Down
2 changes: 2 additions & 0 deletions doc/whats_new/v0.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Changelog
- |Feature| Implement and test functions to convert a DAG to MAG, by `Aryan Roy`_ (:pr:`96`)
- |Feature| Implement and test functions to convert a PAG to MAG, by `Aryan Roy`_ (:pr:`93`)
- |API| Remove support for Python 3.8 by `Adam Li`_ (:pr:`99`)
- |Feature| Implement a suite of functions for finding and checking semi-directed paths on a mixed-edge graph, by `Adam Li`_ (:pr:`101`)
- |Feature| Implement functions for converting between a DAG and PDAG and CPDAG for generating consistent extensions of a CPDAG for example. These functions are :func:`pywhy_graphs.algorithms.pdag_to_cpdag`, :func:`pywhy_graphs.algorithms.pdag_to_dag` and :func:`pywhy_graphs.algorithms.dag_to_cpdag`, by `Adam Li`_ (:pr:`102`)

Code and Documentation Contributors
-----------------------------------
Expand Down
9 changes: 2 additions & 7 deletions examples/mixededge/plot_mixed_edge_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,8 @@
# %%
# Construct a MixedEdgeGraph
# --------------------------
# Using the ``MixedEdgeGraph``, we can represent a causal graph
# with two different kinds of edges. To create the graph, we
# use networkx ``nx.DiGraph`` class to represent directed edges,
# and ``nx.Graph`` class to represent edges without directions (i.e.
# bidirected edges). The edge types are then specified, so the mixed edge
# graph object knows which graphs are associated with which types of edges.
# Here we demonstrate how to construct a mixed edge graph
# by composing networkx graphs.

directed_G = nx.DiGraph(
[
Expand All @@ -60,7 +56,6 @@
name="IV Graph",
)

# Compute the multipartite_layout using the "layer" node attribute
pos = nx.spring_layout(G)

# we can then visualize the mixed-edge graph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
cpdag.orient_uncertain_edge("x", "y")
cpdag.orient_uncertain_edge("xy", "y")
cpdag.orient_uncertain_edge("z", "y")

# create a PAG from the CPDAG, with all undirected edges
pag = PAG()
pag.add_edges_from(G.edges, cpdag.undirected_edge_name)

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exclude_dirs = ["tests"]

[tool.black]
line-length = 100
target-version = ['py38']
target-version = ['py39']
include = '\.pyi?$'
extend-exclude = '''
(
Expand Down Expand Up @@ -102,10 +102,10 @@ readme = "README.md"
classifiers = [
'Development Status :: 4 - Beta',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11'
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12'
]
keywords = ['causality', 'graphs', 'causal-inference', 'graphical-model']

Expand Down
2 changes: 2 additions & 0 deletions pywhy_graphs/algorithms/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from .cpdag import * # noqa: F403
from .cyclic import * # noqa: F403
from .generic import * # noqa: F403
from .multidomain import * # noqa: F403
from .pag import * # noqa: F403
from .semi_directed_paths import * # noqa: F403
Loading

0 comments on commit 4015667

Please sign in to comment.