diff --git a/.github/workflows/release-action.yaml b/.github/workflows/release_action.yaml similarity index 100% rename from .github/workflows/release-action.yaml rename to .github/workflows/release_action.yaml diff --git a/.github/workflows/scheduled_tests.yaml b/.github/workflows/scheduled_tests.yaml index 490efea9e..0bfd6a0ac 100644 --- a/.github/workflows/scheduled_tests.yaml +++ b/.github/workflows/scheduled_tests.yaml @@ -10,38 +10,67 @@ on: schedule: - cron: '0 9 * * *' +# Check noxfile.py for associated environment variables +env: + PYBOP_SCHEDULED: 1 + jobs: + # Dynamically create a matrix of OS, Python, and PyBaMM versions + create_pybamm_matrix: + name: Dynamically create GitHub Actions matrix + runs-on: ubuntu-latest + steps: + - name: Check out PyBOP repository + uses: actions/checkout@v4 + with: + sparse-checkout-cone-mode: false + sparse-checkout: | + scripts/ci/build_matrix.sh + + - name: Run script to create matrix + id: set-matrix + run: | + echo "matrix=$(bash scripts/ci/build_matrix.sh)" >> "$GITHUB_OUTPUT" + outputs: + pybop_matrix: ${{ steps.set-matrix.outputs.matrix }} + build: + needs: [create_pybamm_matrix] + name: Build (${{ matrix.os }}, Python ${{ matrix.python_version }}, PyBaMM ${{ matrix.pybamm_version }}) runs-on: ${{ matrix.os }} strategy: fail-fast: false - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - python-version: ["3.8", "3.9", "3.10", "3.11"] + matrix: ${{fromJson(needs.create_pybamm_matrix.outputs.pybop_matrix)}} + env: + PYBAMM_VERSION: ${{ matrix.pybamm_version }} steps: - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} + - name: Set up Python ${{ matrix.python_version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ matrix.python_version }} + - name: Install dependencies run: | python -m pip install --upgrade pip nox + - name: Unit tests with nox - run: | - python -m nox -s unit - python -m nox -s notebooks + run: python -m nox -s unit + + - name: Run notebooks with nox + run: python -m nox -s notebooks - #M-series Mac Mini + # M-series Mac Mini build-apple-mseries: runs-on: [self-hosted, macOS, ARM64] + if: github.repository == 'pybop-team/PyBOP' env: GITHUB_PATH: ${PYENV_ROOT/bin:$PATH} strategy: fail-fast: false matrix: - python-version: ["3.8", "3.9", "3.10", "3.11"] + python_version: ["3.8", "3.9", "3.10", "3.11"] steps: - uses: actions/checkout@v4 @@ -49,14 +78,14 @@ jobs: shell: bash run: | eval "$(pyenv init -)" - pyenv install ${{ matrix.python-version }} -s - pyenv virtualenv ${{ matrix.python-version }} pybop-${{ matrix.python-version }} + pyenv install ${{ matrix.python_version }} -s + pyenv virtualenv ${{ matrix.python_version }} pybop-${{ matrix.python_version }} - name: Install dependencies & run unit tests shell: bash run: | eval "$(pyenv init -)" - pyenv activate pybop-${{ matrix.python-version }} + pyenv activate pybop-${{ matrix.python_version }} python -m pip install --upgrade pip wheel setuptools nox python -m nox -s unit python -m nox -s notebooks @@ -66,5 +95,5 @@ jobs: shell: bash run: | eval "$(pyenv init -)" - pyenv activate pybop-${{ matrix.python-version }} + pyenv activate pybop-${{ matrix.python_version }} pyenv uninstall -f $( python --version ) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0077ef9f4..d089db95f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Features +- [#123](https://github.com/pybop-team/PyBOP/issues/123) - Configures scheduled tests to run against the last three PyPI releases of PyBaMM via dynamic GitHub Actions matrix generation. - [#187](https://github.com/pybop-team/PyBOP/issues/187) - Adds M1 Github runner to `test_on_push` workflow, updt. self-hosted supported python versions in scheduled tests. - [#118](https://github.com/pybop-team/PyBOP/issues/118) - Adds example jupyter notebooks. - [#151](https://github.com/pybop-team/PyBOP/issues/151) - Adds a standalone version of the Problem class. @@ -10,11 +11,13 @@ ## Bug Fixes +- [#123](https://github.com/pybop-team/PyBOP/issues/123) - Reinstates check for availability of parameter sets via PyBaMM upon retrieval by `pybop.ParameterSet.pybamm()`. - [#196](https://github.com/pybop-team/PyBOP/issues/196) - Fixes failing observer cost tests. - [#63](https://github.com/pybop-team/PyBOP/issues/63) - Removes NLOpt Optimiser from future releases. This is to support deployment to the Apple M-Series platform. - [#164](https://github.com/pybop-team/PyBOP/issues/164) - Fixes convergence issues with gradient-based optimisers, changes default `model.check_params()` to allow infeasible solutions during optimisation iterations. Adds a feasibility check on the optimal parameters. # [v23.12](https://github.com/pybop-team/PyBOP/tree/v23.12) - 2023-12-19 + ## Features - [#141](https://github.com/pybop-team/PyBOP/pull/141) - Adds documentation with Sphinx and PyData Sphinx Theme. Updates docstrings across package, relocates `costs` and `dataset` to top-level of package. Adds noxfile session and deployment workflow for docs. diff --git a/noxfile.py b/noxfile.py index ddb7bd191..c14e5b880 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,20 +1,31 @@ +import os import nox + # nox options nox.options.reuse_existing_virtualenvs = True +nox.options.venv_backend = "virtualenv" + +# Environment variables to control CI behaviour for nox sessions +PYBOP_SCHEDULED = int(os.environ.get("PYBOP_SCHEDULED", 0)) +PYBAMM_VERSION = os.environ.get("PYBAMM_VERSION", None) @nox.session def unit(session): - session.run_always("pip", "install", "-e", ".[all]") - session.install("pytest", "pytest-mock") + session.install("-e", ".[all]", silent=False) + if PYBOP_SCHEDULED: + session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False) + session.install("pytest", "pytest-mock", silent=False) session.run("pytest", "--unit") @nox.session def coverage(session): - session.run_always("pip", "install", "-e", ".[all]") - session.install("pytest", "pytest-cov", "pytest-mock") + session.install("-e", ".[all]", silent=False) + if PYBOP_SCHEDULED: + session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False) + session.install("pytest", "pytest-cov", "pytest-mock", silent=False) session.run( "pytest", "--unit", @@ -27,8 +38,10 @@ def coverage(session): @nox.session def notebooks(session): """Run the examples tests for Jupyter notebooks.""" - session.run_always("pip", "install", "-e", ".[all]") - session.install("pytest", "nbmake") + session.install("-e", ".[all]", silent=False) + if PYBOP_SCHEDULED: + session.run("pip", "install", f"pybamm=={PYBAMM_VERSION}", silent=False) + session.install("pytest", "nbmake", silent=False) session.run("pytest", "--nbmake", "--examples", "examples/", external=True) @@ -39,7 +52,7 @@ def docs(session): Credit: PyBaMM Team """ envbindir = session.bin - session.install("-e", ".[all,docs]") + session.install("-e", ".[all,docs]", silent=False) session.chdir("docs") # Local development if session.interactive: diff --git a/pybop/parameters/parameter_set.py b/pybop/parameters/parameter_set.py index 946d05baa..8a99b8b2f 100644 --- a/pybop/parameters/parameter_set.py +++ b/pybop/parameters/parameter_set.py @@ -152,4 +152,10 @@ def pybamm(cls, name): pybamm.ParameterValues A PyBaMM parameter set corresponding to the provided name. """ + + msg = f"Parameter set '{name}' is not a valid PyBaMM parameter set. Available parameter sets are: {list(pybamm.parameter_sets)}" + + if name not in list(pybamm.parameter_sets): + raise ValueError(msg) + return pybamm.ParameterValues(name).copy() diff --git a/scripts/ci/build_matrix.sh b/scripts/ci/build_matrix.sh new file mode 100644 index 000000000..49b13d54e --- /dev/null +++ b/scripts/ci/build_matrix.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# This helper script generates a matrix for further use in the +# scheduled/nightly builds for PyBOP, i.e., in scheduled_tests.yaml +# It generates a matrix of all combinations of the following variables: +# - python_version: 3.X +# - os: ubuntu-latest, windows-latest, macos-latest +# - pybamm_version: the last X versions of PyBaMM from PyPI, excluding release candidates + +# To update the matrix, the variables below can be modified as needed. + +python_version=("3.8" "3.9" "3.10" "3.11") +os=("ubuntu-latest" "windows-latest" "macos-latest") +# This command fetches the last three PyBaMM versions excluding release candidates from PyPI +pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 3 | awk '{print "\"" $1 "\"" }' | paste -sd " " -)) + +# open dict +json='{ + "include": [ +' + +# loop through each combination of variables to generate matrix components +for py_ver in "${python_version[@]}"; do + for os_type in "${os[@]}"; do + for pybamm_ver in "${pybamm_version[@]}"; do + json+='{ + "os": "'$os_type'", + "python_version": "'$py_ver'", + "pybamm_version": '$pybamm_ver' + },' + done + done +done + +# fix structure, removing trailing comma +json=${json%,} + +# close dict +json+=' + ] +}' + +echo "$json" | jq -c . diff --git a/tests/unit/test_parameter_sets.py b/tests/unit/test_parameter_sets.py index fc9356d2f..39d29d415 100644 --- a/tests/unit/test_parameter_sets.py +++ b/tests/unit/test_parameter_sets.py @@ -10,7 +10,7 @@ class TestParameterSets: @pytest.mark.unit def test_parameter_set(self): - # Tests parameter set creation + # Tests parameter set creation and validation with pytest.raises(ValueError): pybop.ParameterSet.pybamm("sChen2010s")