Skip to content

Commit

Permalink
Merge pull request #6 from adam2392/cpdag
Browse files Browse the repository at this point in the history
[ENH] Adding cpdag class
  • Loading branch information
adam2392 authored Aug 17, 2022
2 parents 5bdd430 + 3506e1c commit 603efdf
Show file tree
Hide file tree
Showing 29 changed files with 4,435 additions and 1,038 deletions.
410 changes: 187 additions & 223 deletions .circleci/config.yml

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions .codespellignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
raison
GES
Binary file added .github/.DS_Store
Binary file not shown.
105 changes: 54 additions & 51 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: unit-tests
name: gh-ci-checks
concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}-${{ github.event.type }}
cancel-in-progress: true
Expand All @@ -10,12 +10,17 @@ on:
branches: [main]
paths:
- '**.py'
tags:
- 'v*.*.*'
workflow_dispatch:

jobs:
style:
timeout-minutes: 10
runs-on: ubuntu-latest
strategy:
matrix:
poetry-version: [1.1.14]
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -24,42 +29,36 @@ jobs:
with:
python-version: '3.9'
architecture: 'x64'
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off .[style]
- name: Run flake8
uses: py-actions/flake8@v2
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/[email protected]
with:
path: "pywhy_graphs"
- name: Run isort
uses: isort/isort-action@master
- name: Run black
uses: psf/black@stable
with:
options: "--check --verbose"
- name: Run codespell
uses: codespell-project/actions-codespell@master
with:
check_filenames: true
check_hidden: true
skip: './.git,./build,./.mypy_cache,./.pytest_cache'
ignore_words_file: ./.codespellignore
- name: Run pydocstyle
run: pydocstyle .
- name: Run mypy
uses: jpetrucciani/mypy-check@master
with:
path: './pywhy_graphs'
mypy_flags: '--config-file pyproject.toml'
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
run: pip install poetry-dynamic-versioning

# TODO: once poetry v1.2 is release, we want to only install dev dependencies
- name: Install dependencies
run: poetry install

# check formatting of the code style
- name: Check code formatting
run: poetry run poe check_format

# this applies various linting
- name: Lint codebase
run: poetry run poe lint

- name: Typecheck
run: poetry run poe typecheck

build:
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
os: [ubuntu, macos, windows]
python-version: [3.7, 3.8, 3.9, "3.10"]
python-version: [3.8, 3.9, "3.10"]
poetry-version: [1.1.14]
name: build ${{ matrix.os }} - py${{ matrix.python-version }}
runs-on: ${{ matrix.os }}-latest
defaults:
Expand All @@ -73,17 +72,25 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Install dependencies
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
run: pip install poetry-dynamic-versioning
- name: Install from source
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off .[build]
poetry install
- name: Test package install
run: python -c "import pywhy_graphs; print(pywhy_graphs.__version__)"
run: poetry run python -c "import pywhy_graphs; print(pywhy_graphs.__version__)"
- name: Remove package install
run: python -m pip uninstall -yq pywhy_graphs
- name: Check poetry lock file
run: poetry update --dry-run
- name: Build package
run: python -m build
run: poetry build
- name: Upload package distribution files
if: ${{ matrix.os == 'ubuntu' && matrix.python-version == '3.10' }}
uses: actions/upload-artifact@v3
with:
name: package
Expand All @@ -108,6 +115,7 @@ jobs:
matrix:
os: [ubuntu, macos, windows]
python-version: [3.8, "3.10"] # oldest and newest supported versions
poetry-version: [1.1.14]
networkx: [stable, main]
name: pytest ${{ matrix.os }} - py${{ matrix.python-version }} - Networkx ${{ matrix.networkx }}
runs-on: ${{ matrix.os }}-latest
Expand All @@ -117,32 +125,27 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
path: main # clone repository in a sub-directory
- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
architecture: 'x64'
- name: Install Qt dependencies
if: "matrix.os == 'ubuntu'"
run: |
sudo apt update
sudo apt install qt5-default
- name: Install package
- name: Install Poetry ${{ matrix.poetry-version }}
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}
- name: Install Poetry Dynamic Versioning Plugin
run: pip install poetry-dynamic-versioning
- name: Install packages via poetry
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off main/.[test]
# TODO: remove this eventually
python -m pip install --progress-bar off git+https://github.com/py-why/graphs
poetry install
- name: Install Networkx (main)
if: "matrix.networkx == 'main'"
run: |
python -m pip uninstall -yq networkx
pip uninstall -yq networkx
pip install --progress-bar off git+https://github.com/networkx/networkx
- name: Run pytest # headless via Xvfb on linux
uses: GabrielBB/[email protected]
with:
run: pytest main/pywhy_graphs --cov=main/pywhy_graphs --cov-report=xml --cov-config=main/pyproject.toml
run: poetry run poe unit_test
- name: Upload coverage stats to codecov
if: ${{ matrix.os == 'ubuntu' && matrix.python-version == '3.10' && matrix.networkx == 'stable' }}
uses: codecov/codecov-action@v3
Expand All @@ -168,7 +171,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --progress-bar off --upgrade pip setuptools wheel
python -m pip install --progress-bar off .[build]
python -m pip install --progress-bar off build twine
- name: Prepare environment
run: |
echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ jobs:
exit 0
fi
all_changelogs=$(cat ./docs/whats_new/v*.rst)
if [[ "$all_changelogs" =~ :gh:\`$PR_NUMBER\` ]]
if [[ "$all_changelogs" =~ :pr:\`$PR_NUMBER\` ]]
then
echo "Changelog has been updated."
# If the pull request is milestoned check the correspondent changelog
if exist -f ./docs/whats_new/v${TAGGED_MILESTONE:0:4}.rst
then
expected_changelog=$(cat ./docs/whats_new/v${TAGGED_MILESTONE:0:4}.rst)
if [[ "$expected_changelog" =~ :gh:\`$PR_NUMBER\` ]]
if [[ "$expected_changelog" =~ :pr:\`$PR_NUMBER\` ]]
then
echo "Changelog and milestone correspond."
else
Expand All @@ -63,7 +63,7 @@ jobs:
echo "in time for the next release of pywhy-graphs."
echo ""
echo "Look at other entries in that file for inspiration and please"
echo "reference this pull request using the ':gh:' directive and"
echo "reference this pull request using the ':pr:' directive and"
echo "credit yourself (and other contributors if applicable) with"
echo "the ':user:' directive."
echo ""
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ __pycache__/
*$py.class

.vscode
junit-results.xml

# C extensions
*.so

.DS_Store
# Distribution / packaging
.Python
build/
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# simple makefile to simplify repetetive build env management tasks under posix
# simple makefile to simplify repetitive build env management tasks under posix
# caution: testing won't work on windows

PYTHON ?= python
Expand Down
54 changes: 0 additions & 54 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,59 +23,5 @@ graphs encountered in the literature.
.. autosummary::
:toctree: generated/

StructuralCausalModel
CPDAG
ADMG
PAG

To see a breakdown of different inner graph functionalities,
see the :ref:`Graph API <graph_api>` page. See

.. toctree::
:maxdepth: 0

graph_api


IO for reading/writing causal graphs
====================================
We advocate for using our implemented causal graph classes whenever
utilizing various packages. However, we also support transformations
to and from popular storage classes, such as ``numpy arrays``,
``pandas dataframes``, ``pgmpy``, ``DOT`` and ``dagitty``. Note that
not all these are supported for all types of graphs because of
inherent limitations in supporting mixed-edge graphs in other formats.

.. currentmodule:: pywhy_graphs.io

.. autosummary::
:toctree: generated/

load_from_networkx
load_from_numpy
load_from_pgmpy
to_networkx
to_numpy

Converting Graphs
=================
.. currentmodule:: pywhy_graphs.algorithms

.. autosummary::
:toctree: generated/

dag2cpdag
admg2pag

Utility Algorithms for Causal Graphs
====================================
.. currentmodule:: pywhy_graphs.algorithms

.. autosummary::
:toctree: generated/

discriminating_path
possibly_d_sep_sets
uncovered_pd_path
is_markov_equivalent
compute_v_structures
Loading

0 comments on commit 603efdf

Please sign in to comment.