From 3c23d920ade30e4b48314cfccbf15486077c3a63 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:17:18 +0530 Subject: [PATCH 01/17] Fix styling for search box --- docs/_static/pybamm.css | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/_static/pybamm.css b/docs/_static/pybamm.css index a795e50f23..614716d24a 100644 --- a/docs/_static/pybamm.css +++ b/docs/_static/pybamm.css @@ -152,6 +152,11 @@ html[data-theme="dark"] .DocSearch-Commands-Key { .DocSearch-Hit-source { background: var(--pst-color-background); } + +.DocSearch-Hit-icon { + height: 30px; +} + .DocSearch-Button { border-radius: 6px; } @@ -187,5 +192,5 @@ html[data-theme="light"] .DocSearch-Logo svg rect.cls-1 { /* Search field dark theme corrections */ html[data-theme="dark"] .DocSearch-Button { - background: var(--pst-color-on-surface); + background: var(--pst-color-background); } From c31b839e118ea75d6d26b574cc5575f6f5274b67 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:18:02 +0530 Subject: [PATCH 02/17] Include the Contributor guide directly --- docs/index.rst | 3 ++- docs/source/user_guide/contributing.md | 5 +++++ docs/source/user_guide/index.md | 8 ++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 docs/source/user_guide/contributing.md diff --git a/docs/index.rst b/docs/index.rst index 3e5d54ecb5..bf0d34e1a0 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -16,6 +16,7 @@ PyBaMM documentation User Guide source/api/index source/examples/index + Contributing **Version**: |version| @@ -106,7 +107,7 @@ explore the effect of different battery designs and modeling assumptions under a +++ - .. button-link:: https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md + .. button-link:: source/user_guide/contributing.html :expand: :color: secondary :click-parent: diff --git a/docs/source/user_guide/contributing.md b/docs/source/user_guide/contributing.md new file mode 100644 index 0000000000..3f967fa93f --- /dev/null +++ b/docs/source/user_guide/contributing.md @@ -0,0 +1,5 @@ + + +```{include} ../../../CONTRIBUTING.md +``` diff --git a/docs/source/user_guide/index.md b/docs/source/user_guide/index.md index f7bc57a414..e26f20f4cc 100644 --- a/docs/source/user_guide/index.md +++ b/docs/source/user_guide/index.md @@ -23,6 +23,14 @@ maxdepth: 2 fundamentals/index ``` +```{toctree} +--- +caption: Contributing guide +maxdepth: 1 +--- +contributing +``` + # Example notebooks PyBaMM ships with example notebooks that demonstrate how to use it and reveal some of its From 5bb36cdd2c899a03e621d8e9a1ce6d83e4eb2944 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:18:21 +0530 Subject: [PATCH 03/17] Fix link error in contributor guide --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0084f729dc..f2e494135b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,7 +72,7 @@ python -m pip install pre-commit pre-commit run ruff ``` -ruff is configured inside the file `pre-commit-config.yaml`, allowing us to ignore some errors. If you think this should be added or removed, please submit an [issue](#issues) +ruff is configured inside the file `pre-commit-config.yaml`, allowing us to ignore some errors. If you think this should be added or removed, please submit an [issue](https://github.com/pybamm-team/PyBaMM/issues) When you commit your changes they will be checked against ruff automatically (see [Pre-commit checks](#pre-commit-checks)). From dc80ead30ea4f15b40257dbbe30f4d69ba5261b3 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:38:44 +0530 Subject: [PATCH 04/17] Add a check for hosted docs (check warnings) --- .github/workflows/run_periodic_tests.yml | 4 ++++ .github/workflows/test_on_push.yml | 5 +++++ noxfile.py | 19 +++++++++++++++++-- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run_periodic_tests.yml b/.github/workflows/run_periodic_tests.yml index 663eb5cfca..d4a8e3bb87 100644 --- a/.github/workflows/run_periodic_tests.yml +++ b/.github/workflows/run_periodic_tests.yml @@ -111,6 +111,10 @@ jobs: if: matrix.os == 'ubuntu-latest' run: nox -s doctests + - name: Check if the documentation can be built + if: matrix.os == 'ubuntu-latest' + run: nox -s docs + - name: Install dev dependencies and run example tests if: matrix.os == 'ubuntu-latest' run: nox -s examples diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index 839d53306f..d5b9f20549 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -313,6 +313,11 @@ jobs: - name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11 run: nox -s doctests + continue-on-error: true + + - name: Check if the documentation can be built for GNU/Linux with Python 3.11 + run: nox -s docs + continue-on-error: true - name: Install dev dependencies and run example tests for GNU/Linux with Python 3.11 run: nox -s examples diff --git a/noxfile.py b/noxfile.py index 039742f746..bd045ce1fb 100644 --- a/noxfile.py +++ b/noxfile.py @@ -153,7 +153,9 @@ def build_docs(session): envbindir = session.bin session.install("-e", ".[all,docs]") session.chdir("docs") - session.run( + # Local development + if session.interactive: + session.run( "sphinx-autobuild", "-j", "auto", @@ -161,7 +163,20 @@ def build_docs(session): "-qT", ".", f"{envbindir}/../tmp/html", - ) + ) + # Runs in CI only + else: + session.run( + "sphinx-build", + "-j", + "auto", + "-b", + "html", + "-W", + "--keep-going", + ".", + f"{envbindir}/../tmp/html", + ) @nox.session(name="pre-commit") From 6034b1b7eda6a4b4c16ba432dd118be322ec8f84 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:38:59 +0530 Subject: [PATCH 05/17] Add documentation about using `sphinx-build` --- docs/source/user_guide/installation/install-from-source.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/source/user_guide/installation/install-from-source.rst b/docs/source/user_guide/installation/install-from-source.rst index ce5d7e0ca3..4c9b7091d4 100644 --- a/docs/source/user_guide/installation/install-from-source.rst +++ b/docs/source/user_guide/installation/install-from-source.rst @@ -245,8 +245,9 @@ Doctests, examples, and coverage - ``nox -s coverage``: Measure current test coverage and generate a coverage report. - ``nox -s quick``: Run integration tests, unit tests, and doctests sequentially. -Extra tips while using Nox --------------------------- +Extra tips while using ``Nox`` +------------------------------ + Here are some additional useful commands you can run with ``Nox``: - ``--verbose or -v``: Enables verbose mode, providing more detailed output during the execution of Nox sessions. @@ -256,6 +257,7 @@ Here are some additional useful commands you can run with ``Nox``: - ``--install-only``: Skips the test execution and only performs the installation step defined in the Nox sessions. - ``--nocolor``: Disables the color output in the console during the execution of Nox sessions. - ``--report output.json``: Generates a JSON report of the Nox session execution and saves it to the specified file, in this case, "output.json". +- ``nox -s docs --non-interactive``: Builds the documentation without serving it locally (using ``sphinx-build`` instead of ``sphinx-autobuild``). Troubleshooting =============== From 7665b95015004e28c82434faa949402f574a60a0 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:42:28 +0530 Subject: [PATCH 06/17] Suppress myst warnings, remove external links --- docs/conf.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 1cb1a521ae..fd2f226c43 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -103,7 +103,7 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".ipynb_checkpoints"] # Suppress warnings generated by Sphinx and/or by Sphinx extensions -suppress_warnings = ["git.too_shallow"] +suppress_warnings = ["git.too_shallow", "myst.xref_missing"] # -- Options for HTML output ------------------------------------------------- @@ -142,12 +142,6 @@ }, ], "collapse_navigation": True, - "external_links": [ - { - "name": "Contributing", - "url": "https://github.com/pybamm-team/PyBaMM/tree/develop/CONTRIBUTING.md", - }, - ], # should be kept versioned to use for the version warning bar "switcher": { "version_match": version, From d86be930cc7b7f50d1d79e2b71d4ca56540d29f1 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:43:35 +0530 Subject: [PATCH 07/17] Add note about treating warnings as errors --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index bd045ce1fb..ae4a7c68d1 100644 --- a/noxfile.py +++ b/noxfile.py @@ -164,7 +164,7 @@ def build_docs(session): ".", f"{envbindir}/../tmp/html", ) - # Runs in CI only + # Runs in CI only, treating warnings as errors else: session.run( "sphinx-build", From 216d3e1d96c275f5089c7bb00fb0c92b856071c1 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 18:51:30 +0530 Subject: [PATCH 08/17] Remove `sphinx` version bound, remove `rtd-theme` --- docs/source/user_guide/installation/index.rst | 2 +- setup.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/source/user_guide/installation/index.rst b/docs/source/user_guide/installation/index.rst index c5714d5d5d..84c5de9de3 100644 --- a/docs/source/user_guide/installation/index.rst +++ b/docs/source/user_guide/installation/index.rst @@ -117,7 +117,7 @@ Installable with ``pip install "pybamm[docs]"`` ================================================================================================= ================== ================== ======================================================================= Dependency Minimum Version pip extra Notes ================================================================================================= ================== ================== ======================================================================= -`sphinx `__ 1.5.0 docs Sphinx makes it easy to create intelligent and beautiful documentation. +`sphinx `__ \- docs Sphinx makes it easy to create intelligent and beautiful documentation. `pydata-sphinx-theme `__ \- docs A clean, Bootstrap-based Sphinx theme. `sphinx_design `__ \- docs A sphinx extension for designing. `sphinx-copybutton `__ \- docs To copy codeblocks. diff --git a/setup.py b/setup.py index df55a24325..a16cc84a0d 100644 --- a/setup.py +++ b/setup.py @@ -210,8 +210,7 @@ def compile_KLU(): ], extras_require={ "docs": [ - "sphinx>=6", - "sphinx_rtd_theme>=0.5", + "sphinx", "pydata-sphinx-theme", "sphinx_design", "sphinx-copybutton", From d12903a676d4f79879d58f60e32c012666648ced Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:24:20 +0530 Subject: [PATCH 09/17] Cleanup noxfile and add coloured outputs to CI --- .github/workflows/test_on_push.yml | 5 ++-- noxfile.py | 39 ++++++++++++------------------ 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index d5b9f20549..a6abcfb494 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -4,6 +4,9 @@ on: workflow_dispatch: pull_request: +env: + FORCE_COLOR: 3 + concurrency: # github.workflow: name of the workflow, so that we don't cancel other workflows # github.event.pull_request.number || github.ref: pull request number or branch name if not a pull request @@ -313,11 +316,9 @@ jobs: - name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11 run: nox -s doctests - continue-on-error: true - name: Check if the documentation can be built for GNU/Linux with Python 3.11 run: nox -s docs - continue-on-error: true - name: Install dev dependencies and run example tests for GNU/Linux with Python 3.11 run: nox -s examples diff --git a/noxfile.py b/noxfile.py index ae4a7c68d1..4986f0efe8 100644 --- a/noxfile.py +++ b/noxfile.py @@ -16,13 +16,6 @@ "SUNDIALS_INST": f"{homedir}/.local", "LD_LIBRARY_PATH": f"{homedir}/.local/lib:", } -# Do not stdout ANSI colours on GitHub Actions -if os.getenv("CI") == "true": - os.environ["NO_COLOR"] = "1" - # The setup-python action installs and caches dependencies by default, so we skip - # installing them again in nox environments. The dev and docs sessions will still - # require a virtual environment, but we don't run them in the CI - nox.options.default_venv_backend = "none" def set_environment_variables(env_dict, session): @@ -46,7 +39,7 @@ def run_pybamm_requires(session): """Download, compile, and install the build-time requirements for Linux and macOS: the SuiteSparse and SUNDIALS libraries.""" # noqa: E501 set_environment_variables(PYBAMM_ENV, session=session) if sys.platform != "win32": - session.run_always("pip", "install", "wget", "cmake") + session.install("pip", "install", "wget", "cmake") session.run("python", "scripts/install_KLU_Sundials.py") if not os.path.exists("./pybind11"): session.run( @@ -64,11 +57,11 @@ def run_pybamm_requires(session): def run_coverage(session): """Run the coverage tests and generate an XML report.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "coverage") - session.run_always("pip", "install", "-e", ".[all]") + session.install("coverage") + session.install("-e", ".[all]") if sys.platform != "win32": - session.run_always("pip", "install", "-e", ".[odes]") - session.run_always("pip", "install", "-e", ".[jax]") + session.install("-e", ".[odes]") + session.install("-e", ".[jax]") session.run("coverage", "run", "--rcfile=.coveragerc", "run-tests.py", "--nosub") session.run("coverage", "combine") session.run("coverage", "xml") @@ -78,16 +71,16 @@ def run_coverage(session): def run_integration(session): """Run the integration tests.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "-e", ".[all]") + session.install("-e", ".[all]") if sys.platform == "linux": - session.run_always("pip", "install", "-e", ".[odes]") + session.install("-e", ".[odes]") session.run("python", "run-tests.py", "--integration") @nox.session(name="doctests") def run_doctests(session): """Run the doctests and generate the output(s) in the docs/build/ directory.""" - session.run_always("pip", "install", "-e", ".[all,docs]") + session.install("-e", ".[all,docs]") session.run("python", "run-tests.py", "--doctest") @@ -95,10 +88,10 @@ def run_doctests(session): def run_unit(session): """Run the unit tests.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "-e", ".[all]") + session.install("-e", ".[all]") if sys.platform == "linux": - session.run_always("pip", "install", "-e", ".[odes]") - session.run_always("pip", "install", "-e", ".[jax]") + session.install("-e", ".[odes]") + session.install("-e", ".[jax]") session.run("python", "run-tests.py", "--unit") @@ -106,7 +99,7 @@ def run_unit(session): def run_examples(session): """Run the examples tests for Jupyter notebooks.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "-e", ".[all]") + session.install("-e", ".[all]") session.run("python", "run-tests.py", "--examples") @@ -114,7 +107,7 @@ def run_examples(session): def run_scripts(session): """Run the scripts tests for Python scripts.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "-e", ".[all]") + session.install("-e", ".[all]") session.run("python", "run-tests.py", "--scripts") @@ -140,10 +133,10 @@ def set_dev(session): def run_tests(session): """Run the unit tests and integration tests sequentially.""" set_environment_variables(PYBAMM_ENV, session=session) - session.run_always("pip", "install", "-e", ".[all]") + session.install("-e", ".[all]") if sys.platform == "linux" or sys.platform == "darwin": - session.run_always("pip", "install", "-e", ".[odes]") - session.run_always("pip", "install", "-e", ".[jax]") + session.install("-e", ".[odes]") + session.install("-e", ".[jax]") session.run("python", "run-tests.py", "--all") From 50a82538c8040894109cd148a22ca2b92ae1d0e0 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:29:10 +0530 Subject: [PATCH 10/17] Fix install for `cmake` and `wget` --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 4986f0efe8..69a78a83b2 100644 --- a/noxfile.py +++ b/noxfile.py @@ -39,7 +39,7 @@ def run_pybamm_requires(session): """Download, compile, and install the build-time requirements for Linux and macOS: the SuiteSparse and SUNDIALS libraries.""" # noqa: E501 set_environment_variables(PYBAMM_ENV, session=session) if sys.platform != "win32": - session.install("pip", "install", "wget", "cmake") + session.install("wget", "cmake") session.run("python", "scripts/install_KLU_Sundials.py") if not os.path.exists("./pybind11"): session.run( From 2d7cd2d4f591c5c95fd0692efdf2a57bbe0e8904 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:38:40 +0530 Subject: [PATCH 11/17] Temporarily invalidate all caches --- .github/workflows/test_on_push.yml | 77 ------------------------------ 1 file changed, 77 deletions(-) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index a6abcfb494..586fad6c6a 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -87,28 +87,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] - - name: Cache pybamm-requires nox environment for GNU/Linux - uses: actions/cache@v3 - if: matrix.os == 'ubuntu-latest' - with: - path: | - # Repository files - ${{ github.workspace }}/pybind11/ - ${{ github.workspace }}/install_KLU_Sundials/ - # Headers and dynamic library files for SuiteSparse and SUNDIALS - ${{ env.HOME }}/.local/lib/ - ${{ env.HOME }}/.local/include/ - ${{ env.HOME }}/.local/examples/ - key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} - - name: Install SuiteSparse and SUNDIALS on GNU/Linux if: matrix.os == 'ubuntu-latest' run: nox -s pybamm-requires @@ -147,27 +131,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 - cache: 'pip' - cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] - - name: Cache pybamm-requires nox environment for GNU/Linux - uses: actions/cache@v3 - with: - path: | - # Repository files - ${{ github.workspace }}/pybind11/ - ${{ github.workspace }}/install_KLU_Sundials/ - # Headers and dynamic library files for SuiteSparse and SUNDIALS - ${{ env.HOME }}/.local/lib/ - ${{ env.HOME }}/.local/include/ - ${{ env.HOME }}/.local/examples/ - key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} - - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires @@ -230,28 +199,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - cache: 'pip' - cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] - - name: Cache pybamm-requires nox environment for GNU/Linux - uses: actions/cache@v3 - if: matrix.os == 'ubuntu-latest' - with: - path: | - # Repository files - ${{ github.workspace }}/pybind11/ - ${{ github.workspace }}/install_KLU_Sundials/ - # Headers and dynamic library files for SuiteSparse and SUNDIALS - ${{ env.HOME }}/.local/lib/ - ${{ env.HOME }}/.local/include/ - ${{ env.HOME }}/.local/examples/ - key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} - - name: Install SuiteSparse and SUNDIALS on GNU/Linux if: matrix.os == 'ubuntu-latest' run: nox -s pybamm-requires @@ -290,27 +243,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 - cache: 'pip' - cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] - - name: Cache pybamm-requires nox environment for GNU/Linux - uses: actions/cache@v3 - with: - path: | - # Repository files - ${{ github.workspace }}/pybind11/ - ${{ github.workspace }}/install_KLU_Sundials/ - # Headers and dynamic library files for SuiteSparse and SUNDIALS - ${{ env.HOME }}/.local/lib/ - ${{ env.HOME }}/.local/include/ - ${{ env.HOME }}/.local/examples/ - key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} - - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires @@ -354,27 +292,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 - cache: 'pip' - cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] - - name: Cache pybamm-requires nox environment for GNU/Linux - uses: actions/cache@v3 - with: - path: | - # Repository files - ${{ github.workspace }}/pybind11/ - ${{ github.workspace }}/install_KLU_Sundials/ - # Headers and dynamic library files for SuiteSparse and SUNDIALS - ${{ env.HOME }}/.local/lib/ - ${{ env.HOME }}/.local/include/ - ${{ env.HOME }}/.local/examples/ - key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} - - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires From bf9ff71dd1aa2d07dcc5dbece7c39c1d9116940d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sat, 16 Sep 2023 19:48:27 +0530 Subject: [PATCH 12/17] Restore all pip and pybamm-requires caches This reverts commit 2d7cd2d4f591c5c95fd0692efdf2a57bbe0e8904. --- .github/workflows/test_on_push.yml | 77 ++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index 586fad6c6a..a6abcfb494 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -87,12 +87,28 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] + - name: Cache pybamm-requires nox environment for GNU/Linux + uses: actions/cache@v3 + if: matrix.os == 'ubuntu-latest' + with: + path: | + # Repository files + ${{ github.workspace }}/pybind11/ + ${{ github.workspace }}/install_KLU_Sundials/ + # Headers and dynamic library files for SuiteSparse and SUNDIALS + ${{ env.HOME }}/.local/lib/ + ${{ env.HOME }}/.local/include/ + ${{ env.HOME }}/.local/examples/ + key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} + - name: Install SuiteSparse and SUNDIALS on GNU/Linux if: matrix.os == 'ubuntu-latest' run: nox -s pybamm-requires @@ -131,12 +147,27 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 + cache: 'pip' + cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] + - name: Cache pybamm-requires nox environment for GNU/Linux + uses: actions/cache@v3 + with: + path: | + # Repository files + ${{ github.workspace }}/pybind11/ + ${{ github.workspace }}/install_KLU_Sundials/ + # Headers and dynamic library files for SuiteSparse and SUNDIALS + ${{ env.HOME }}/.local/lib/ + ${{ env.HOME }}/.local/include/ + ${{ env.HOME }}/.local/examples/ + key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} + - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires @@ -199,12 +230,28 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} + cache: 'pip' + cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] + - name: Cache pybamm-requires nox environment for GNU/Linux + uses: actions/cache@v3 + if: matrix.os == 'ubuntu-latest' + with: + path: | + # Repository files + ${{ github.workspace }}/pybind11/ + ${{ github.workspace }}/install_KLU_Sundials/ + # Headers and dynamic library files for SuiteSparse and SUNDIALS + ${{ env.HOME }}/.local/lib/ + ${{ env.HOME }}/.local/include/ + ${{ env.HOME }}/.local/examples/ + key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} + - name: Install SuiteSparse and SUNDIALS on GNU/Linux if: matrix.os == 'ubuntu-latest' run: nox -s pybamm-requires @@ -243,12 +290,27 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 + cache: 'pip' + cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] + - name: Cache pybamm-requires nox environment for GNU/Linux + uses: actions/cache@v3 + with: + path: | + # Repository files + ${{ github.workspace }}/pybind11/ + ${{ github.workspace }}/install_KLU_Sundials/ + # Headers and dynamic library files for SuiteSparse and SUNDIALS + ${{ env.HOME }}/.local/lib/ + ${{ env.HOME }}/.local/include/ + ${{ env.HOME }}/.local/examples/ + key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} + - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires @@ -292,12 +354,27 @@ jobs: uses: actions/setup-python@v4 with: python-version: 3.11 + cache: 'pip' + cache-dependency-path: setup.py - name: Install PyBaMM dependencies run: | pip install --upgrade pip wheel setuptools nox pip install -e .[all,docs] + - name: Cache pybamm-requires nox environment for GNU/Linux + uses: actions/cache@v3 + with: + path: | + # Repository files + ${{ github.workspace }}/pybind11/ + ${{ github.workspace }}/install_KLU_Sundials/ + # Headers and dynamic library files for SuiteSparse and SUNDIALS + ${{ env.HOME }}/.local/lib/ + ${{ env.HOME }}/.local/include/ + ${{ env.HOME }}/.local/examples/ + key: nox-pybamm-requires-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/install_KLU_Sundials.py') }} + - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires From 90abbdf02717093f7980c79a9083221d2912518c Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:16:11 +0530 Subject: [PATCH 13/17] Un-silence session install commands to stream `pip` output --- noxfile.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/noxfile.py b/noxfile.py index ef1b14d5c3..0b5a188f96 100644 --- a/noxfile.py +++ b/noxfile.py @@ -39,7 +39,7 @@ def run_pybamm_requires(session): """Download, compile, and install the build-time requirements for Linux and macOS: the SuiteSparse and SUNDIALS libraries.""" # noqa: E501 set_environment_variables(PYBAMM_ENV, session=session) if sys.platform != "win32": - session.install("wget", "cmake") + session.install("wget", "cmake", silent=False) session.run("python", "scripts/install_KLU_Sundials.py") if not os.path.exists("./pybind11"): session.run( @@ -50,18 +50,18 @@ def run_pybamm_requires(session): external=True, ) else: - session.error("nox -s pybamm-requires is only available on Linux & MacOS.") + session.error("nox -s pybamm-requires is only available on Linux & macOS.") @nox.session(name="coverage") def run_coverage(session): """Run the coverage tests and generate an XML report.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("coverage") - session.install("-e", ".[all]") + session.install("coverage", silent=False) + session.install("-e", ".[all]", silent=False) if sys.platform != "win32": - session.install("-e", ".[odes]") - session.install("-e", ".[jax]") + session.install("-e", ".[odes]", silent=False) + session.install("-e", ".[jax]", silent=False) session.run("coverage", "run", "--rcfile=.coveragerc", "run-tests.py", "--nosub") session.run("coverage", "combine") session.run("coverage", "xml") @@ -71,16 +71,16 @@ def run_coverage(session): def run_integration(session): """Run the integration tests.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("-e", ".[all]") + session.install("-e", ".[all]", silent=False) if sys.platform == "linux": - session.install("-e", ".[odes]") + session.install("-e", ".[odes]", silent=False) session.run("python", "run-tests.py", "--integration") @nox.session(name="doctests") def run_doctests(session): """Run the doctests and generate the output(s) in the docs/build/ directory.""" - session.install("-e", ".[all,docs]") + session.install("-e", ".[all,docs]", silent=False) session.run("python", "run-tests.py", "--doctest") @@ -90,8 +90,8 @@ def run_unit(session): set_environment_variables(PYBAMM_ENV, session=session) session.install("-e", ".[all]") if sys.platform == "linux": - session.install("-e", ".[odes]") - session.install("-e", ".[jax]") + session.install("-e", ".[odes]", silent=False) + session.install("-e", ".[jax]", silent=False) session.run("python", "run-tests.py", "--unit") @@ -99,7 +99,7 @@ def run_unit(session): def run_examples(session): """Run the examples tests for Jupyter notebooks.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("-e", ".[all,dev]") + session.install("-e", ".[all,dev]", silent=False) notebooks_to_test = session.posargs if session.posargs else [] session.run("pytest", "--nbmake", *notebooks_to_test, external=True) @@ -108,7 +108,7 @@ def run_examples(session): def run_scripts(session): """Run the scripts tests for Python scripts.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("-e", ".[all]") + session.install("-e", ".[all]", silent=False) session.run("python", "run-tests.py", "--scripts") @@ -117,8 +117,8 @@ def set_dev(session): """Install PyBaMM in editable mode.""" set_environment_variables(PYBAMM_ENV, session=session) envbindir = session.bin - session.install("-e", ".[all]") - session.install("cmake") + session.install("-e", ".[all]", silent=False) + session.install("cmake", silent=False) if sys.platform == "linux" or sys.platform == "darwin": session.run( "echo", @@ -134,10 +134,10 @@ def set_dev(session): def run_tests(session): """Run the unit tests and integration tests sequentially.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("-e", ".[all]") + session.install("-e", ".[all]", silent=False) if sys.platform == "linux" or sys.platform == "darwin": - session.install("-e", ".[odes]") - session.install("-e", ".[jax]") + session.install("-e", ".[odes]", silent=False) + session.install("-e", ".[jax]", silent=False) session.run("python", "run-tests.py", "--all") @@ -145,7 +145,7 @@ def run_tests(session): def build_docs(session): """Build the documentation and load it in a browser tab, rebuilding on changes.""" envbindir = session.bin - session.install("-e", ".[all,docs]") + session.install("-e", ".[all,docs]", silent=False) session.chdir("docs") # Local development if session.interactive: @@ -176,7 +176,7 @@ def build_docs(session): @nox.session(name="pre-commit") def lint(session): """Check all files against the defined pre-commit hooks.""" - session.install("pre-commit") + session.install("pre-commit", silent=False) session.run("pre-commit", "run", "--all-files") From 8dd57f9d1828ac30f04a3ec69485c8fc2e0f769f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 22 Sep 2023 22:17:53 +0530 Subject: [PATCH 14/17] Unsilence unit tests `nox` session --- noxfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/noxfile.py b/noxfile.py index 0b5a188f96..c215c73ca5 100644 --- a/noxfile.py +++ b/noxfile.py @@ -88,7 +88,7 @@ def run_doctests(session): def run_unit(session): """Run the unit tests.""" set_environment_variables(PYBAMM_ENV, session=session) - session.install("-e", ".[all]") + session.install("-e", ".[all]", silent=False) if sys.platform == "linux": session.install("-e", ".[odes]", silent=False) session.install("-e", ".[jax]", silent=False) From 6cda8f363ac7403213a898549a4e1c2245a6af1f Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sun, 1 Oct 2023 17:58:46 +0530 Subject: [PATCH 15/17] Un-suppress all `myst.xref_missing` warnings --- CONTRIBUTING.md | 18 +++++++++--------- docs/conf.py | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4b74d83557..a6aa6987c2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -347,17 +347,17 @@ Using [Sphinx](http://www.sphinx-doc.org/en/stable/) the documentation in `docs` ### Building the documentation -To test and debug the documentation, it's best to build it locally. To do this, navigate to your PyBaMM directory in a console, and then type: +To test and debug the documentation, it's best to build it locally. To do this, navigate to your PyBaMM directory in a console, and then type (on GNU/Linux, macOS, and Windows): ``` -nox -s docs (GNU/Linux, MacOS and Windows) +nox -s docs ``` -And then visit the webpage served at http://127.0.0.1:8000. Each time a change to the documentation source is detected, the HTML is rebuilt and the browser automatically reloaded. +And then visit the webpage served at `http://127.0.0.1:8000`. Each time a change to the documentation source is detected, the HTML is rebuilt and the browser automatically reloaded. In CI, the docs are built and tested using the `docs` session in the `noxfile.py` file with warnings turned into errors, to fail the build. The warnings can be removed or ignored by adding the appropriate warning identifier to the `suppress_warnings` list in `docs/conf.py`. ### Example notebooks -Major PyBaMM features are showcased in [Jupyter notebooks](https://jupyter.org/) stored in the [docs/source/examples directory](docs/source/examples/notebooks). Which features are "major" is of course wholly subjective, so please discuss on GitHub first! +Major PyBaMM features are showcased in [Jupyter notebooks](https://jupyter.org/) stored in the [docs/source/examples directory](https://github.com/pybamm-team/PyBaMM/tree/develop/docs/source/examples). Which features are "major" is of course wholly subjective, so please discuss on GitHub first! All example notebooks should be listed in [docs/source/examples/index.rst](https://github.com/pybamm-team/PyBaMM/blob/develop/docs/source/examples/index.rst). Please follow the (naming and writing) style of existing notebooks where possible. @@ -375,7 +375,7 @@ pybamm.print_citations() to the end of a script will print all citations that were used by that script. This will print BibTeX information to the terminal; passing a filename to `print_citations` will print the BibTeX information to the specified file instead. -When you contribute code to PyBaMM, you can add your own papers that you would like to be cited if that code is used. First, add the BibTeX for your paper to [CITATIONS.bib](pybamm/CITATIONS.bib). Then, add the line +When you contribute code to PyBaMM, you can add your own papers that you would like to be cited if that code is used. First, add the BibTeX for your paper to [CITATIONS.bib](https://github.com/pybamm-team/PyBaMM/blob/develop/pybamm/CITATIONS.bib). Then, add the line ```python3 pybamm.citations.register("your_paper_bibtex_identifier") @@ -395,7 +395,7 @@ Configuration files: setup.py ``` -Note that this file must be kept in sync with the version number in [pybamm/**init**.py](pybamm/__init__.py). +Note that this file must be kept in sync with the version number in [pybamm/**init**.py](https://github.com/pybamm-team/PyBaMM/blob/develop/pybamm/__init__.py). ### Continuous Integration using GitHub actions @@ -431,9 +431,9 @@ Editable notebooks are made available using [Google Colab](https://colab.researc GitHub does some magic with particular filenames. In particular: -- The first page people see when they go to [our GitHub page](https://github.com/pybamm-team/PyBaMM) displays the contents of [README.md](README.md), which is written in the [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) format. Some guidelines can be found [here](https://help.github.com/articles/about-readmes/). -- The license for using PyBaMM is stored in [LICENSE](LICENSE.txt), and [automatically](https://help.github.com/articles/adding-a-license-to-a-repository/) linked to by GitHub. -- This file, [CONTRIBUTING.md](CONTRIBUTING.md) is recognised as the contribution guidelines and a link is [automatically](https://github.com/blog/1184-contributing-guidelines) displayed when new issues or pull requests are created. +- The first page people see when they go to [our GitHub page](https://github.com/pybamm-team/PyBaMM) displays the contents of [README.md](https://github.com/pybamm-team/PyBaMM/blob/develop/README.md), which is written in the [Markdown](https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet) format. Some guidelines can be found [here](https://help.github.com/articles/about-readmes/). +- The license for using PyBaMM is stored in [LICENSE](https://github.com/pybamm-team/PyBaMM/blob/develop/LICENSE.txt), and [automatically](https://help.github.com/articles/adding-a-license-to-a-repository/) linked to by GitHub. +- This file, [CONTRIBUTING.md](https://github.com/pybamm-team/PyBaMM/blob/develop/CONTRIBUTING.md) is recognised as the contribution guidelines and a link is [automatically](https://github.com/blog/1184-contributing-guidelines) displayed when new issues or pull requests are created. ## Acknowledgements diff --git a/docs/conf.py b/docs/conf.py index fd2f226c43..a96d139b12 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -103,7 +103,7 @@ exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".ipynb_checkpoints"] # Suppress warnings generated by Sphinx and/or by Sphinx extensions -suppress_warnings = ["git.too_shallow", "myst.xref_missing"] +suppress_warnings = ["git.too_shallow"] # -- Options for HTML output ------------------------------------------------- From d3de3649a05b35104952b52f3d783259b6f8fe97 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:20:52 +0530 Subject: [PATCH 16/17] Add a doctests parallel job --- .github/workflows/test_on_push.yml | 51 +++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index a6abcfb494..76e8d4b033 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -259,13 +259,54 @@ jobs: - name: Run integration tests for ${{ matrix.os }} with Python ${{ matrix.python-version }} run: nox -s integration +# Runs only on Ubuntu with Python 3.11. Skips IDAKLU module compilation +# for speedups, which is already tested in other jobs. + run_doctests: + needs: style + runs-on: ubuntu-latest + strategy: + fail-fast: false + name: Doctests (ubuntu-latest / Python 3.11) + + steps: + - name: Check out PyBaMM repository + uses: actions/checkout@v4 + + # Install and cache apt packages + - name: Install Linux system dependencies + uses: awalsh128/cache-apt-pkgs-action@v1.3.0 + with: + packages: gfortran gcc graphviz pandoc + execute_install_scripts: true + + # dot -c is for registering graphviz fonts and plugins + - name: Install OpenBLAS and TeXLive for Linux + run: | + sudo apt-get update + sudo dot -c + sudo apt-get install libopenblas-dev texlive-latex-extra dvipng + + - name: Set up Python 3.11 + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: 3.11 + cache: 'pip' + cache-dependency-path: setup.py + + - name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11 + run: nox -s doctests + + - name: Check if the documentation can be built for GNU/Linux with Python 3.11 + run: nox -s docs + # Runs only on Ubuntu with Python 3.11 - run_doctests_and_example_tests: + run_example_tests: needs: style runs-on: ubuntu-latest strategy: fail-fast: false - name: Doctests and notebooks (ubuntu-latest / Python 3.11) + name: Example notebooks (ubuntu-latest / Python 3.11) steps: - name: Check out PyBaMM repository @@ -314,12 +355,6 @@ jobs: - name: Install SuiteSparse and SUNDIALS on GNU/Linux run: nox -s pybamm-requires - - name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11 - run: nox -s doctests - - - name: Check if the documentation can be built for GNU/Linux with Python 3.11 - run: nox -s docs - - name: Install dev dependencies and run example tests for GNU/Linux with Python 3.11 run: nox -s examples From b441fc4003ef2dca42e10a728368b7916eb4cde7 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Sun, 1 Oct 2023 18:24:56 +0530 Subject: [PATCH 17/17] Add missing PyBaMM dependencies step --- .github/workflows/test_on_push.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index 76e8d4b033..b740da2e1b 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -294,6 +294,11 @@ jobs: cache: 'pip' cache-dependency-path: setup.py + - name: Install PyBaMM dependencies + run: | + pip install --upgrade pip wheel setuptools nox + pip install -e .[all,docs] + - name: Install docs dependencies and run doctests for GNU/Linux with Python 3.11 run: nox -s doctests