diff --git a/.github/workflows/test_notebook.yml b/.github/workflows/test_notebook.yml index fd4294547..d4725d4c0 100644 --- a/.github/workflows/test_notebook.yml +++ b/.github/workflows/test_notebook.yml @@ -1,4 +1,4 @@ -name: Test Notebook +name: Test Other Notebooks on: pull_request: @@ -8,6 +8,7 @@ on: - "tests/**.py" - "pymc_marketing/**" - "docs/source/notebooks/**.ipynb" + - "!docs/source/notebooks/mmm/**.ipynb" - "!docs/source/notebooks/*/dev/**.ipynb" push: branches: [main] @@ -16,6 +17,7 @@ on: - "tests/**.py" - "pymc_marketing/**" - "docs/source/notebooks/**.ipynb" + - "!docs/source/notebooks/mmm/**.ipynb" - "!docs/source/notebooks/*/dev/**.ipynb" concurrency: @@ -23,7 +25,7 @@ concurrency: cancel-in-progress: true jobs: - example_notebooks: + other_notebooks: runs-on: ubuntu-latest steps: - uses: actions/checkout@v5 @@ -35,5 +37,5 @@ jobs: run: | sudo apt-get install graphviz graphviz-dev pip install -e .[docs,test,dag] - - name: Run notebooks - run: make run_notebooks + - name: Run non-MMM notebooks + run: make run_notebooks_other diff --git a/.github/workflows/test_notebook_mmm.yml b/.github/workflows/test_notebook_mmm.yml new file mode 100644 index 000000000..28d79b93f --- /dev/null +++ b/.github/workflows/test_notebook_mmm.yml @@ -0,0 +1,39 @@ +name: Test MMM Notebooks + +on: + pull_request: + branches: [main] + paths: + - "pyproject.toml" + - "tests/**.py" + - "pymc_marketing/**" + - "docs/source/notebooks/mmm/**.ipynb" + - "!docs/source/notebooks/*/dev/**.ipynb" + push: + branches: [main] + paths: + - "pyproject.toml" + - "tests/**.py" + - "pymc_marketing/**" + - "docs/source/notebooks/mmm/**.ipynb" + - "!docs/source/notebooks/*/dev/**.ipynb" + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + mmm_notebooks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Set up Python + uses: actions/setup-python@v6 + with: + python-version: "3.12" + - name: Install dependencies + run: | + sudo apt-get install graphviz graphviz-dev + pip install -e .[docs,test,dag] + - name: Run MMM notebooks + run: make run_notebooks_mmm diff --git a/Makefile b/Makefile index 64d6d8140..51e4165b6 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,12 @@ cleandocs: ## Clean the documentation build directories run_notebooks: ## Run Jupyter notebooks python scripts/run_notebooks/runner.py +run_notebooks_mmm: ## Run MMM Jupyter notebooks only + python scripts/run_notebooks/runner.py --exclude-dirs clv bass customer_choice general + +run_notebooks_other: ## Run non-MMM Jupyter notebooks + python scripts/run_notebooks/runner.py --exclude-dirs mmm + uml: ## Install documentation dependencies and generate UML diagrams pip install .[docs] pyreverse pymc_marketing/mmm -d docs/source/uml -f 'ALL' -o png -p mmm diff --git a/docs/source/notebooks/clv/clv_quickstart.ipynb b/docs/source/notebooks/clv/clv_quickstart.ipynb index d86c8d1a4..d96aa40e9 100644 --- a/docs/source/notebooks/clv/clv_quickstart.ipynb +++ b/docs/source/notebooks/clv/clv_quickstart.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 1, "id": "65621d72", "metadata": {}, "outputs": [], @@ -3086,7 +3086,7 @@ }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 2, "id": "d56da0f3-9f85-4972-898c-ba0490cdb12e", "metadata": {}, "outputs": [ @@ -3094,22 +3094,21 @@ "name": "stdout", "output_type": "stream", "text": [ - "Last updated: Sun Jul 27 2025\n", + "Last updated: Wed Oct 08 2025\n", "\n", "Python implementation: CPython\n", "Python version : 3.12.11\n", - "IPython version : 9.4.0\n", + "IPython version : 9.3.0\n", "\n", "pymc : 5.25.1\n", "pytensor: 2.31.7\n", "\n", - "arviz : 0.22.0\n", - "pandas : 2.3.1\n", - "numpy : 2.2.6\n", - "pymc_marketing: 0.15.1\n", "matplotlib : 3.10.3\n", - "pytensor : 2.31.7\n", + "arviz : 0.21.0\n", "pymc_extras : 0.4.0\n", + "pymc_marketing: 0.15.1\n", + "numpy : 2.2.0\n", + "pandas : 2.3.0\n", "\n", "Watermark: 2.5.0\n", "\n" @@ -3125,7 +3124,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, diff --git a/docs/source/notebooks/mmm/mmm_example.ipynb b/docs/source/notebooks/mmm/mmm_example.ipynb index 2d56fbfb7..dd5ed3393 100644 --- a/docs/source/notebooks/mmm/mmm_example.ipynb +++ b/docs/source/notebooks/mmm/mmm_example.ipynb @@ -38,7 +38,7 @@ "\n", "\n", - "\n", "\n", "\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 1, @@ -12215,31 +12215,23 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "Last updated: Thu Aug 07 2025\n", + "Last updated: Wed Oct 08 2025\n", "\n", "Python implementation: CPython\n", "Python version : 3.12.11\n", - "IPython version : 9.4.0\n", + "IPython version : 9.3.0\n", "\n", "pymc_marketing: 0.15.1\n", "pytensor : 2.31.7\n", "\n", - "seaborn : 0.13.2\n", - "pymc_extras : 0.4.0\n", - "matplotlib : 3.10.3\n", - "graphviz : 0.21\n", - "arviz : 0.22.0\n", - "pymc : 5.25.1\n", - "pymc_marketing: 0.15.1\n", - "pandas : 2.3.1\n", - "numpy : 2.2.6\n", + "graphviz: 0.21\n", "\n", "Watermark: 2.5.0\n", "\n" @@ -12255,7 +12247,7 @@ "metadata": { "hide_input": false, "kernelspec": { - "display_name": "pymc-marketing-dev", + "display_name": "Python 3", "language": "python", "name": "python3" }, diff --git a/scripts/run_notebooks/runner.py b/scripts/run_notebooks/runner.py index cdc3c286c..95b0a6b73 100644 --- a/scripts/run_notebooks/runner.py +++ b/scripts/run_notebooks/runner.py @@ -105,6 +105,12 @@ def parse_args(): type=str, help="List of notebooks to run. If not provided, all notebooks will be run.", ) + parser.add_argument( + "--exclude-dirs", + nargs="+", + type=str, + help="List of directories to exclude (e.g., mmm clv)", + ) return parser.parse_args() @@ -115,12 +121,22 @@ def parse_args(): if args.notebooks: notebooks_to_run = [Path(notebook) for notebook in args.notebooks] + if args.exclude_dirs: + exclude_set = set(args.exclude_dirs) + notebooks_to_run = [ + nb for nb in notebooks_to_run if nb.parent.name not in exclude_set + ] + setup_logging() logging.info("Starting notebook runner") logging.info(f"Notebooks to run: {notebooks_to_run}") - Parallel(n_jobs=-1)( + results = Parallel(n_jobs=-1)( delayed(run_notebook)(**run_params) for run_params in run_parameters(notebooks_to_run) ) + del results + import gc + + gc.collect() logging.info("Notebooks run successfully!")