|
| 1 | +# Notebook Runner |
| 2 | + |
| 3 | +This script runs Jupyter notebooks from `docs/source/notebooks/` to validate they execute without errors. |
| 4 | + |
| 5 | +## How It Works |
| 6 | + |
| 7 | +1. **Mocks `pm.sample()`** — Replaces MCMC sampling with prior predictive (1 chain × 100 draws) for speed |
| 8 | +2. **Uses Papermill** — Executes notebooks programmatically |
| 9 | +3. **Clears saved outputs** — Avoids widget state issues during execution |
| 10 | +4. **Guards widget updates** — Patches nbclient to ignore display_id assertion errors |
| 11 | +5. **Discards outputs** — Only checks for errors, doesn't save results |
| 12 | + |
| 13 | +## Dependencies |
| 14 | + |
| 15 | +The notebook runner mirrors the CI setup and expects a full docs/test environment. |
| 16 | + |
| 17 | +1. **Install Python dependencies** |
| 18 | + |
| 19 | + ```bash |
| 20 | + pip install -e ".[test,docs]" |
| 21 | + ``` |
| 22 | + |
| 23 | + This brings in Papermill, Jupyter, nbclient, and notebook-related dependencies. |
| 24 | + |
| 25 | +2. **Install Graphviz (system dependency)** |
| 26 | + |
| 27 | + - macOS: |
| 28 | + ```bash |
| 29 | + brew install graphviz |
| 30 | + ``` |
| 31 | + - Ubuntu/Debian: |
| 32 | + ```bash |
| 33 | + sudo apt-get update && sudo apt-get install -y graphviz |
| 34 | + ``` |
| 35 | + |
| 36 | +3. **Optional: parallel execution** |
| 37 | + |
| 38 | + ```bash |
| 39 | + pip install joblib |
| 40 | + ``` |
| 41 | + |
| 42 | +## Notes |
| 43 | + |
| 44 | +- The runner executes using the `python3` Jupyter kernel. Ensure your environment |
| 45 | + provides that kernel (e.g., from `ipykernel` installed via the docs extras). |
| 46 | +- The CI workflow uses Python 3.12 and installs the same extras. |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +```bash |
| 51 | +# Run all notebooks |
| 52 | +python scripts/run_notebooks/runner.py |
| 53 | +
|
| 54 | +# Run only PyMC notebooks |
| 55 | +python scripts/run_notebooks/runner.py --pattern "*_pymc*.ipynb" |
| 56 | +
|
| 57 | +# Run only sklearn notebooks |
| 58 | +python scripts/run_notebooks/runner.py --pattern "*_skl*.ipynb" |
| 59 | +
|
| 60 | +# Exclude PyMC and sklearn notebooks (run others) |
| 61 | +python scripts/run_notebooks/runner.py --exclude-pattern _pymc --exclude-pattern _skl |
| 62 | +
|
| 63 | +# Run notebooks in parallel (requires joblib) |
| 64 | +python scripts/run_notebooks/runner.py --parallel |
| 65 | +``` |
| 66 | + |
| 67 | +## CI Integration |
| 68 | + |
| 69 | +The GitHub Actions workflow (`.github/workflows/test_notebook.yml`) runs this script in parallel: |
| 70 | +- Job 1: PyMC notebooks |
| 71 | +- Job 2: Sklearn notebooks |
| 72 | +- Job 3: Other notebooks |
| 73 | + |
| 74 | +## Files |
| 75 | + |
| 76 | +- `runner.py` — Main script |
| 77 | +- `injected.py` — Code injected into notebooks to mock `pm.sample()` |
| 78 | +- `skip_notebooks.yml` — List of notebooks to skip (incompatible with mock sampling) |
0 commit comments