Skip to content

Commit 41c53e2

Browse files
authored
Split notebooks test run mmm vs others (#1986)
1 parent ad48e67 commit 41c53e2

File tree

6 files changed

+84
-30
lines changed

6 files changed

+84
-30
lines changed

.github/workflows/test_notebook.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test Notebook
1+
name: Test Other Notebooks
22

33
on:
44
pull_request:
@@ -8,6 +8,7 @@ on:
88
- "tests/**.py"
99
- "pymc_marketing/**"
1010
- "docs/source/notebooks/**.ipynb"
11+
- "!docs/source/notebooks/mmm/**.ipynb"
1112
- "!docs/source/notebooks/*/dev/**.ipynb"
1213
push:
1314
branches: [main]
@@ -16,14 +17,15 @@ on:
1617
- "tests/**.py"
1718
- "pymc_marketing/**"
1819
- "docs/source/notebooks/**.ipynb"
20+
- "!docs/source/notebooks/mmm/**.ipynb"
1921
- "!docs/source/notebooks/*/dev/**.ipynb"
2022

2123
concurrency:
2224
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
2325
cancel-in-progress: true
2426

2527
jobs:
26-
example_notebooks:
28+
other_notebooks:
2729
runs-on: ubuntu-latest
2830
steps:
2931
- uses: actions/checkout@v5
@@ -35,5 +37,5 @@ jobs:
3537
run: |
3638
sudo apt-get install graphviz graphviz-dev
3739
pip install -e .[docs,test,dag]
38-
- name: Run notebooks
39-
run: make run_notebooks
40+
- name: Run non-MMM notebooks
41+
run: make run_notebooks_other
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Test MMM Notebooks
2+
3+
on:
4+
pull_request:
5+
branches: [main]
6+
paths:
7+
- "pyproject.toml"
8+
- "tests/**.py"
9+
- "pymc_marketing/**"
10+
- "docs/source/notebooks/mmm/**.ipynb"
11+
- "!docs/source/notebooks/*/dev/**.ipynb"
12+
push:
13+
branches: [main]
14+
paths:
15+
- "pyproject.toml"
16+
- "tests/**.py"
17+
- "pymc_marketing/**"
18+
- "docs/source/notebooks/mmm/**.ipynb"
19+
- "!docs/source/notebooks/*/dev/**.ipynb"
20+
21+
concurrency:
22+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
23+
cancel-in-progress: true
24+
25+
jobs:
26+
mmm_notebooks:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v5
30+
- name: Set up Python
31+
uses: actions/setup-python@v6
32+
with:
33+
python-version: "3.12"
34+
- name: Install dependencies
35+
run: |
36+
sudo apt-get install graphviz graphviz-dev
37+
pip install -e .[docs,test,dag]
38+
- name: Run MMM notebooks
39+
run: make run_notebooks_mmm

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ cleandocs: ## Clean the documentation build directories
4646
run_notebooks: ## Run Jupyter notebooks
4747
python scripts/run_notebooks/runner.py
4848

49+
run_notebooks_mmm: ## Run MMM Jupyter notebooks only
50+
python scripts/run_notebooks/runner.py --exclude-dirs clv bass customer_choice general
51+
52+
run_notebooks_other: ## Run non-MMM Jupyter notebooks
53+
python scripts/run_notebooks/runner.py --exclude-dirs mmm
54+
4955
uml: ## Install documentation dependencies and generate UML diagrams
5056
pip install .[docs]
5157
pyreverse pymc_marketing/mmm -d docs/source/uml -f 'ALL' -o png -p mmm

docs/source/notebooks/clv/clv_quickstart.ipynb

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
},
3939
{
4040
"cell_type": "code",
41-
"execution_count": 47,
41+
"execution_count": 1,
4242
"id": "65621d72",
4343
"metadata": {},
4444
"outputs": [],
@@ -3086,30 +3086,29 @@
30863086
},
30873087
{
30883088
"cell_type": "code",
3089-
"execution_count": 46,
3089+
"execution_count": 2,
30903090
"id": "d56da0f3-9f85-4972-898c-ba0490cdb12e",
30913091
"metadata": {},
30923092
"outputs": [
30933093
{
30943094
"name": "stdout",
30953095
"output_type": "stream",
30963096
"text": [
3097-
"Last updated: Sun Jul 27 2025\n",
3097+
"Last updated: Wed Oct 08 2025\n",
30983098
"\n",
30993099
"Python implementation: CPython\n",
31003100
"Python version : 3.12.11\n",
3101-
"IPython version : 9.4.0\n",
3101+
"IPython version : 9.3.0\n",
31023102
"\n",
31033103
"pymc : 5.25.1\n",
31043104
"pytensor: 2.31.7\n",
31053105
"\n",
3106-
"arviz : 0.22.0\n",
3107-
"pandas : 2.3.1\n",
3108-
"numpy : 2.2.6\n",
3109-
"pymc_marketing: 0.15.1\n",
31103106
"matplotlib : 3.10.3\n",
3111-
"pytensor : 2.31.7\n",
3107+
"arviz : 0.21.0\n",
31123108
"pymc_extras : 0.4.0\n",
3109+
"pymc_marketing: 0.15.1\n",
3110+
"numpy : 2.2.0\n",
3111+
"pandas : 2.3.0\n",
31133112
"\n",
31143113
"Watermark: 2.5.0\n",
31153114
"\n"
@@ -3125,7 +3124,7 @@
31253124
"metadata": {
31263125
"hide_input": false,
31273126
"kernelspec": {
3128-
"display_name": "Python 3 (ipykernel)",
3127+
"display_name": "Python 3",
31293128
"language": "python",
31303129
"name": "python3"
31313130
},

docs/source/notebooks/mmm/mmm_example.ipynb

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
3939
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
4040
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
41-
"<!-- Generated by graphviz version 13.1.1 (0)\n",
41+
"<!-- Generated by graphviz version 14.0.0 (20250921.2048)\n",
4242
" -->\n",
4343
"<!-- Pages: 1 -->\n",
4444
"<svg width=\"451pt\" height=\"116pt\"\n",
@@ -91,7 +91,7 @@
9191
"</svg>\n"
9292
],
9393
"text/plain": [
94-
"<graphviz.graphs.Digraph at 0x10aab01d0>"
94+
"<graphviz.graphs.Digraph at 0x104d4b380>"
9595
]
9696
},
9797
"execution_count": 1,
@@ -12215,31 +12215,23 @@
1221512215
},
1221612216
{
1221712217
"cell_type": "code",
12218-
"execution_count": 64,
12218+
"execution_count": 2,
1221912219
"metadata": {},
1222012220
"outputs": [
1222112221
{
1222212222
"name": "stdout",
1222312223
"output_type": "stream",
1222412224
"text": [
12225-
"Last updated: Thu Aug 07 2025\n",
12225+
"Last updated: Wed Oct 08 2025\n",
1222612226
"\n",
1222712227
"Python implementation: CPython\n",
1222812228
"Python version : 3.12.11\n",
12229-
"IPython version : 9.4.0\n",
12229+
"IPython version : 9.3.0\n",
1223012230
"\n",
1223112231
"pymc_marketing: 0.15.1\n",
1223212232
"pytensor : 2.31.7\n",
1223312233
"\n",
12234-
"seaborn : 0.13.2\n",
12235-
"pymc_extras : 0.4.0\n",
12236-
"matplotlib : 3.10.3\n",
12237-
"graphviz : 0.21\n",
12238-
"arviz : 0.22.0\n",
12239-
"pymc : 5.25.1\n",
12240-
"pymc_marketing: 0.15.1\n",
12241-
"pandas : 2.3.1\n",
12242-
"numpy : 2.2.6\n",
12234+
"graphviz: 0.21\n",
1224312235
"\n",
1224412236
"Watermark: 2.5.0\n",
1224512237
"\n"
@@ -12255,7 +12247,7 @@
1225512247
"metadata": {
1225612248
"hide_input": false,
1225712249
"kernelspec": {
12258-
"display_name": "pymc-marketing-dev",
12250+
"display_name": "Python 3",
1225912251
"language": "python",
1226012252
"name": "python3"
1226112253
},

scripts/run_notebooks/runner.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,12 @@ def parse_args():
105105
type=str,
106106
help="List of notebooks to run. If not provided, all notebooks will be run.",
107107
)
108+
parser.add_argument(
109+
"--exclude-dirs",
110+
nargs="+",
111+
type=str,
112+
help="List of directories to exclude (e.g., mmm clv)",
113+
)
108114
return parser.parse_args()
109115

110116

@@ -115,12 +121,22 @@ def parse_args():
115121
if args.notebooks:
116122
notebooks_to_run = [Path(notebook) for notebook in args.notebooks]
117123

124+
if args.exclude_dirs:
125+
exclude_set = set(args.exclude_dirs)
126+
notebooks_to_run = [
127+
nb for nb in notebooks_to_run if nb.parent.name not in exclude_set
128+
]
129+
118130
setup_logging()
119131
logging.info("Starting notebook runner")
120132
logging.info(f"Notebooks to run: {notebooks_to_run}")
121-
Parallel(n_jobs=-1)(
133+
results = Parallel(n_jobs=-1)(
122134
delayed(run_notebook)(**run_params)
123135
for run_params in run_parameters(notebooks_to_run)
124136
)
137+
del results
138+
import gc
139+
140+
gc.collect()
125141

126142
logging.info("Notebooks run successfully!")

0 commit comments

Comments
 (0)