{"id":14970646,"url":"https://github.com/basisresearch/chirho","last_synced_at":"2025-05-16T06:06:41.274Z","repository":{"id":180158912,"uuid":"541701671","full_name":"BasisResearch/chirho","owner":"BasisResearch","description":"An experimental language for causal reasoning","archived":false,"fork":false,"pushed_at":"2025-05-01T01:28:12.000Z","size":300706,"stargazers_count":203,"open_issues_count":79,"forks_count":12,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-05-01T02:35:14.829Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://basisresearch.github.io/chirho/getting_started.html","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BasisResearch.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":"CONTRIBUTING.rst","funding":null,"license":"LICENSE.md","code_of_conduct":null,"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,"zenodo":null}},"created_at":"2022-09-26T17:20:11.000Z","updated_at":"2025-04-29T07:42:26.000Z","dependencies_parsed_at":"2023-09-25T19:00:37.724Z","dependency_job_id":"b19abada-a2b3-452c-aca1-8a62c8f6aaa0","html_url":"https://github.com/BasisResearch/chirho","commit_stats":{"total_commits":218,"total_committers":16,"mean_commits":13.625,"dds":0.6146788990825688,"last_synced_commit":"0f5dae6508842ff2014e032c474db138cdfa8d4a"},"previous_names":["basisresearch/chirho"],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Fchirho","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Fchirho/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Fchirho/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BasisResearch%2Fchirho/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BasisResearch","download_url":"https://codeload.github.com/BasisResearch/chirho/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478190,"owners_count":22077676,"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":[],"created_at":"2024-09-24T13:43:54.925Z","updated_at":"2025-05-16T06:06:36.265Z","avatar_url":"https://github.com/BasisResearch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"|Build Status|\n\n.. image:: docs/source/_static/img/chirho_logo_wide.png\n   :alt: ChiRho logo\n   :align: center\n\n.. index-inclusion-marker\n\nCausal Reasoning with ChiRho\n============================\n\nChiRho is a causal extension to the Pyro probabilistic programming\nlanguage. It was built to bridge the gap between the capabilities of\nmodern probabilistic programming systems, such as Pyro, and the needs of\npolicymakers, scientists, and AI researchers, who often want to use\nmodels to answer their questions about cause-and-effect relationships.\nAs a non-exhaustive set of examples, ChiRho makes it easier to\nanswer the following kinds of causal questions that appear frequently in\npractice.\n\n-  **Interventional**: *How many COVID-19 hospitalizations will occur if\n   the USA imposes a national mask mandate?*\n\n-  **Counterfactual**: *Given that 100,000 people were infected with\n   COVID-19 in the past month, how many would have been infected if a\n   mask mandate had been in place?*\n\n-  **Explanation**: *Why were 100,000 people infected with COVID-19 in\n   the past month?*\n\n-  **Causal structure discovery**: *What individual attributes influence\n   risk of COVID-19 hospitalization?*\n\nTo see how ChiRho supports causal reasoning, take a look at our `Tutorial \u003chttps://basisresearch.github.io/chirho/tutorial_i.html\u003e`_.\n\nInstallation\n------------\n\n**Install using pip:**\n\n.. code:: sh\n\n   pip install chirho\n\n**Install from source:**\n\n.. code:: sh\n\n   git clone git@github.com:BasisResearch/chirho.git\n   cd chirho\n   git checkout master\n   pip install .\n\n**Install with extra packages:**\n\nTo install the dependencies required to run the tutorials in\n``examples``/``tutorials`` directories, please use the following\ncommand:\n\n.. code:: sh\n\n   pip install chirho[extras] \n\nMake sure that the models come from the same release version of the\n`ChiRho source\ncode \u003chttps://github.com/BasisResearch/chirho/releases\u003e`__ as you\nhave installed.\n\nGetting Started\n---------------\n\nBelow is a simple example of how to use ChiRho to answer an\ninterventional question. For more in-depth examples, go to `Learn\nmore \u003c#learn-more\u003e`__.\n\n.. code:: python\n\n   import torch\n   import pyro\n   import pyro.distributions as dist\n   from chirho.interventional.handlers import do\n\n   pyro.set_rng_seed(101)\n\n   # Define a causal model with single confounder h\n   def model():\n       h = pyro.sample(\"h\", dist.Normal(0, 1))\n       x = pyro.sample(\"x\", dist.Normal(h, 1))\n       y = pyro.sample(\"y\", dist.Normal(x + h, 1))\n       return y\n\n   # Define a causal query (here intervening on x)\n   def queried_model():\n       return do(model, {\"x\": 1})\n\n   # Generate 10,000 samples from the observational distribution P(y) ~ N(0, 2)\n   obs_samples = pyro.infer.Predictive(model, num_samples=1000)()[\"y\"]\n\n   # Generate 10,000 samples from the interventional distribution P(y | do(X=1)) ~ N(1, 1)\n   int_samples = pyro.infer.Predictive(queried_model(), num_samples=1000)()[\"y\"]\n\nLearn more\n----------\n\nWe have written a number of tutorials and examples for ChiRho. We\nhave tried to choose simple examples that would be of interest to both\nthe causal inference and probabilistic programming communities: they\ncollectively span Pearl’s causal hierarchy (Pearl 2009), and\nmost are broadly applicable, empirically validated, have an\nunconventional or limited identification result, and make use of modern\nprobabilistic machine learning tools, like neural networks or stochastic\nvariational inference.\n\nOur examples demonstrate how real-world causal assumptions can be expressed as probabilistic programs \nand real-world causal estimands can be expressed as program transformations.\nThese example illustrate how ChiRho is compatible with any inference method \nimplemented in Pyro, including the kinds of scalable gradient-based\napproximations that power much of the modern probabilistic machine learning landscape.\n\n- `Tutorial \u003chttps://basisresearch.github.io/chirho/tutorial_i.html\u003e`_\n  - Key observations inspiring ChiRho's design and outlines a causal Bayesian workflow for using ChiRho to answer causal questions\n- `Example: Backdoor Adjustment Criteria \u003chttps://basisresearch.github.io/chirho/backdoor.html\u003e`_\n  - Adjusting for observed confounders\n- `Example: Causal Effect Variational Autoencoder \u003chttps://basisresearch.github.io/chirho/cevae.html\u003e`_\n  - Causal inference with deep models and proxy variables\n- `Example: Mediation analysis and (in)direct effects \u003chttps://basisresearch.github.io/chirho/mediation.html\u003e`_\n  - Mediation analysis for path specific effects\n- `Example: Estimating causal effects using instrumental variables \u003chttps://basisresearch.github.io/chirho/instrumental_var.html\u003e`_\n  - Causal effect estimation with instrumental variables\n- `Example: Deep structural causal model counterfactuals \u003chttps://basisresearch.github.io/chirho/deepscm.html\u003e`_\n  - Counterfactuals with normalizing flows\n- `Example: Structured Latent Confounders \u003chttps://basisresearch.github.io/chirho/slc.html\u003e`_\n  - Causal effect estimation when latent confounders are shared across groups\n- `Example: Synthetic difference-in-differences \u003chttps://basisresearch.github.io/chirho/sdid.html\u003e`_\n  - Counterfactual estimation from longitudinal data\n- `Example: Robust estimation with the DR learner \u003chttps://basisresearch.github.io/chirho/dr_learner.html\u003e`_\n  - Heterogeneous causal effect estimation with a misspecified model\n- `Example: Estimating the effects of drugs on gene expression \u003chttps://basisresearch.github.io/chirho/sciplex.html\u003e`_\n  - Causal inference with single-cell RNA-seq data\n- `Example: Causal reasoning in dynamical systems \u003chttps://basisresearch.github.io/chirho/dynamical_intro.html\u003e`_\n  - Causal inference with continuous-time dynamical systems\n- `Design notes \u003chttps://basisresearch.github.io/chirho/design_notes\u003e`_\n  - Technical implementation details of ChiRho using effect handlers\n\n*Note*: These tutorials and examples assume some familiarity with Pyro and\nprobabilistic programming. For introductory Pyro tutorials, please see\n`Additional background reading\nmaterial \u003c#additional-background-reading-material\u003e`__ below.\n\nDocumentation\n-------------\n- `Counterfactual \u003chttps://basisresearch.github.io/chirho/counterfactual.html\u003e`_\n  - Effect handlers for counterfactual world splitting\n- `Interventional \u003chttps://basisresearch.github.io/chirho/interventional.html\u003e`_\n  - Effect handlers for performing interventions\n- `Observational \u003chttps://basisresearch.github.io/chirho/observational.html\u003e`_\n  - Effect handler utilities for computing probabilistic quantities for \n  partially deterministic models which is useful for counterfactual reasoning\n- `Indexed \u003chttps://basisresearch.github.io/chirho/indexed.html\u003e`_\n  - Effect handler utilities for named indices in ChiRho which is useful for manipluating\n  and tracking counterfactual worlds\n- `Dynamical \u003chttps://basisresearch.github.io/chirho/dynamical.html\u003e`_\n  - Operations and effect handlers for counterfactual reasoning in dynamical systems\n- `Robust \u003chttps://basisresearch.github.io/chirho/robust.html\u003e`_\n  - Operations and effect handlers for robust estimation\n- `Explainable \u003chttps://basisresearch.github.io/chirho/explainable.html\u003e`_\n  - Operations and effect handlers for causal explanation\n  \nCaveats\n-------\nChiRho does not answer causal questions by magic. In fact, there is\nno escaping the fact that\n\n   *behind any causal conclusion there must lie some causal assumption,*\n\na phrase made famous by Judea Pearl (Pearl 2009). Instead,\nChiRho provides a substrate for writing causal assumptions as\nprobabilistic programs, and for writing causal questions in terms of\nprogram transformations.\n\nAdditional background reading material\n--------------------------------------\n\n-  Causal Probabilistic Programming Without Tears\n   https://drive.google.com/file/d/1Uzjg-vX77BdSnAcfpUcb-aIXxhnAPI24/view?usp=sharing\n-  Introduction to Pyro: \\ http://pyro.ai/examples/intro_long.html\n-  Tensor shapes in Pyro: \\ http://pyro.ai/examples/tensor_shapes.html\n-  A guide to programming with effect handlers in\n   Pyro \\ http://pyro.ai/examples/effect_handlers.html\n-  Minipyro: \\ http://pyro.ai/examples/minipyro.html\n-  Reparameterization of Pyro\n   programs: \\ https://docs.pyro.ai/en/stable/infer.reparam.html\n-  Optional: getting started with\n   NumPyro \\ https://num.pyro.ai/en/stable/getting_started.html\n\n\nReferences\n----------\nPearl, Judea. *Causality: Models, Reasoning and Inference*. 2nd ed. USA: Cambridge University Press, 2009.\n\n\n.. |Build Status| image:: https://github.com/BasisResearch/chirho/actions/workflows/test.yml/badge.svg\n   :target: https://github.com/BasisResearch/chirho/actions/workflows/test.yml\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasisresearch%2Fchirho","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbasisresearch%2Fchirho","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbasisresearch%2Fchirho/lists"}