Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding notebook tests #308

Merged
merged 28 commits into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
431bb17
adding notebook test
rfl-urbaniak Oct 11, 2023
b37a79f
added pip upgrade to workflow
rfl-urbaniak Oct 11, 2023
b5ababd
fixed path to requirements in the yml file
rfl-urbaniak Oct 11, 2023
136e0fa
added pytest installation to workflow
rfl-urbaniak Oct 11, 2023
f8617e8
fixed nbval install command
rfl-urbaniak Oct 11, 2023
28eff60
added graphviz and matplotlib to pip install
rfl-urbaniak Oct 11, 2023
f333bdc
moved notebook requirements away, added sns
rfl-urbaniak Oct 12, 2023
11e432e
adding setup-graphviz to steps
rfl-urbaniak Oct 12, 2023
f364240
fixing notebook requirements
rfl-urbaniak Oct 12, 2023
59cbd14
adding chirho to notebook requirements
rfl-urbaniak Oct 12, 2023
253a0b4
Humouring Sam, reverting to .[test]
rfl-urbaniak Oct 12, 2023
6c8019f
reverting
rfl-urbaniak Oct 12, 2023
f5c3386
remove notebook_requirements and add nbval to test dependencies (#318)
SamWitty Oct 17, 2023
2d27da5
added backdoor.ipynb to tested notebooks
rfl-urbaniak Oct 17, 2023
8614918
added cevae to notebook tests
rfl-urbaniak Oct 18, 2023
41b4c31
added dr_learner
rfl-urbaniak Oct 18, 2023
647ed3e
added mediation.ipynb to testing
rfl-urbaniak Oct 18, 2023
c72d1b6
adding a sciplex generated file to gitignore
rfl-urbaniak Oct 18, 2023
ca8381e
adding sdid to notebook tests
rfl-urbaniak Oct 18, 2023
4b9f198
added slc to notebook tests
rfl-urbaniak Oct 18, 2023
3b09f19
revert changes to cevae
rfl-urbaniak Nov 15, 2023
55dee80
removed cevae
rfl-urbaniak Nov 15, 2023
e5ce83a
re-run cevae.ipynb with the original settings
rfl-urbaniak Nov 15, 2023
162867f
Merge branch 'master'
rfl-urbaniak Nov 16, 2023
848f908
generalizing a .gitignore entry
rfl-urbaniak Nov 16, 2023
166d6ea
re-run dr_learner and mediation notebooks
rfl-urbaniak Nov 16, 2023
e7a451e
lowered num samples in mediation from 10k to 1k
rfl-urbaniak Nov 16, 2023
ea7143e
Merge branch 'master' of https://github.com/BasisResearch/causal_pyro…
SamWitty Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/test_notebooks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Test notebooks

on:
schedule:
- cron: '0 0 * * 6' # Run at midnight on Saturdays
push:
branches:
- master
pull_request:
branches:
- master
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.8]

steps:
- uses: actions/checkout@v2

- name: pip cache
uses: actions/cache@v2
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}


- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}

- name: Setup Graphviz
uses: ts-graphviz/setup-graphviz@v1

- name: Install Python packages from requirements.txt
run: |
pip install --upgrade pip
pip install -e .[test]

- name: Run Notebook Test
run: |
./scripts/test_notebooks.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ venv/
/.vscode

# Automatically generated files
docs/source/lightning_logs
docs/preconvert
docs/build
site/
out
*.matrix.gz
97 changes: 61 additions & 36 deletions docs/source/backdoor.ipynb

Large diffs are not rendered by default.

63 changes: 29 additions & 34 deletions docs/source/cevae.ipynb

Large diffs are not rendered by default.

68 changes: 38 additions & 30 deletions docs/source/dr_learner.ipynb

Large diffs are not rendered by default.

129 changes: 65 additions & 64 deletions docs/source/mediation.ipynb

Large diffs are not rendered by default.

169 changes: 91 additions & 78 deletions docs/source/sdid.ipynb

Large diffs are not rendered by default.

148 changes: 97 additions & 51 deletions docs/source/slc.ipynb

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions docs/source/tutorial_i.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import pyro\n",
"from pyro.distributions import Bernoulli\n",
"\n",
"smoke_test = ('CI' in os.environ)\n",
"num_samples = 1000 if not smoke_test else 10\n",
"num_iterations = 1000 if not smoke_test else 10\n",
"n_individuals = 10000 if not smoke_test else 10\n",
"\n",
"def causal_model(stress_pt, smokes_cpt, cancer_cpt):\n",
" stress = pyro.sample(\"stress\", Bernoulli(stress_pt))\n",
" smokes = pyro.sample(\"smokes\", Bernoulli(smokes_cpt[stress.long()]))\n",
Expand Down Expand Up @@ -223,7 +229,7 @@
" with pyro.plate(\"individuals\", n_individuals, dim=-1):\n",
" return causal_model(stress_pt, smokes_cpt, cancer_cpt)\n",
"\n",
"n_individuals = 10000\n",
"\n",
"\n",
"smokes_obs = population_causal_model(n_individuals, stress_pt, smokes_cpt, cancer_cpt)\n",
"# stress_obs, smokes_obs, cancer_obs = population_causal_model(n_individuals, stress_pt, smokes_cpt, cancer_cpt)\n",
Expand Down Expand Up @@ -455,7 +461,7 @@
}
],
"source": [
"predictive_int_fixed = pyro.infer.Predictive(population_forced_smokes_model, num_samples=1000, return_sites=(\"cancer\", \"_RETURN\"))\n",
"predictive_int_fixed = pyro.infer.Predictive(population_forced_smokes_model, num_samples=num_samples, return_sites=(\"cancer\", \"_RETURN\"))\n",
"prediction_int_fixed = predictive_int_fixed(n_individuals, stress_pt, smokes_cpt, cancer_cpt)\n",
"\n",
"visualize_proportions_single(prediction_int_fixed, \"Intervened Data - Fixed Parameters\")"
Expand Down Expand Up @@ -846,7 +852,7 @@
}
],
"source": [
"predictive_bayesian = pyro.infer.Predictive(bayesian_population_causal_model, num_samples=1000, return_sites=(\"cancer\", \"_RETURN\"))\n",
"predictive_bayesian = pyro.infer.Predictive(bayesian_population_causal_model, num_samples=num_samples, return_sites=(\"cancer\", \"_RETURN\"))\n",
"prediction_bayesian = predictive_bayesian(n_individuals)\n",
"visualize_proportions_multiple(prediction_bayesian, \"Observational Data - Uncertain Parameters\")"
]
Expand Down Expand Up @@ -914,7 +920,7 @@
}
],
"source": [
"predictive_int_bayesian = pyro.infer.Predictive(bayesian_population_forced_smokes_model, num_samples=1000, return_sites=(\"cancer\", \"_RETURN\"))\n",
"predictive_int_bayesian = pyro.infer.Predictive(bayesian_population_forced_smokes_model, num_samples=num_samples, return_sites=(\"cancer\", \"_RETURN\"))\n",
"prediction_int_bayesian = predictive_int_bayesian(n_individuals)\n",
"visualize_proportions_multiple(prediction_int_bayesian, \"Interventional Data - Uncertain Parameters\")"
]
Expand Down Expand Up @@ -1710,8 +1716,6 @@
"\n",
"svi = SVI(twin_model_conditioned, guide, adam, loss=elbo)\n",
"\n",
"num_iterations = 1000\n",
"\n",
"for j in range(num_iterations):\n",
" # calculate the loss and take a gradient step\n",
" loss = svi.step(n_individuals)\n",
Expand Down
5 changes: 5 additions & 0 deletions scripts/test_notebooks.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

INCLUDED_NOTEBOOKS="docs/source/tutorial_i.ipynb docs/source/backdoor.ipynb docs/source/dr_learner.ipynb docs/source/mediation.ipynb docs/source/sdid.ipynb docs/source/slc.ipynb"

CI=1 pytest --nbval-lax --dist loadscope -n auto $INCLUDED_NOTEBOOKS
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"sphinx_rtd_theme==1.3.0",
"myst_parser",
"nbsphinx",
"nbval",
],
},
python_requires=">=3.8",
Expand Down
Loading