From 62d09f4ae3cb151ca4b80379866ceadbb6274c3d Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 10 Jan 2024 18:35:20 +0530 Subject: [PATCH 01/14] Add `cmake` and `wget` as Pythonic prerequisites --- docs/source/user_guide/installation/gnu-linux-mac.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/source/user_guide/installation/gnu-linux-mac.rst b/docs/source/user_guide/installation/gnu-linux-mac.rst index 3e93587cde..dd6a677dee 100644 --- a/docs/source/user_guide/installation/gnu-linux-mac.rst +++ b/docs/source/user_guide/installation/gnu-linux-mac.rst @@ -119,7 +119,8 @@ Users can install `scikits.odes `__ to utilize i .. code:: bash - apt install libopenblas-dev + apt-get install libopenblas-dev + pip install wget cmake pybamm_install_odes system (under ``~/.local``), before installing ``scikits.odes``. (Alternatively, one can install SUNDIALS without this script and run ``pip install pybamm[odes]`` to install ``pybamm`` with ``scikits.odes``.) @@ -131,6 +132,7 @@ Users can install `scikits.odes `__ to utilize i .. code:: bash brew install openblas gcc gfortran + pip install wget cmake pybamm_install_odes The ``pybamm_install_odes`` command, installed with PyBaMM, automatically downloads and installs the SUNDIALS library on your From 3f29ea435fcd61fe7cf2943e774532c068166b5b Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 10 Jan 2024 18:39:11 +0530 Subject: [PATCH 02/14] Use `sys.executable` to invoke `pip`, make it verbose --- pybamm/install_odes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pybamm/install_odes.py b/pybamm/install_odes.py index 128d3ca396..d04d04ab8a 100644 --- a/pybamm/install_odes.py +++ b/pybamm/install_odes.py @@ -190,8 +190,8 @@ def main(arguments=None): # see https://scikits-odes.readthedocs.io/en/latest/installation.html#id1 os.environ["SUNDIALS_INST"] = SUNDIALS_LIB_DIR env = os.environ.copy() - subprocess.run(["pip", "install", "scikits.odes"], env=env, check=True) - + logger.info("Installing scikits.odes via pip") + subprocess.run([f"{sys.executable}", "-m", "pip", "install", "scikits.odes", "--verbose"], env=env, check=True) if __name__ == "__main__": main(sys.argv[1:]) From c68c8a9e449fc4cd1705f25576d4ba76bddeb5fe Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 10 Jan 2024 13:21:07 +0000 Subject: [PATCH 03/14] style: pre-commit fixes --- pybamm/install_odes.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pybamm/install_odes.py b/pybamm/install_odes.py index d04d04ab8a..3809d763f2 100644 --- a/pybamm/install_odes.py +++ b/pybamm/install_odes.py @@ -191,7 +191,12 @@ def main(arguments=None): os.environ["SUNDIALS_INST"] = SUNDIALS_LIB_DIR env = os.environ.copy() logger.info("Installing scikits.odes via pip") - subprocess.run([f"{sys.executable}", "-m", "pip", "install", "scikits.odes", "--verbose"], env=env, check=True) + subprocess.run( + [f"{sys.executable}", "-m", "pip", "install", "scikits.odes", "--verbose"], + env=env, + check=True, + ) + if __name__ == "__main__": main(sys.argv[1:]) From 62195f2ccdc9ff5f60ffbd6b2ed9c7e2da415812 Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Wed, 10 Jan 2024 18:52:20 +0530 Subject: [PATCH 04/14] Add changelog entry for `pybamm_install_odes` --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17adc3a31f..965a2aa7b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## Features -- The `pybamm_install_odes` command now includes support for macOS systems and can be used to set up SUNDIALS and install the `scikits.odes` solver on macOS ([#3417](https://github.com/pybamm-team/PyBaMM/pull/3417)) +- The `pybamm_install_odes` command now includes support for macOS systems and can be used to set up SUNDIALS and install the `scikits.odes` solver on macOS ([#3417](https://github.com/pybamm-team/PyBaMM/pull/3417), [#3706](https://github.com/pybamm-team/PyBaMM/3706])) - Added support for Python 3.12 ([#3531](https://github.com/pybamm-team/PyBaMM/pull/3531)) - Added method to get QuickPlot axes by variable ([#3596](https://github.com/pybamm-team/PyBaMM/pull/3596)) - Added custom experiment terminations ([#3596](https://github.com/pybamm-team/PyBaMM/pull/3596)) From 64681dd7ee9ca6e9c6c18a9e704e5d984a90466c Mon Sep 17 00:00:00 2001 From: "Eric G. Kratz" Date: Wed, 10 Jan 2024 09:49:37 -0500 Subject: [PATCH 05/14] Run pre-commit on all files (#3705) * Run pre-commit on all files * Apply suggestions from code review --- .github/workflows/run_periodic_tests.yml | 3 +-- .github/workflows/test_on_push.yml | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/run_periodic_tests.yml b/.github/workflows/run_periodic_tests.yml index cc09203ef3..0fdf5d1ecc 100644 --- a/.github/workflows/run_periodic_tests.yml +++ b/.github/workflows/run_periodic_tests.yml @@ -36,8 +36,7 @@ jobs: - name: Check style run: | python -m pip install pre-commit - git add . - pre-commit run ruff + pre-commit run -a build: needs: style diff --git a/.github/workflows/test_on_push.yml b/.github/workflows/test_on_push.yml index 7297f48fad..d1f448c110 100644 --- a/.github/workflows/test_on_push.yml +++ b/.github/workflows/test_on_push.yml @@ -28,8 +28,7 @@ jobs: - name: Check style run: | python -m pip install pre-commit - git add . - pre-commit run ruff + pre-commit run -a run_unit_tests: needs: style From fdbd8865c6be13ffb7cfef1524817df4ad897684 Mon Sep 17 00:00:00 2001 From: AlessioBugetti Date: Fri, 12 Jan 2024 11:06:48 +0100 Subject: [PATCH 06/14] Add PEP 723 support for SuiteSparse and SUNDIALS installation script Introduce a TOML-style comment block at the top of the `install_KLU_Sundials.py` script. This block contains essential metadata, including the required Python version and a list of dependencies. This addition aligns the script with the PEP 723 guidelines, enhancing readability and portability for script runners and developers. The metadata includes: - The Python version requirement (<=3.9) - Dependencies required for the script (wget, cmake) - Additional information like the repository and documentation links This enhancement facilitates easier script sharing and collaboration, providing a standardized way to specify and access script dependencies and supported Python versions. It also lays the groundwork for potential future tooling that could automate environment setup and dependency installation. Refer to PEP 723 for more details on this format. Resolves: #3647 --- scripts/install_KLU_Sundials.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index 2aa8394ac4..edcf90160c 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -1,3 +1,15 @@ +# /// pyproject +# [run] +# requires-python = "<=3.9" +# dependencies = [ +# "wget", +# "cmake", +# ] +# +# [additional-info] +# repository = "https://github.com/pybamm-team/PyBaMM" +# documentation = "https://docs.pybamm.org" +# /// import os import subprocess import tarfile From 0bd42a59e4d65ffdd393cd576ce758ce094d7499 Mon Sep 17 00:00:00 2001 From: AlessioBugetti Date: Fri, 12 Jan 2024 12:45:02 +0100 Subject: [PATCH 07/14] Update Python version compatibility in install_KLU_Sundials.py --- scripts/install_KLU_Sundials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index edcf90160c..ef24b92c64 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -1,6 +1,6 @@ # /// pyproject # [run] -# requires-python = "<=3.9" +# requires-python = "">=3.8, <=3.12"" # dependencies = [ # "wget", # "cmake", From 79f93161354fc1b0d9a61a23fce112c1ce47e048 Mon Sep 17 00:00:00 2001 From: AlessioBugetti Date: Fri, 12 Jan 2024 12:56:44 +0100 Subject: [PATCH 08/14] Adjust Python version range in requirements to >=3.8, <3.13 in install_KLU_Sundials.py --- scripts/install_KLU_Sundials.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/install_KLU_Sundials.py b/scripts/install_KLU_Sundials.py index ef24b92c64..5aaccd0e15 100755 --- a/scripts/install_KLU_Sundials.py +++ b/scripts/install_KLU_Sundials.py @@ -1,6 +1,6 @@ # /// pyproject # [run] -# requires-python = "">=3.8, <=3.12"" +# requires-python = "">=3.8, <3.13"" # dependencies = [ # "wget", # "cmake", From f6af07e306a76d62862453c7c1663df1ac949feb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:04:06 +0000 Subject: [PATCH 09/14] docs: update README.md [skip ci] --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2aa9220e70..02be55daf8 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ [![code style](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff) -[![All Contributors](https://img.shields.io/badge/all_contributors-73-orange.svg)](#-contributors) +[![All Contributors](https://img.shields.io/badge/all_contributors-74-orange.svg)](#-contributors) @@ -279,6 +279,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d Pradyot Ranjan
Pradyot Ranjan

🚇 XuboGU
XuboGU

💻 🐛 Ankit Meda
Ankit Meda

💻 + Alessio Bugetti
Alessio Bugetti

🚇 From 8162d1b5be5025de3b255d08126c7aee8eaf80fb Mon Sep 17 00:00:00 2001 From: "allcontributors[bot]" <46447321+allcontributors[bot]@users.noreply.github.com> Date: Fri, 12 Jan 2024 13:04:07 +0000 Subject: [PATCH 10/14] docs: update .all-contributorsrc [skip ci] --- .all-contributorsrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5b003ed874..7d05f65d0f 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -793,6 +793,15 @@ "contributions": [ "code" ] + }, + { + "login": "AlessioBugetti", + "name": "Alessio Bugetti", + "avatar_url": "https://avatars.githubusercontent.com/u/38499721?v=4", + "profile": "https://github.com/AlessioBugetti", + "contributions": [ + "infra" + ] } ], "contributorsPerLine": 7, From 025ac6f85404383cbc3b3eb059c5c5d1d30d606b Mon Sep 17 00:00:00 2001 From: Agriya Khetarpal <74401230+agriyakhetarpal@users.noreply.github.com> Date: Fri, 12 Jan 2024 23:36:34 +0530 Subject: [PATCH 11/14] Fix docs about Jax solver compatibility with Python versions (#3702) * Ensure correct Python versions for Jax solver compatibility * Simplify array of Python versions Co-authored-by: Eric G. Kratz * Use different conjunction Co-authored-by: Eric G. Kratz --------- Co-authored-by: Eric G. Kratz --- docs/source/user_guide/installation/gnu-linux-mac.rst | 2 +- docs/source/user_guide/installation/windows.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/user_guide/installation/gnu-linux-mac.rst b/docs/source/user_guide/installation/gnu-linux-mac.rst index 3e93587cde..c73f549299 100644 --- a/docs/source/user_guide/installation/gnu-linux-mac.rst +++ b/docs/source/user_guide/installation/gnu-linux-mac.rst @@ -161,7 +161,7 @@ Users can install ``jax`` and ``jaxlib`` to use the Jax solver. .. note:: - The Jax solver is not supported on Python 3.8. It is supported on Python 3.9, 3.10, and 3.11. + The Jax solver is only supported for Python versions 3.9 through 3.12. .. code:: bash diff --git a/docs/source/user_guide/installation/windows.rst b/docs/source/user_guide/installation/windows.rst index 6e815b33c8..d99d1f2eb2 100644 --- a/docs/source/user_guide/installation/windows.rst +++ b/docs/source/user_guide/installation/windows.rst @@ -73,7 +73,7 @@ Users can install ``jax`` and ``jaxlib`` to use the Jax solver. .. note:: - The Jax solver is not supported on Python 3.8. It is supported on Python 3.9, 3.10, and 3.11. + The Jax solver is only supported for Python versions 3.9 through 3.12. .. code:: bash From a2481fa48acc3afcafa0533db0ddbf59c8cec075 Mon Sep 17 00:00:00 2001 From: Robert Timms <43040151+rtimms@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:14:25 +0000 Subject: [PATCH 12/14] #3690 fix issue with skipped steps (#3708) * #3690 fix issue with skipped steps * #3690 changelog * #3690 add test --- CHANGELOG.md | 3 +++ pybamm/simulation.py | 15 ++++++++++++++- .../test_simulation_with_experiment.py | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 965a2aa7b4..00ad65f9a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # [Unreleased](https://github.com/pybamm-team/PyBaMM/) +## Bug Fixes + +- Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708)) # [v24.1rc0](https://github.com/pybamm-team/PyBaMM/tree/v24.1rc0) - 2024-01-31 ## Features diff --git a/pybamm/simulation.py b/pybamm/simulation.py index c95ab3039c..8a6150cc4e 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -839,7 +839,20 @@ def solve( steps.append(step_solution) - cycle_solution = cycle_solution + step_solution + # If there haven't been any successful steps yet in this cycle, then + # carry the solution over from the previous cycle (but + # `step_solution` should still be an EmptySolution so that in the + # list of returned step solutions we can see which steps were + # skipped) + if ( + cycle_solution is None + and isinstance(step_solution, pybamm.EmptySolution) + and not isinstance(current_solution, pybamm.EmptySolution) + ): + cycle_solution = current_solution.last_state + else: + cycle_solution = cycle_solution + step_solution + current_solution = cycle_solution callbacks.on_step_end(logs) diff --git a/tests/unit/test_experiments/test_simulation_with_experiment.py b/tests/unit/test_experiments/test_simulation_with_experiment.py index cc04177ba2..36475081c3 100644 --- a/tests/unit/test_experiments/test_simulation_with_experiment.py +++ b/tests/unit/test_experiments/test_simulation_with_experiment.py @@ -519,6 +519,25 @@ def test_run_experiment_skip_steps(self): decimal=5, ) + def test_skipped_step_continuous(self): + model = pybamm.lithium_ion.SPM({"SEI": "solvent-diffusion limited"}) + experiment = pybamm.Experiment( + [ + ("Rest for 24 hours (1 hour period)",), + ( + "Charge at C/3 until 4.1 V", + "Hold at 4.1V until C/20", + "Discharge at C/3 until 2.5 V", + ), + ] + ) + sim = pybamm.Simulation(model, experiment=experiment) + sim.solve(initial_soc=1) + np.testing.assert_array_almost_equal( + sim.solution.cycles[0].last_state.y.full(), + sim.solution.cycles[1].steps[-1].first_state.y.full(), + ) + def test_all_empty_solution_errors(self): model = pybamm.lithium_ion.SPM() parameter_values = pybamm.ParameterValues("Chen2020") From 6d2227eefe8193842f1d29103c44fa5cc20114e9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 14:54:33 -0500 Subject: [PATCH 13/14] chore: update pre-commit hooks (#3728) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.11 → v0.1.13](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.11...v0.1.13) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 20fce209d2..3ecec61480 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: "v0.1.11" + rev: "v0.1.13" hooks: - id: ruff args: [--fix, --show-fixes] From 3e57733aeee3032e8d6248182c7dae6d1e2a28cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 16:31:47 -0500 Subject: [PATCH 14/14] Bump the actions group with 1 update (#3729) Bumps the actions group with 1 update: [lycheeverse/lychee-action](https://github.com/lycheeverse/lychee-action). Updates `lycheeverse/lychee-action` from 1.9.0 to 1.9.1 - [Release notes](https://github.com/lycheeverse/lychee-action/releases) - [Commits](https://github.com/lycheeverse/lychee-action/compare/v1.9.0...v1.9.1) --- updated-dependencies: - dependency-name: lycheeverse/lychee-action dependency-type: direct:production update-type: version-update:semver-patch dependency-group: actions ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- .github/workflows/lychee_url_checker.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/lychee_url_checker.yml b/.github/workflows/lychee_url_checker.yml index 1ce20decd9..f94ecb7876 100644 --- a/.github/workflows/lychee_url_checker.yml +++ b/.github/workflows/lychee_url_checker.yml @@ -28,7 +28,7 @@ jobs: # use stable version for now to avoid breaking changes - name: Lychee URL checker - uses: lycheeverse/lychee-action@v1.9.0 + uses: lycheeverse/lychee-action@v1.9.1 with: # arguments with file types to check args: >-