{"id":13570222,"url":"https://github.com/y0-causal-inference/y0","last_synced_at":"2025-04-04T06:32:05.406Z","repository":{"id":43218741,"uuid":"328745468","full_name":"y0-causal-inference/y0","owner":"y0-causal-inference","description":"❓y0 (pronounced \"why not?\") is for causal inference in Python","archived":false,"fork":false,"pushed_at":"2025-03-13T23:14:38.000Z","size":6246,"stargazers_count":50,"open_issues_count":54,"forks_count":10,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-03-14T00:26:18.608Z","etag":null,"topics":["causal-inference","structural-causal-model","symbolic-math"],"latest_commit_sha":null,"homepage":"https://y0.readthedocs.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/y0-causal-inference.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-11T17:46:13.000Z","updated_at":"2025-03-07T07:17:38.000Z","dependencies_parsed_at":"2023-02-09T16:16:25.403Z","dependency_job_id":"682b3218-6620-4a89-895d-439e39ea378a","html_url":"https://github.com/y0-causal-inference/y0","commit_stats":{"total_commits":168,"total_committers":3,"mean_commits":56.0,"dds":"0.029761904761904767","last_synced_commit":"5dee9e2c687460d2339456b70e90842241b42a54"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y0-causal-inference%2Fy0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y0-causal-inference%2Fy0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y0-causal-inference%2Fy0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/y0-causal-inference%2Fy0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/y0-causal-inference","download_url":"https://codeload.github.com/y0-causal-inference/y0/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247134745,"owners_count":20889408,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["causal-inference","structural-causal-model","symbolic-math"],"created_at":"2024-08-01T14:00:49.825Z","updated_at":"2025-04-04T06:32:00.395Z","avatar_url":"https://github.com/y0-causal-inference.png","language":"Python","funding_links":[],"categories":["Uncategorized"],"sub_categories":["Uncategorized"],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/source/logo.png\" height=\"120\"\u003e\n\u003c/p\u003e\n\n\u003ch1 align=\"center\"\u003e\n  y0\n\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests\"\u003e\n        \u003cimg alt=\"Tests\" src=\"https://github.com/y0-causal-inference/y0/workflows/Tests/badge.svg\" /\u003e\n    \u003c/a\u003e\n   \u003ca href=\"https://github.com/cthoyt/cookiecutter-python-package\"\u003e\n      \u003cimg alt=\"Cookiecutter template from @cthoyt\" src=\"https://img.shields.io/badge/Cookiecutter-snekpack-blue\" /\u003e \n   \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/y0\"\u003e\n        \u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/y0\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://pypi.org/project/y0\"\u003e\n        \u003cimg alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/y0\" /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/y0-causal-inference/y0/blob/main/LICENSE\"\u003e\n        \u003cimg alt=\"PyPI - License\" src=\"https://img.shields.io/pypi/l/y0\" /\u003e\n    \u003c/a\u003e\n    \u003ca href='https://y0.readthedocs.io/en/latest/?badge=latest'\u003e\n        \u003cimg src='https://readthedocs.org/projects/y0/badge/?version=latest' alt='Documentation Status' /\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://zenodo.org/badge/latestdoi/328745468\"\u003e\n        \u003cimg src=\"https://zenodo.org/badge/328745468.svg\" alt=\"DOI\"\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://github.com/psf/black\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/code%20style-black-000000.svg\" alt=\"Code style: black\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\n`y0` (pronounced \"why not?\") is Python code for causal inference.\n\n## 💪 Getting Started\n\n### Representing Probability Expressions\n\n`y0` has a fully featured internal domain specific language for representing\nprobability expressions:\n\n```python\nfrom y0.dsl import P, A, B\n\n# The probability of A given B\nexpr_1 = P(A | B)\n\n# The probability of A given not B\nexpr_2 = P(A | ~B)\n\n# The joint probability of A and B\nexpr_3 = P(A, B)\n```\n\nIt can also be used to manipulate expressions:\n\n```python\nfrom y0.dsl import P, A, B, Sum\n\nP(A, B).marginalize(A) == Sum[A](P(A, B))\nP(A, B).conditional(A) == P(A, B) / Sum[A](P(A, B))\n```\n\nDSL objects can be converted into strings with `str()` and parsed back\nusing `y0.parser.parse_y0()`.\n\nA full demo of the DSL can be found in this\n[Jupyter Notebook](https://github.com/y0-causal-inference/y0/blob/main/notebooks/DSL%20Demo.ipynb)\n\n### Representing Causality\n\n`y0` has a notion of acyclic directed mixed graphs built on top of\n`networkx` that can be used to model causality:\n\n```python\nfrom y0.graph import NxMixedGraph\nfrom y0.dsl import X, Y, Z1, Z2\n\n# Example from:\n#   J. Pearl and D. Mackenzie (2018)\n#   The Book of Why: The New Science of Cause and Effect.\n#   Basic Books, p. 240.\nnapkin = NxMixedGraph.from_edges(\n    directed=[\n        (Z2, Z1),\n        (Z1, X),\n        (X, Y),\n    ],\n    undirected=[\n        (Z2, X),\n        (Z2, Y),\n    ],\n)\n```\n\n`y0` has many pre-written examples in `y0.examples` from Pearl, Shpitser,\nBareinboim, and others.\n\n### do Calculus\n\n`y0` provides _actual_ implementations of many algorithms that have remained\nunimplemented for the last 15 years of publications including:\n\n| Algorithm          | Reference                                                                   |\n|--------------------|-----------------------------------------------------------------------------|\n| ID                 | [Shpitser and Pearl, 2006](https://dl.acm.org/doi/10.5555/1597348.1597382)  |\n| IDC                | [Shpitser and Pearl, 2008](https://www.jmlr.org/papers/v9/shpitser08a.html) |\n| ID*                | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |\n| IDC*               | [Shpitser and Pearl, 2012](https://arxiv.org/abs/1206.5294)                 |\n| Surrogate Outcomes | [Tikka and Karvanen, 2018](https://arxiv.org/abs/1806.07172)                |\n\nApply an algorithm to an ADMG and a causal query to generate an estimand\nrepresented in the DSL like:\n\n```python\nfrom y0.dsl import P, X, Y\nfrom y0.examples import napkin\nfrom y0.algorithm.identify import Identification, identify\n\n# TODO after ID* and IDC* are done, we'll update this interface\nquery = Identification.from_expression(graph=napkin, query=P(Y @ X))\nestimand = identify(query)\nassert estimand == P(Y @ X)\n```\n\n## 🚀 Installation\n\nThe most recent release can be installed from\n[PyPI](https://pypi.org/project/y0/) with:\n\n```bash\n$ pip install y0\n```\n\nThe most recent code and data can be installed directly from GitHub with:\n\n```bash\n$ pip install git+https://github.com/y0-causal-inference/y0.git\n```\n\n## 👐 Contributing\n\nContributions, whether filing an issue, making a pull request, or forking, are appreciated. See\n[CONTRIBUTING.md](https://github.com/y0-causal-inference/y0/blob/master/.github/CONTRIBUTING.md) for more information on getting\ninvolved.\n\n## 👋 Attribution\n\n### ⚖️ License\n\nThe code in this package is licensed under the [BSD-3-Clause\nlicense](https://github.com/y0-causal-inference/y0/blob/master/LICENSE).\n\n### 📖 Citation\n\nBefore we publish an application note on `y0`, you can cite this software\nvia our Zenodo record (also see the badge above):\n\n```bibtex\n@software{y0,\n  author       = {Charles Tapley Hoyt and\n                  Jeremy Zucker and\n                  Marc-Antoine Parent},\n  title        = {y0-causal-inference/y0},\n  month        = jun,\n  year         = 2021,\n  publisher    = {Zenodo},\n  version      = {v0.1.0},\n  doi          = {10.5281/zenodo.4950768},\n  url          = {https://doi.org/10.5281/zenodo.4950768}\n}\n```\n\n### 🙏 Supporters\n\nThis project has been supported by several organizations (in alphabetical order):\n\n- [Harvard Program in Therapeutic Science - Laboratory of Systems Pharmacology](https://hits.harvard.edu/the-program/laboratory-of-systems-pharmacology/)\n- [Pacific Northwest National Laboratory](https://www.pnnl.org/)\n\n### 💰 Funding\n\nThe development of the Y0 Causal Inference Engine has been funded by the following grants:\n\n| Funding Body                                             | Program                                                                                                                       | Grant           |\n|----------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|-----------------|\n| DARPA                                                    | [Automating Scientific Knowledge Extraction (ASKE)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction) | HR00111990009   |\n| PNNL Data Model Convergence Initiative    | [Causal Inference and Machine Learning Methods for Analysis of Security Constrained Unit Commitment (SCY0)](https://www.pnnl.gov/projects/dmc/converged-applications-projects) | 90001   |\n| DARPA                                                    |  [Automating Scientific Knowledge Extraction and Modeling (ASKEM)](https://www.darpa.mil/program/automating-scientific-knowledge-extraction-and-modeling) |  HR00112220036  |\n\n### 🍪 Cookiecutter\n\nThis package was created with [@audreyfeldroy](https://github.com/audreyfeldroy)'s\n[cookiecutter](https://github.com/cookiecutter/cookiecutter) package using [@cthoyt](https://github.com/cthoyt)'s\n[cookiecutter-snekpack](https://github.com/cthoyt/cookiecutter-snekpack) template.\n\n## 🛠️ For Developers\n\n\u003cdetails\u003e\n  \u003csummary\u003eSee developer instructions\u003c/summary\u003e\n\nThe final section of the README is for if you want to get involved by making a code contribution.\n\n### Development Installation\n\nTo install in development mode, use the following:\n\n```bash\ngit clone git+https://github.com/y0-causal-inference/y0.git\ncd y0\npip install -e .\n```\n\n### Updating Package Boilerplate\n\nThis project uses `cruft` to keep boilerplate (i.e., configuration, contribution guidelines, documentation\nconfiguration)\nup-to-date with the upstream cookiecutter package. Update with the following:\n\n```shell\npip install cruft\ncruft update\n```\n\nMore info on Cruft's update command is\navailable [here](https://github.com/cruft/cruft?tab=readme-ov-file#updating-a-project).\n\n### 🥼 Testing\n\nAfter cloning the repository and installing `tox` with `pip install tox tox-uv`, \nthe unit tests in the `tests/` folder can be run reproducibly with:\n\n```shell\ntox -e py\n```\n\nAdditionally, these tests are automatically re-run with each commit in a\n[GitHub Action](https://github.com/y0-causal-inference/y0/actions?query=workflow%3ATests).\n\n### 📖 Building the Documentation\n\nThe documentation can be built locally using the following:\n\n```shell\ngit clone git+https://github.com/y0-causal-inference/y0.git\ncd y0\ntox -e docs\nopen docs/build/html/index.html\n``` \n\nThe documentation automatically installs the package as well as the `docs`\nextra specified in the [`pyproject.toml`](pyproject.toml). `sphinx` plugins\nlike `texext` can be added there. Additionally, they need to be added to the\n`extensions` list in [`docs/source/conf.py`](docs/source/conf.py).\n\nThe documentation can be deployed to [ReadTheDocs](https://readthedocs.io) using\n[this guide](https://docs.readthedocs.io/en/stable/intro/import-guide.html).\nThe [`.readthedocs.yml`](../../dev/y0/.readthedocs.yml) YAML file contains all the configuration you'll need.\nYou can also set up continuous integration on GitHub to check not only that\nSphinx can build the documentation in an isolated environment (i.e., with ``tox -e docs-test``)\nbut also that [ReadTheDocs can build it too](https://docs.readthedocs.io/en/stable/pull-requests.html).\n\n#### Configuring ReadTheDocs\n\n1. Log in to ReadTheDocs with your GitHub account to install the integration\n   at https://readthedocs.org/accounts/login/?next=/dashboard/\n2. Import your project by navigating to https://readthedocs.org/dashboard/import then clicking the plus icon next to\n   your repository\n3. You can rename the repository on the next screen using a more stylized name (i.e., with spaces and capital letters)\n4. Click next, and you're good to go!\n\n### 📦 Making a Release\n\n#### Configuring Zenodo\n\n[Zenodo](https://zenodo.org) is a long-term archival system that assigns a DOI to each release of your package.\n\n1. Log in to Zenodo via GitHub with this link: https://zenodo.org/oauth/login/github/?next=%2F. This brings you to a\n   page that lists all of your organizations and asks you to approve installing the Zenodo app on GitHub. Click \"grant\"\n   next to any organizations you want to enable the integration for, then click the big green \"approve\" button. This\n   step only needs to be done once.\n2. Navigate to https://zenodo.org/account/settings/github/, which lists all of your GitHub repositories (both in your\n   username and any organizations you enabled). Click the on/off toggle for any relevant repositories. When you make\n   a new repository, you'll have to come back to this\n\nAfter these steps, you're ready to go! After you make \"release\" on GitHub (steps for this are below), you can navigate\nto https://zenodo.org/account/settings/github/repository/y0-causal-inference/y0\nto see the DOI for the release and link to the Zenodo record for it.\n\n#### Registering with the Python Package Index (PyPI)\n\nYou only have to do the following steps once.\n\n1. Register for an account on the [Python Package Index (PyPI)](https://pypi.org/account/register)\n2. Navigate to https://pypi.org/manage/account and make sure you have verified your email address. A verification email\n   might not have been sent by default, so you might have to click the \"options\" dropdown next to your address to get to\n   the \"re-send verification email\" button\n3. 2-Factor authentication is required for PyPI since the end of 2023 (see\n   this [blog post from PyPI](https://blog.pypi.org/posts/2023-05-25-securing-pypi-with-2fa/)). This means\n   you have to first issue account recovery codes, then set up 2-factor authentication\n4. Issue an API token from https://pypi.org/manage/account/token\n\n#### Configuring your machine's connection to PyPI\n\nYou have to do the following steps once per machine. Create a file in your home directory called\n`.pypirc` and include the following:\n\n```ini\n[distutils]\nindex-servers =\n    pypi\n    testpypi\n\n[pypi]\nusername = __token__\npassword = \u003cthe API token you just got\u003e\n\n# This block is optional in case you want to be able to make test releases to the Test PyPI server\n[testpypi]\nrepository = https://test.pypi.org/legacy/\nusername = __token__\npassword = \u003can API token from test PyPI\u003e\n```\n\nNote that since PyPI is requiring token-based authentication, we use `__token__` as the user, verbatim.\nIf you already have a `.pypirc` file with a `[distutils]` section, just make sure that there is an `index-servers`\nkey and that `pypi` is in its associated list. More information on configuring the `.pypirc` file can\nbe found [here](https://packaging.python.org/en/latest/specifications/pypirc).\n\n#### Uploading to PyPI\n\nAfter installing the package in development mode and installing\n`tox` with `pip install tox tox-uv`,\nrun the following from the shell:\n\n```shell\ntox -e finish\n```\n\nThis script does the following:\n\n1. Uses [Bump2Version](https://github.com/c4urself/bump2version) to switch the version number in\n   the `pyproject.toml`, `CITATION.cff`, `src/y0/version.py`,\n   and [`docs/source/conf.py`](docs/source/conf.py) to not have the `-dev` suffix\n2. Packages the code in both a tar archive and a wheel using [`build`](https://github.com/pypa/build)\n3. Uploads to PyPI using [`twine`](https://github.com/pypa/twine).\n4. Push to GitHub. You'll need to make a release going with the commit where the version was bumped.\n5. Bump the version to the next patch. If you made big changes and want to bump the version by minor, you can\n   use `tox -e bumpversion -- minor` after.\n\n#### Releasing on GitHub\n\n1. Navigate\n   to https://github.com/y0-causal-inference/y0/releases/new\n   to draft a new release\n2. Click the \"Choose a Tag\" dropdown and select the tag corresponding to the release you just made\n3. Click the \"Generate Release Notes\" button to get a quick outline of recent changes. Modify the title and description\n   as you see fit\n4. Click the big green \"Publish Release\" button\n\nThis will trigger Zenodo to assign a DOI to your release as well.\n\n\u003c/details\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy0-causal-inference%2Fy0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fy0-causal-inference%2Fy0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fy0-causal-inference%2Fy0/lists"}