diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d1c9159b2..c6c5cead21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ # [Unreleased](https://github.com/pybamm-team/PyBaMM/) + +# [v22.6](https://github.com/pybamm-team/PyBaMM/tree/v22.6) - 2022-06-30 + ## Features - Added open-circuit potential as a separate submodel ([#2094](https://github.com/pybamm-team/PyBaMM/pull/2094)) diff --git a/CITATION.cff b/CITATION.cff index 0448617dd1..588e082157 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -24,6 +24,6 @@ keywords: - "expression tree" - "python" - "symbolic differentiation" -version: "22.5" +version: "22.6" repository-code: "https://github.com/pybamm-team/PyBaMM" title: "Python Battery Mathematical Modelling (PyBaMM)" diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67728d8a39..d2b5b273d9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -302,90 +302,6 @@ pybamm.citations.register("your_paper_bibtex_identifier") wherever code is called that uses that citation (for example, in functions or in the `__init__` method of a class such as a model or solver). -## Benchmarks - -A benchmark suite is located in the `benchmarks` directory at the root of the PyBaMM project. These benchmarks can be run using [airspeed velocity](https://asv.readthedocs.io/en/stable/) (`asv`). - -### Running the benchmarks -First of all, you'll need `asv` installed: -```shell -pip install asv -``` - -To run the benchmarks for the latest commit on the `develop` branch, simply enter the following command: -```shell -asv run -``` -If it is the first time you run `asv`, you will be prompted for information about your machine (e.g. its name, operating system, architecture...). - -Running the benchmarks can take a while, as all benchmarks are repeated several times to ensure statistically significant results. If accuracy isn't an issue, use the `--quick` option to avoid repeating each benchmark multiple times. -```shell -asv run --quick -``` - -Benchmarks can also be run over a range of commits. For instance, the following command runs the benchmark suite over every commit between version `0.3` and the tip of the `develop` branch: -```shell -asv run v0.3..develop -``` -Further information on how to run benchmarks with `asv` can be found in the documentation at [Using airspeed velocity](https://asv.readthedocs.io/en/stable/using.html). - -`asv` is configured using a file `asv.conf.json` located at the root of the PyBaMM repository. See the [asv reference](https://asv.readthedocs.io/en/stable/reference.html) for details on available settings and options. - -Benchmark results are stored in a directory `results/` at the location of the configuration file. There is one result file per commit, per machine. - -### Visualising benchmark results - -`asv` is able to generate a static website with a visualisation of the benchmarks results, i.e. the benchmark's duration as a function of the commit hash. -To generate the website, use -```shell -asv publish -``` -then, to view the website: -```shell -asv preview -``` - -Current benchmarks over PyBaMM's history can be viewed at https://pybamm-team.github.io/pybamm-bench/ - -### Adding benchmarks - -To contribute benchmarks to PyBaMM, add a new benchmark function in one of the files in the `benchmarks/` directory. -Benchmarks are distributed across multiple files, grouped by theme. You're welcome to add a new file if none of your benchmarks fit into one of the already existing files. -Inside a benchmark file (e.g. `benchmarks/benchmarks.py`) benchmarks functions are grouped within classes. - -Note that benchmark functions _must_ start with the prefix `time_`, for instance -```python3 -def time_solve_SPM_ScipySolver(self): - solver = pb.ScipySolver() - solver.solve(self.model, [0, 3600]) -``` - -In the case where some setup is necessary, but should not be timed, a `setup` function -can be defined as a method of the relevant class. For example: -```python3 -class TimeSPM: - def setup(self): - model = pb.lithium_ion.SPM() - geometry = model.default_geometry - - # ... - - self.model = model - - def time_solve_SPM_ScipySolver(self): - solver = pb.ScipySolver() - solver.solve(self.model, [0, 3600]) -``` - -Similarly, a `teardown` method will be run after the benchmark. Note that, unless the `--quick` option is used, benchmarks are executed several times for accuracy, and both the `setup` and `teardown` function are executed before/after each repetition. - -Running benchmarks can take a while, and by default encountered exceptions will not be shown. When developing benchmarks, it is often convenient to use the following command instead of `asv run`: -```shell -asv dev -``` - -`asv dev` implies options `--quick`, `--show-stderr`, and `--dry-run` (to avoid updating the `results` directory). - ## Infrastructure ### Setuptools diff --git a/benchmarks/README.md b/benchmarks/README.md new file mode 100644 index 0000000000..5328d9e928 --- /dev/null +++ b/benchmarks/README.md @@ -0,0 +1,83 @@ +## Benchmarks + +This directory contains the benchmark suites of the PyBaMM project. These benchmarks can be run using [airspeed velocity](https://asv.readthedocs.io/en/stable/) (`asv`). + +### Running the benchmarks +First of all, you'll need `asv` installed: +```shell +pip install asv +``` + +To run the benchmarks for the latest commit on the `develop` branch, simply enter the following command: +```shell +asv run +``` +If it is the first time you run `asv`, you will be prompted for information about your machine (e.g. its name, operating system, architecture...). + +Running the benchmarks can take a while, as all benchmarks are repeated several times to ensure statistically significant results. If accuracy isn't an issue, use the `--quick` option to avoid repeating each benchmark multiple times. +```shell +asv run --quick +``` + +Benchmarks can also be run over a range of commits. For instance, the following command runs the benchmark suite over every commit between version `0.3` and the tip of the `develop` branch: +```shell +asv run v0.3..develop +``` +Further information on how to run benchmarks with `asv` can be found in the documentation at [Using airspeed velocity](https://asv.readthedocs.io/en/stable/using.html). + +`asv` is configured using a file `asv.conf.json` located at the root of the PyBaMM repository. See the [asv reference](https://asv.readthedocs.io/en/stable/reference.html) for details on available settings and options. + +Benchmark results are stored in a directory `results/` at the location of the configuration file. There is one result file per commit, per machine. + +### Visualising benchmark results + +`asv` is able to generate a static website with a visualisation of the benchmarks results, i.e. the benchmark's duration as a function of the commit hash. +To generate the website, use +```shell +asv publish +``` +then, to view the website: +```shell +asv preview +``` + +Current benchmarks over PyBaMM's history can be viewed at https://pybamm-team.github.io/pybamm-bench/ + +### Adding benchmarks + +To contribute benchmarks to PyBaMM, add a new benchmark function in one of the files in the `benchmarks/` directory. +Benchmarks are distributed across multiple files, grouped by theme. You're welcome to add a new file if none of your benchmarks fit into one of the already existing files. +Inside a benchmark file (e.g. `benchmarks/benchmarks.py`) benchmarks functions are grouped within classes. + +Note that benchmark functions _must_ start with the prefix `time_`, for instance +```python3 +def time_solve_SPM_ScipySolver(self): + solver = pb.ScipySolver() + solver.solve(self.model, [0, 3600]) +``` + +In the case where some setup is necessary, but should not be timed, a `setup` function +can be defined as a method of the relevant class. For example: +```python3 +class TimeSPM: + def setup(self): + model = pb.lithium_ion.SPM() + geometry = model.default_geometry + + # ... + + self.model = model + + def time_solve_SPM_ScipySolver(self): + solver = pb.ScipySolver() + solver.solve(self.model, [0, 3600]) +``` + +Similarly, a `teardown` method will be run after the benchmark. Note that, unless the `--quick` option is used, benchmarks are executed several times for accuracy, and both the `setup` and `teardown` function are executed before/after each repetition. + +Running benchmarks can take a while, and by default encountered exceptions will not be shown. When developing benchmarks, it is often convenient to use the following command instead of `asv run`: +```shell +asv dev +``` + +`asv dev` implies options `--quick`, `--show-stderr`, and `--dry-run` (to avoid updating the `results` directory). \ No newline at end of file diff --git a/benchmarks/memory_sims.py b/benchmarks/memory_sims.py new file mode 100644 index 0000000000..1857873476 --- /dev/null +++ b/benchmarks/memory_sims.py @@ -0,0 +1,79 @@ +import pybamm + +parameters = ["Marquis2019", "Chen2020"] + + +class MemSPMSimulationCCCV: + param_names = ["parameter"] + params = parameters + + def mem_setup_SPM_simulationCCCV(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPM() + exp = pybamm.Experiment( + [ + "Discharge at C/5 for 10 hours or until 3.3 V", + "Rest for 1 hour", + "Charge at 1 A until 4.1 V", + "Hold at 4.1 V until 10 mA", + "Rest for 1 hour", + ] + ) + self.sim = pybamm.Simulation( + self.model, parameter_values=self.param, experiment=exp + ) + return self.sim + + +class MemDFNSimulationCCCV: + param_names = ["parameter"] + params = parameters + + def mem_setup_DFN_simulationCCCV(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.DFN() + exp = pybamm.Experiment( + [ + "Discharge at C/5 for 10 hours or until 3.3 V", + "Rest for 1 hour", + "Charge at 1 A until 4.1 V", + "Hold at 4.1 V until 10 mA", + "Rest for 1 hour", + ] + ) + self.sim = pybamm.Simulation( + self.model, parameter_values=self.param, experiment=exp + ) + return self.sim + + +class MemSPMSimulationGITT: + param_names = ["parameter"] + params = parameters + + def mem_setup_SPM_simulationGITT(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPM() + exp = pybamm.Experiment( + [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 + ) + self.sim = pybamm.Simulation( + self.model, parameter_values=self.param, experiment=exp + ) + return self.sim + + +class MemDFNSimulationGITT: + param_names = ["parameter"] + params = parameters + + def mem_setup_DFN_simulationGITT(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPM() + exp = pybamm.Experiment( + [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 + ) + self.sim = pybamm.Simulation( + self.model, parameter_values=self.param, experiment=exp + ) + return self.sim diff --git a/benchmarks/memory_unit_benchmarks.py b/benchmarks/memory_unit_benchmarks.py new file mode 100644 index 0000000000..4b20996b75 --- /dev/null +++ b/benchmarks/memory_unit_benchmarks.py @@ -0,0 +1,89 @@ +import pybamm +import numpy as np + + +class MemCreateExpression: + def mem_create_expression(self): + self.R = pybamm.Parameter("Particle radius [m]") + D = pybamm.Parameter("Diffusion coefficient [m2.s-1]") + j = pybamm.Parameter("Interfacial current density [A.m-2]") + F = pybamm.Parameter("Faraday constant [C.mol-1]") + c0 = pybamm.Parameter("Initial concentration [mol.m-3]") + self.model = pybamm.BaseModel() + + c = pybamm.Variable("Concentration [mol.m-3]", domain="negative particle") + N = -D * pybamm.grad(c) + dcdt = -pybamm.div(N) + self.model.rhs = {c: dcdt} + + lbc = pybamm.Scalar(0) + rbc = -j / F / D + self.model.boundary_conditions = { + c: {"left": (lbc, "Neumann"), "right": (rbc, "Neumann")} + } + + self.model.initial_conditions = {c: c0} + self.model.variables = { + "Concentration [mol.m-3]": c, + "Surface concentration [mol.m-3]": pybamm.surf(c), + "Flux [mol.m-2.s-1]": N, + } + return self.model + + +class MemParameteriseModel: + def setup(self): + MemCreateExpression.mem_create_expression(self) + + def mem_parameterise(self): + param = pybamm.ParameterValues( + { + "Particle radius [m]": 10e-6, + "Diffusion coefficient [m2.s-1]": 3.9e-14, + "Interfacial current density [A.m-2]": 1.4, + "Faraday constant [C.mol-1]": 96485, + "Initial concentration [mol.m-3]": 2.5e4, + } + ) + + self.r = pybamm.SpatialVariable( + "r", domain=["negative particle"], coord_sys="spherical polar" + ) + + self.geometry = { + "negative particle": {self.r: {"min": pybamm.Scalar(0), "max": self.R}} + } + param.process_model(self.model) + param.process_geometry(self.geometry) + return param + + +class MemDiscretiseModel: + def setup(self): + MemCreateExpression.mem_create_expression(self) + MemParameteriseModel.mem_parameterise(self) + + def mem_discretise(self): + MemCreateExpression.mem_create_expression(self) + MemParameteriseModel.mem_parameterise(self) + submesh_types = {"negative particle": pybamm.Uniform1DSubMesh} + var_pts = {self.r: 20} + mesh = pybamm.Mesh(self.geometry, submesh_types, var_pts) + + spatial_methods = {"negative particle": pybamm.FiniteVolume()} + disc = pybamm.Discretisation(mesh, spatial_methods) + disc.process_model(self.model) + return disc + + +class MemSolveModel: + def setup(self): + MemCreateExpression.mem_create_expression(self) + MemParameteriseModel.mem_parameterise(self) + MemDiscretiseModel.mem_discretise(self) + + def mem_solve(self): + solver = pybamm.ScipySolver() + t = np.linspace(0, 3600, 600) + solver.solve(self.model, t) + return solver diff --git a/benchmarks/time_solve_models.py b/benchmarks/time_solve_models.py index bf4a11ead4..235043badc 100644 --- a/benchmarks/time_solve_models.py +++ b/benchmarks/time_solve_models.py @@ -10,7 +10,7 @@ def solve_model_once(model, solver, t_eval): class TimeSolveSPM: - param_names = ['solve first', 'parameter'] + param_names = ["solve first", "parameter"] params = ( [False, True], [ @@ -64,7 +64,7 @@ def time_solve_model(self, solve_first, parameters): class TimeSolveSPMe: - param_names = ['solve first', 'parameter'] + param_names = ["solve first", "parameter"] params = ( [False, True], [ @@ -118,7 +118,7 @@ def time_solve_model(self, solve_first, parameters): class TimeSolveDFN: - param_names = ['solve first', 'parameter'] + param_names = ["solve first", "parameter"] params = ( [False, True], [ diff --git a/docs/conf.py b/docs/conf.py index 5fe3ed89e8..6efc75aadc 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -27,7 +27,7 @@ author = "The PyBaMM Team" # The short X.Y version -version = "22.5" +version = "22.6" # The full version, including alpha/beta/rc tags release = version diff --git a/docs/index.rst b/docs/index.rst index e0814f68d1..36c265a929 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -107,4 +107,4 @@ There are many ways to contribute to PyBaMM: tutorials/add-spatial-method tutorials/add-solver -Before contributing, please read the `Contribution Guidelines `_. +Before contributing, please read the `Contribution Guidelines `_. \ No newline at end of file diff --git a/pybamm/plotting/quick_plot.py b/pybamm/plotting/quick_plot.py index e11a01cd96..eb2435105f 100644 --- a/pybamm/plotting/quick_plot.py +++ b/pybamm/plotting/quick_plot.py @@ -759,7 +759,7 @@ def create_gif(self, number_of_images=80, duration=0.1, output_filename="plot.gi Name of the generated GIF file. """ - import imageio + import imageio.v2 as imageio import matplotlib.pyplot as plt # time stamps at which the images/plots will be created diff --git a/pybamm/version.py b/pybamm/version.py index f4624fbd18..85b9e0bb72 100644 --- a/pybamm/version.py +++ b/pybamm/version.py @@ -1 +1 @@ -__version__ = "22.5" +__version__ = "22.6" diff --git a/vcpkg.json b/vcpkg.json index d186733afd..00aab456ba 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -1,6 +1,6 @@ { "name": "pybamm", - "version-string": "22.5", + "version-string": "22.6", "dependencies": [ "casadi", {