From 557bc7d0bcc262ef5a201b37305fdc728117ff46 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 20 Jun 2022 23:45:02 +0530 Subject: [PATCH 01/10] add docs for asv --- docs/index.rst | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/docs/index.rst b/docs/index.rst index e0814f68d1..f554cc82fe 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -108,3 +108,31 @@ There are many ways to contribute to PyBaMM: tutorials/add-solver Before contributing, please read the `Contribution Guidelines `_. + +Benchmarking +============ + +PyBaMM uses `asv `_ for benchmarking performance. + +Installing asv +-------------- + +.. code:: bash + + pip install asv + +Running Benchmarks +------------------ + +.. code:: bash + + asv run + +Viewing results +--------------- + +.. code:: bash + + asv publish && asv preview + + From ed653669ecef97497b7405b4ae6df82cf06beb95 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 23 Jun 2022 13:31:39 +0530 Subject: [PATCH 02/10] add README.md for asv --- benchmarks/README.md | 83 ++++++++++++++++++++++++++++++++++++++++++++ docs/index.rst | 30 +--------------- 2 files changed, 84 insertions(+), 29 deletions(-) create mode 100644 benchmarks/README.md 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/docs/index.rst b/docs/index.rst index f554cc82fe..36c265a929 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -107,32 +107,4 @@ There are many ways to contribute to PyBaMM: tutorials/add-spatial-method tutorials/add-solver -Before contributing, please read the `Contribution Guidelines `_. - -Benchmarking -============ - -PyBaMM uses `asv `_ for benchmarking performance. - -Installing asv --------------- - -.. code:: bash - - pip install asv - -Running Benchmarks ------------------- - -.. code:: bash - - asv run - -Viewing results ---------------- - -.. code:: bash - - asv publish && asv preview - - +Before contributing, please read the `Contribution Guidelines `_. \ No newline at end of file From b4cc44c820d290b095b3a8c4bacd28f15220d102 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 23 Jun 2022 19:08:54 +0530 Subject: [PATCH 03/10] memory benchmarks --- benchmarks/memory_sims.py | 62 +++++ benchmarks/memory_unit_benchmarks.py | 89 ++++++ benchmarks/time_setup_models_and_sims.py | 234 ++++++++-------- benchmarks/time_sims_experiments.py | 108 ++++---- benchmarks/time_solve_models.py | 336 +++++++++++------------ benchmarks/unit_benchmarks.py | 170 ++++++------ 6 files changed, 575 insertions(+), 424 deletions(-) create mode 100644 benchmarks/memory_sims.py create mode 100644 benchmarks/memory_unit_benchmarks.py diff --git a/benchmarks/memory_sims.py b/benchmarks/memory_sims.py new file mode 100644 index 0000000000..fb11eb9ac1 --- /dev/null +++ b/benchmarks/memory_sims.py @@ -0,0 +1,62 @@ +# 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 \ No newline at end of file diff --git a/benchmarks/memory_unit_benchmarks.py b/benchmarks/memory_unit_benchmarks.py new file mode 100644 index 0000000000..2b5e106cc4 --- /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 \ No newline at end of file diff --git a/benchmarks/time_setup_models_and_sims.py b/benchmarks/time_setup_models_and_sims.py index a2689e7b2a..43a73418ea 100644 --- a/benchmarks/time_setup_models_and_sims.py +++ b/benchmarks/time_setup_models_and_sims.py @@ -1,117 +1,117 @@ -import pybamm - -parameters = [ - "Marquis2019", - "ORegan2021", - "NCA_Kim2011", - "Prada2013", - "Ai2020", - "Ramadass2004", - "Mohtat2020", - "Chen2020", - "Chen2020_plating", - "Ecker2015", -] - - -def compute_discretisation(model, param): - var_pts = { - pybamm.standard_spatial_vars.x_n: 20, - pybamm.standard_spatial_vars.x_s: 20, - pybamm.standard_spatial_vars.x_p: 20, - pybamm.standard_spatial_vars.r_n: 30, - pybamm.standard_spatial_vars.r_p: 30, - pybamm.standard_spatial_vars.y: 10, - pybamm.standard_spatial_vars.z: 10, - } - geometry = model.default_geometry - param.process_geometry(geometry) - mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts) - return pybamm.Discretisation(mesh, model.default_spatial_methods) - - -class TimeBuildSPM: - param_names = ["parameter"] - params = parameters - - def time_setup_SPM(self, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.SPM() - self.param.process_model(self.model) - compute_discretisation(self.model, self.param).process_model(self.model) - - -class TimeBuildSPMe: - param_names = ["parameter"] - params = parameters - - def time_setup_SPMe(self, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.SPMe() - self.param.process_model(self.model) - compute_discretisation(self.model, self.param).process_model(self.model) - - -class TimeBuildDFN: - param_names = ["parameter"] - params = parameters - - def time_setup_DFN(self, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.DFN() - self.param.process_model(self.model) - compute_discretisation(self.model, self.param).process_model(self.model) - - -class TimeBuildSPMSimulation: - param_names = ["with experiment", "parameter"] - params = ([False, True], parameters) - - def time_setup_SPM_simulation(self, with_experiment, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.SPM() - if with_experiment: - exp = pybamm.Experiment( - [ - "Discharge at 0.1C until 3.105 V", - ] - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) - else: - pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) - - -class TimeBuildSPMeSimulation: - param_names = ["with experiment", "parameter"] - params = ([False, True], parameters) - - def time_setup_SPMe_simulation(self, with_experiment, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.SPMe() - if with_experiment: - exp = pybamm.Experiment( - [ - "Discharge at 0.1C until 3.105 V", - ] - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) - else: - pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) - - -class TimeBuildDFNSimulation: - param_names = ["with experiment", "parameter"] - params = ([False, True], parameters) - - def time_setup_DFN_simulation(self, with_experiment, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.DFN() - if with_experiment: - exp = pybamm.Experiment( - [ - "Discharge at 0.1C until 3.105 V", - ] - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) - else: - pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) +# import pybamm + +# parameters = [ +# "Marquis2019", +# "ORegan2021", +# "NCA_Kim2011", +# "Prada2013", +# "Ai2020", +# "Ramadass2004", +# "Mohtat2020", +# "Chen2020", +# "Chen2020_plating", +# "Ecker2015", +# ] + + +# def compute_discretisation(model, param): +# var_pts = { +# pybamm.standard_spatial_vars.x_n: 20, +# pybamm.standard_spatial_vars.x_s: 20, +# pybamm.standard_spatial_vars.x_p: 20, +# pybamm.standard_spatial_vars.r_n: 30, +# pybamm.standard_spatial_vars.r_p: 30, +# pybamm.standard_spatial_vars.y: 10, +# pybamm.standard_spatial_vars.z: 10, +# } +# geometry = model.default_geometry +# param.process_geometry(geometry) +# mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts) +# return pybamm.Discretisation(mesh, model.default_spatial_methods) + + +# class TimeBuildSPM: +# param_names = ["parameter"] +# params = parameters + +# def time_setup_SPM(self, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.SPM() +# self.param.process_model(self.model) +# compute_discretisation(self.model, self.param).process_model(self.model) + + +# class TimeBuildSPMe: +# param_names = ["parameter"] +# params = parameters + +# def time_setup_SPMe(self, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.SPMe() +# self.param.process_model(self.model) +# compute_discretisation(self.model, self.param).process_model(self.model) + + +# class TimeBuildDFN: +# param_names = ["parameter"] +# params = parameters + +# def time_setup_DFN(self, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.DFN() +# self.param.process_model(self.model) +# compute_discretisation(self.model, self.param).process_model(self.model) + + +# class TimeBuildSPMSimulation: +# param_names = ["with experiment", "parameter"] +# params = ([False, True], parameters) + +# def time_setup_SPM_simulation(self, with_experiment, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.SPM() +# if with_experiment: +# exp = pybamm.Experiment( +# [ +# "Discharge at 0.1C until 3.105 V", +# ] +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# else: +# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) + + +# class TimeBuildSPMeSimulation: +# param_names = ["with experiment", "parameter"] +# params = ([False, True], parameters) + +# def time_setup_SPMe_simulation(self, with_experiment, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.SPMe() +# if with_experiment: +# exp = pybamm.Experiment( +# [ +# "Discharge at 0.1C until 3.105 V", +# ] +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# else: +# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) + + +# class TimeBuildDFNSimulation: +# param_names = ["with experiment", "parameter"] +# params = ([False, True], parameters) + +# def time_setup_DFN_simulation(self, with_experiment, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.DFN() +# if with_experiment: +# exp = pybamm.Experiment( +# [ +# "Discharge at 0.1C until 3.105 V", +# ] +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# else: +# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) diff --git a/benchmarks/time_sims_experiments.py b/benchmarks/time_sims_experiments.py index 9bbf31fc80..a0a07b2599 100644 --- a/benchmarks/time_sims_experiments.py +++ b/benchmarks/time_sims_experiments.py @@ -1,67 +1,67 @@ -import pybamm +# import pybamm -parameters = ["Marquis2019", "Chen2020"] +# parameters = ["Marquis2019", "Chen2020"] -class TimeSPMSimulationCCCV: - param_names = ["parameter"] - params = parameters +# class TimeSPMSimulationCCCV: +# param_names = ["parameter"] +# params = parameters - def time_setup_SPM_simulation(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", - ] - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# def time_setup_SPM_simulation(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", +# ] +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -class TimeDFNSimulationCCCV: - param_names = ["parameter"] - params = parameters +# class TimeDFNSimulationCCCV: +# param_names = ["parameter"] +# params = parameters - def time_setup_SPM_simulation(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", - ] - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# def time_setup_SPM_simulation(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", +# ] +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -class TimeSPMSimulationGITT: - param_names = ["parameter"] - params = parameters +# class TimeSPMSimulationGITT: +# param_names = ["parameter"] +# params = parameters - def time_setup_SPM_simulation(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 - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# def time_setup_SPM_simulation(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 +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -class TimeDFNSimulationGITT: - param_names = ["parameter"] - params = parameters +# class TimeDFNSimulationGITT: +# param_names = ["parameter"] +# params = parameters - def time_setup_SPM_simulation(self, parameters): - self.param = pybamm.ParameterValues(parameters) - self.model = pybamm.lithium_ion.DFN() - exp = pybamm.Experiment( - [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 - ) - pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) +# def time_setup_SPM_simulation(self, parameters): +# self.param = pybamm.ParameterValues(parameters) +# self.model = pybamm.lithium_ion.DFN() +# exp = pybamm.Experiment( +# [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 +# ) +# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) diff --git a/benchmarks/time_solve_models.py b/benchmarks/time_solve_models.py index bf4a11ead4..be19e8d584 100644 --- a/benchmarks/time_solve_models.py +++ b/benchmarks/time_solve_models.py @@ -1,171 +1,171 @@ # Write the benchmarking functions here. # See "Writing benchmarks" in the asv docs for more information. -import pybamm -import numpy as np - - -def solve_model_once(model, solver, t_eval): - solver.solve(model, t_eval=t_eval) - - -class TimeSolveSPM: - param_names = ['solve first', 'parameter'] - params = ( - [False, True], - [ - "Marquis2019", - "ORegan2021", - "NCA_Kim2011", - "Prada2013", - # "Ai2020", - "Ramadass2004", - "Mohtat2020", - "Chen2020", - "Chen2020_plating", - "Ecker2015", - ], - ) - solver = pybamm.CasadiSolver() - - def setup(self, solve_first, parameters): - self.model = pybamm.lithium_ion.SPM() - c_rate = 1 - tmax = 4000 / c_rate - nb_points = 500 - self.t_eval = np.linspace(0, tmax, nb_points) - geometry = self.model.default_geometry - - # load parameter values and process model and geometry - param = pybamm.ParameterValues(parameters) - param.process_model(self.model) - param.process_geometry(geometry) - - # set mesh - var_pts = { - "x_n": 20, - "x_s": 20, - "x_p": 20, - "r_n": 30, - "r_p": 30, - "y": 10, - "z": 10, - } - mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - - # discretise model - disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) - disc.process_model(self.model) - if solve_first: - solve_model_once(self.model, TimeSolveSPM.solver, self.t_eval) - - def time_solve_model(self, solve_first, parameters): - TimeSolveSPM.solver.solve(self.model, t_eval=self.t_eval) - - -class TimeSolveSPMe: - param_names = ['solve first', 'parameter'] - params = ( - [False, True], - [ - "Marquis2019", - "ORegan2021", - "NCA_Kim2011", - "Prada2013", - # "Ai2020", - "Ramadass2004", - "Mohtat2020", - "Chen2020", - "Chen2020_plating", - "Ecker2015", - ], - ) - solver = pybamm.CasadiSolver() - - def setup(self, solve_first, parameters): - self.model = pybamm.lithium_ion.SPMe() - c_rate = 1 - tmax = 4000 / c_rate - nb_points = 500 - self.t_eval = np.linspace(0, tmax, nb_points) - geometry = self.model.default_geometry - - # load parameter values and process model and geometry - param = pybamm.ParameterValues(parameters) - param.process_model(self.model) - param.process_geometry(geometry) - - # set mesh - var_pts = { - "x_n": 20, - "x_s": 20, - "x_p": 20, - "r_n": 30, - "r_p": 30, - "y": 10, - "z": 10, - } - mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - - # discretise model - disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) - disc.process_model(self.model) - if solve_first: - solve_model_once(self.model, TimeSolveSPMe.solver, self.t_eval) - - def time_solve_model(self, solve_first, parameters): - TimeSolveSPMe.solver.solve(self.model, t_eval=self.t_eval) - - -class TimeSolveDFN: - param_names = ['solve first', 'parameter'] - params = ( - [False, True], - [ - "Marquis2019", - "ORegan2021", - # "NCA_Kim2011", - "Prada2013", - "Ai2020", - "Ramadass2004", - # "Mohtat2020", - "Chen2020", - "Chen2020_plating", - "Ecker2015", - ], - ) - solver = pybamm.CasadiSolver() - - def setup(self, solve_first, parameters): - self.model = pybamm.lithium_ion.DFN() - c_rate = 1 - tmax = 4000 / c_rate - nb_points = 500 - self.t_eval = np.linspace(0, tmax, nb_points) - geometry = self.model.default_geometry - - # load parameter values and process model and geometry - param = pybamm.ParameterValues(parameters) - param.process_model(self.model) - param.process_geometry(geometry) - - # set mesh - var_pts = { - "x_n": 20, - "x_s": 20, - "x_p": 20, - "r_n": 30, - "r_p": 30, - "y": 10, - "z": 10, - } - mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - - # discretise model - disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) - disc.process_model(self.model) - if solve_first: - solve_model_once(self.model, TimeSolveDFN.solver, self.t_eval) - - def time_solve_model(self, solve_first, parameters): - TimeSolveDFN.solver.solve(self.model, t_eval=self.t_eval) +# import pybamm +# import numpy as np + + +# def solve_model_once(model, solver, t_eval): +# solver.solve(model, t_eval=t_eval) + + +# class TimeSolveSPM: +# param_names = ['solve first', 'parameter'] +# params = ( +# [False, True], +# [ +# "Marquis2019", +# "ORegan2021", +# "NCA_Kim2011", +# "Prada2013", +# # "Ai2020", +# "Ramadass2004", +# "Mohtat2020", +# "Chen2020", +# "Chen2020_plating", +# "Ecker2015", +# ], +# ) +# solver = pybamm.CasadiSolver() + +# def setup(self, solve_first, parameters): +# self.model = pybamm.lithium_ion.SPM() +# c_rate = 1 +# tmax = 4000 / c_rate +# nb_points = 500 +# self.t_eval = np.linspace(0, tmax, nb_points) +# geometry = self.model.default_geometry + +# # load parameter values and process model and geometry +# param = pybamm.ParameterValues(parameters) +# param.process_model(self.model) +# param.process_geometry(geometry) + +# # set mesh +# var_pts = { +# "x_n": 20, +# "x_s": 20, +# "x_p": 20, +# "r_n": 30, +# "r_p": 30, +# "y": 10, +# "z": 10, +# } +# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + +# # discretise model +# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) +# disc.process_model(self.model) +# if solve_first: +# solve_model_once(self.model, TimeSolveSPM.solver, self.t_eval) + +# def time_solve_model(self, solve_first, parameters): +# TimeSolveSPM.solver.solve(self.model, t_eval=self.t_eval) + + +# class TimeSolveSPMe: +# param_names = ['solve first', 'parameter'] +# params = ( +# [False, True], +# [ +# "Marquis2019", +# "ORegan2021", +# "NCA_Kim2011", +# "Prada2013", +# # "Ai2020", +# "Ramadass2004", +# "Mohtat2020", +# "Chen2020", +# "Chen2020_plating", +# "Ecker2015", +# ], +# ) +# solver = pybamm.CasadiSolver() + +# def setup(self, solve_first, parameters): +# self.model = pybamm.lithium_ion.SPMe() +# c_rate = 1 +# tmax = 4000 / c_rate +# nb_points = 500 +# self.t_eval = np.linspace(0, tmax, nb_points) +# geometry = self.model.default_geometry + +# # load parameter values and process model and geometry +# param = pybamm.ParameterValues(parameters) +# param.process_model(self.model) +# param.process_geometry(geometry) + +# # set mesh +# var_pts = { +# "x_n": 20, +# "x_s": 20, +# "x_p": 20, +# "r_n": 30, +# "r_p": 30, +# "y": 10, +# "z": 10, +# } +# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + +# # discretise model +# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) +# disc.process_model(self.model) +# if solve_first: +# solve_model_once(self.model, TimeSolveSPMe.solver, self.t_eval) + +# def time_solve_model(self, solve_first, parameters): +# TimeSolveSPMe.solver.solve(self.model, t_eval=self.t_eval) + + +# class TimeSolveDFN: +# param_names = ['solve first', 'parameter'] +# params = ( +# [False, True], +# [ +# "Marquis2019", +# "ORegan2021", +# # "NCA_Kim2011", +# "Prada2013", +# "Ai2020", +# "Ramadass2004", +# # "Mohtat2020", +# "Chen2020", +# "Chen2020_plating", +# "Ecker2015", +# ], +# ) +# solver = pybamm.CasadiSolver() + +# def setup(self, solve_first, parameters): +# self.model = pybamm.lithium_ion.DFN() +# c_rate = 1 +# tmax = 4000 / c_rate +# nb_points = 500 +# self.t_eval = np.linspace(0, tmax, nb_points) +# geometry = self.model.default_geometry + +# # load parameter values and process model and geometry +# param = pybamm.ParameterValues(parameters) +# param.process_model(self.model) +# param.process_geometry(geometry) + +# # set mesh +# var_pts = { +# "x_n": 20, +# "x_s": 20, +# "x_p": 20, +# "r_n": 30, +# "r_p": 30, +# "y": 10, +# "z": 10, +# } +# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + +# # discretise model +# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) +# disc.process_model(self.model) +# if solve_first: +# solve_model_once(self.model, TimeSolveDFN.solver, self.t_eval) + +# def time_solve_model(self, solve_first, parameters): +# TimeSolveDFN.solver.solve(self.model, t_eval=self.t_eval) diff --git a/benchmarks/unit_benchmarks.py b/benchmarks/unit_benchmarks.py index acee9c210a..3d747f77e3 100644 --- a/benchmarks/unit_benchmarks.py +++ b/benchmarks/unit_benchmarks.py @@ -1,85 +1,85 @@ -import pybamm -import numpy as np - - -class TimeCreateExpression: - def time_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, - } - - -class TimeParameteriseModel: - def setup(self): - TimeCreateExpression.time_create_expression(self) - - def time_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) - - -class TimeDiscretiseModel: - def setup(self): - TimeCreateExpression.time_create_expression(self) - TimeParameteriseModel.time_parameterise(self) - - def time_discretise(self): - TimeCreateExpression.time_create_expression(self) - TimeParameteriseModel.time_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) - - -class TimeSolveModel: - def setup(self): - TimeCreateExpression.time_create_expression(self) - TimeParameteriseModel.time_parameterise(self) - TimeDiscretiseModel.time_discretise(self) - - def time_solve(self): - solver = pybamm.ScipySolver() - t = np.linspace(0, 3600, 600) - solver.solve(self.model, t) +# import pybamm +# import numpy as np + + +# class TimeCreateExpression: +# def time_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, +# } + + +# class TimeParameteriseModel: +# def setup(self): +# TimeCreateExpression.time_create_expression(self) + +# def time_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) + + +# class TimeDiscretiseModel: +# def setup(self): +# TimeCreateExpression.time_create_expression(self) +# TimeParameteriseModel.time_parameterise(self) + +# def time_discretise(self): +# TimeCreateExpression.time_create_expression(self) +# TimeParameteriseModel.time_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) + + +# class TimeSolveModel: +# def setup(self): +# TimeCreateExpression.time_create_expression(self) +# TimeParameteriseModel.time_parameterise(self) +# TimeDiscretiseModel.time_discretise(self) + +# def time_solve(self): +# solver = pybamm.ScipySolver() +# t = np.linspace(0, 3600, 600) +# solver.solve(self.model, t) From e78995bbe9ceeb8747ee683e5cd91332437b54c0 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 23 Jun 2022 19:10:12 +0530 Subject: [PATCH 04/10] memory benchmarks typo --- benchmarks/time_setup_models_and_sims.py | 234 ++++++++-------- benchmarks/time_sims_experiments.py | 108 ++++---- benchmarks/time_solve_models.py | 336 +++++++++++------------ benchmarks/unit_benchmarks.py | 170 ++++++------ 4 files changed, 424 insertions(+), 424 deletions(-) diff --git a/benchmarks/time_setup_models_and_sims.py b/benchmarks/time_setup_models_and_sims.py index 43a73418ea..a2689e7b2a 100644 --- a/benchmarks/time_setup_models_and_sims.py +++ b/benchmarks/time_setup_models_and_sims.py @@ -1,117 +1,117 @@ -# import pybamm - -# parameters = [ -# "Marquis2019", -# "ORegan2021", -# "NCA_Kim2011", -# "Prada2013", -# "Ai2020", -# "Ramadass2004", -# "Mohtat2020", -# "Chen2020", -# "Chen2020_plating", -# "Ecker2015", -# ] - - -# def compute_discretisation(model, param): -# var_pts = { -# pybamm.standard_spatial_vars.x_n: 20, -# pybamm.standard_spatial_vars.x_s: 20, -# pybamm.standard_spatial_vars.x_p: 20, -# pybamm.standard_spatial_vars.r_n: 30, -# pybamm.standard_spatial_vars.r_p: 30, -# pybamm.standard_spatial_vars.y: 10, -# pybamm.standard_spatial_vars.z: 10, -# } -# geometry = model.default_geometry -# param.process_geometry(geometry) -# mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts) -# return pybamm.Discretisation(mesh, model.default_spatial_methods) - - -# class TimeBuildSPM: -# param_names = ["parameter"] -# params = parameters - -# def time_setup_SPM(self, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.SPM() -# self.param.process_model(self.model) -# compute_discretisation(self.model, self.param).process_model(self.model) - - -# class TimeBuildSPMe: -# param_names = ["parameter"] -# params = parameters - -# def time_setup_SPMe(self, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.SPMe() -# self.param.process_model(self.model) -# compute_discretisation(self.model, self.param).process_model(self.model) - - -# class TimeBuildDFN: -# param_names = ["parameter"] -# params = parameters - -# def time_setup_DFN(self, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.DFN() -# self.param.process_model(self.model) -# compute_discretisation(self.model, self.param).process_model(self.model) - - -# class TimeBuildSPMSimulation: -# param_names = ["with experiment", "parameter"] -# params = ([False, True], parameters) - -# def time_setup_SPM_simulation(self, with_experiment, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.SPM() -# if with_experiment: -# exp = pybamm.Experiment( -# [ -# "Discharge at 0.1C until 3.105 V", -# ] -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# else: -# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) - - -# class TimeBuildSPMeSimulation: -# param_names = ["with experiment", "parameter"] -# params = ([False, True], parameters) - -# def time_setup_SPMe_simulation(self, with_experiment, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.SPMe() -# if with_experiment: -# exp = pybamm.Experiment( -# [ -# "Discharge at 0.1C until 3.105 V", -# ] -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# else: -# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) - - -# class TimeBuildDFNSimulation: -# param_names = ["with experiment", "parameter"] -# params = ([False, True], parameters) - -# def time_setup_DFN_simulation(self, with_experiment, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.DFN() -# if with_experiment: -# exp = pybamm.Experiment( -# [ -# "Discharge at 0.1C until 3.105 V", -# ] -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# else: -# pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) +import pybamm + +parameters = [ + "Marquis2019", + "ORegan2021", + "NCA_Kim2011", + "Prada2013", + "Ai2020", + "Ramadass2004", + "Mohtat2020", + "Chen2020", + "Chen2020_plating", + "Ecker2015", +] + + +def compute_discretisation(model, param): + var_pts = { + pybamm.standard_spatial_vars.x_n: 20, + pybamm.standard_spatial_vars.x_s: 20, + pybamm.standard_spatial_vars.x_p: 20, + pybamm.standard_spatial_vars.r_n: 30, + pybamm.standard_spatial_vars.r_p: 30, + pybamm.standard_spatial_vars.y: 10, + pybamm.standard_spatial_vars.z: 10, + } + geometry = model.default_geometry + param.process_geometry(geometry) + mesh = pybamm.Mesh(geometry, model.default_submesh_types, var_pts) + return pybamm.Discretisation(mesh, model.default_spatial_methods) + + +class TimeBuildSPM: + param_names = ["parameter"] + params = parameters + + def time_setup_SPM(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPM() + self.param.process_model(self.model) + compute_discretisation(self.model, self.param).process_model(self.model) + + +class TimeBuildSPMe: + param_names = ["parameter"] + params = parameters + + def time_setup_SPMe(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPMe() + self.param.process_model(self.model) + compute_discretisation(self.model, self.param).process_model(self.model) + + +class TimeBuildDFN: + param_names = ["parameter"] + params = parameters + + def time_setup_DFN(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.DFN() + self.param.process_model(self.model) + compute_discretisation(self.model, self.param).process_model(self.model) + + +class TimeBuildSPMSimulation: + param_names = ["with experiment", "parameter"] + params = ([False, True], parameters) + + def time_setup_SPM_simulation(self, with_experiment, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPM() + if with_experiment: + exp = pybamm.Experiment( + [ + "Discharge at 0.1C until 3.105 V", + ] + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + else: + pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) + + +class TimeBuildSPMeSimulation: + param_names = ["with experiment", "parameter"] + params = ([False, True], parameters) + + def time_setup_SPMe_simulation(self, with_experiment, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.SPMe() + if with_experiment: + exp = pybamm.Experiment( + [ + "Discharge at 0.1C until 3.105 V", + ] + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + else: + pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) + + +class TimeBuildDFNSimulation: + param_names = ["with experiment", "parameter"] + params = ([False, True], parameters) + + def time_setup_DFN_simulation(self, with_experiment, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.DFN() + if with_experiment: + exp = pybamm.Experiment( + [ + "Discharge at 0.1C until 3.105 V", + ] + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + else: + pybamm.Simulation(self.model, parameter_values=self.param, C_rate=1) diff --git a/benchmarks/time_sims_experiments.py b/benchmarks/time_sims_experiments.py index a0a07b2599..9bbf31fc80 100644 --- a/benchmarks/time_sims_experiments.py +++ b/benchmarks/time_sims_experiments.py @@ -1,67 +1,67 @@ -# import pybamm +import pybamm -# parameters = ["Marquis2019", "Chen2020"] +parameters = ["Marquis2019", "Chen2020"] -# class TimeSPMSimulationCCCV: -# param_names = ["parameter"] -# params = parameters +class TimeSPMSimulationCCCV: + param_names = ["parameter"] + params = parameters -# def time_setup_SPM_simulation(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", -# ] -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + def time_setup_SPM_simulation(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", + ] + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# class TimeDFNSimulationCCCV: -# param_names = ["parameter"] -# params = parameters +class TimeDFNSimulationCCCV: + param_names = ["parameter"] + params = parameters -# def time_setup_SPM_simulation(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", -# ] -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + def time_setup_SPM_simulation(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", + ] + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# class TimeSPMSimulationGITT: -# param_names = ["parameter"] -# params = parameters +class TimeSPMSimulationGITT: + param_names = ["parameter"] + params = parameters -# def time_setup_SPM_simulation(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 -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + def time_setup_SPM_simulation(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 + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) -# class TimeDFNSimulationGITT: -# param_names = ["parameter"] -# params = parameters +class TimeDFNSimulationGITT: + param_names = ["parameter"] + params = parameters -# def time_setup_SPM_simulation(self, parameters): -# self.param = pybamm.ParameterValues(parameters) -# self.model = pybamm.lithium_ion.DFN() -# exp = pybamm.Experiment( -# [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 -# ) -# pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) + def time_setup_SPM_simulation(self, parameters): + self.param = pybamm.ParameterValues(parameters) + self.model = pybamm.lithium_ion.DFN() + exp = pybamm.Experiment( + [("Discharge at C/20 for 1 hour", "Rest for 1 hour")] * 20 + ) + pybamm.Simulation(self.model, parameter_values=self.param, experiment=exp) diff --git a/benchmarks/time_solve_models.py b/benchmarks/time_solve_models.py index be19e8d584..bf4a11ead4 100644 --- a/benchmarks/time_solve_models.py +++ b/benchmarks/time_solve_models.py @@ -1,171 +1,171 @@ # Write the benchmarking functions here. # See "Writing benchmarks" in the asv docs for more information. -# import pybamm -# import numpy as np - - -# def solve_model_once(model, solver, t_eval): -# solver.solve(model, t_eval=t_eval) - - -# class TimeSolveSPM: -# param_names = ['solve first', 'parameter'] -# params = ( -# [False, True], -# [ -# "Marquis2019", -# "ORegan2021", -# "NCA_Kim2011", -# "Prada2013", -# # "Ai2020", -# "Ramadass2004", -# "Mohtat2020", -# "Chen2020", -# "Chen2020_plating", -# "Ecker2015", -# ], -# ) -# solver = pybamm.CasadiSolver() - -# def setup(self, solve_first, parameters): -# self.model = pybamm.lithium_ion.SPM() -# c_rate = 1 -# tmax = 4000 / c_rate -# nb_points = 500 -# self.t_eval = np.linspace(0, tmax, nb_points) -# geometry = self.model.default_geometry - -# # load parameter values and process model and geometry -# param = pybamm.ParameterValues(parameters) -# param.process_model(self.model) -# param.process_geometry(geometry) - -# # set mesh -# var_pts = { -# "x_n": 20, -# "x_s": 20, -# "x_p": 20, -# "r_n": 30, -# "r_p": 30, -# "y": 10, -# "z": 10, -# } -# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - -# # discretise model -# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) -# disc.process_model(self.model) -# if solve_first: -# solve_model_once(self.model, TimeSolveSPM.solver, self.t_eval) - -# def time_solve_model(self, solve_first, parameters): -# TimeSolveSPM.solver.solve(self.model, t_eval=self.t_eval) - - -# class TimeSolveSPMe: -# param_names = ['solve first', 'parameter'] -# params = ( -# [False, True], -# [ -# "Marquis2019", -# "ORegan2021", -# "NCA_Kim2011", -# "Prada2013", -# # "Ai2020", -# "Ramadass2004", -# "Mohtat2020", -# "Chen2020", -# "Chen2020_plating", -# "Ecker2015", -# ], -# ) -# solver = pybamm.CasadiSolver() - -# def setup(self, solve_first, parameters): -# self.model = pybamm.lithium_ion.SPMe() -# c_rate = 1 -# tmax = 4000 / c_rate -# nb_points = 500 -# self.t_eval = np.linspace(0, tmax, nb_points) -# geometry = self.model.default_geometry - -# # load parameter values and process model and geometry -# param = pybamm.ParameterValues(parameters) -# param.process_model(self.model) -# param.process_geometry(geometry) - -# # set mesh -# var_pts = { -# "x_n": 20, -# "x_s": 20, -# "x_p": 20, -# "r_n": 30, -# "r_p": 30, -# "y": 10, -# "z": 10, -# } -# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - -# # discretise model -# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) -# disc.process_model(self.model) -# if solve_first: -# solve_model_once(self.model, TimeSolveSPMe.solver, self.t_eval) - -# def time_solve_model(self, solve_first, parameters): -# TimeSolveSPMe.solver.solve(self.model, t_eval=self.t_eval) - - -# class TimeSolveDFN: -# param_names = ['solve first', 'parameter'] -# params = ( -# [False, True], -# [ -# "Marquis2019", -# "ORegan2021", -# # "NCA_Kim2011", -# "Prada2013", -# "Ai2020", -# "Ramadass2004", -# # "Mohtat2020", -# "Chen2020", -# "Chen2020_plating", -# "Ecker2015", -# ], -# ) -# solver = pybamm.CasadiSolver() - -# def setup(self, solve_first, parameters): -# self.model = pybamm.lithium_ion.DFN() -# c_rate = 1 -# tmax = 4000 / c_rate -# nb_points = 500 -# self.t_eval = np.linspace(0, tmax, nb_points) -# geometry = self.model.default_geometry - -# # load parameter values and process model and geometry -# param = pybamm.ParameterValues(parameters) -# param.process_model(self.model) -# param.process_geometry(geometry) - -# # set mesh -# var_pts = { -# "x_n": 20, -# "x_s": 20, -# "x_p": 20, -# "r_n": 30, -# "r_p": 30, -# "y": 10, -# "z": 10, -# } -# mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) - -# # discretise model -# disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) -# disc.process_model(self.model) -# if solve_first: -# solve_model_once(self.model, TimeSolveDFN.solver, self.t_eval) - -# def time_solve_model(self, solve_first, parameters): -# TimeSolveDFN.solver.solve(self.model, t_eval=self.t_eval) +import pybamm +import numpy as np + + +def solve_model_once(model, solver, t_eval): + solver.solve(model, t_eval=t_eval) + + +class TimeSolveSPM: + param_names = ['solve first', 'parameter'] + params = ( + [False, True], + [ + "Marquis2019", + "ORegan2021", + "NCA_Kim2011", + "Prada2013", + # "Ai2020", + "Ramadass2004", + "Mohtat2020", + "Chen2020", + "Chen2020_plating", + "Ecker2015", + ], + ) + solver = pybamm.CasadiSolver() + + def setup(self, solve_first, parameters): + self.model = pybamm.lithium_ion.SPM() + c_rate = 1 + tmax = 4000 / c_rate + nb_points = 500 + self.t_eval = np.linspace(0, tmax, nb_points) + geometry = self.model.default_geometry + + # load parameter values and process model and geometry + param = pybamm.ParameterValues(parameters) + param.process_model(self.model) + param.process_geometry(geometry) + + # set mesh + var_pts = { + "x_n": 20, + "x_s": 20, + "x_p": 20, + "r_n": 30, + "r_p": 30, + "y": 10, + "z": 10, + } + mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + + # discretise model + disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) + disc.process_model(self.model) + if solve_first: + solve_model_once(self.model, TimeSolveSPM.solver, self.t_eval) + + def time_solve_model(self, solve_first, parameters): + TimeSolveSPM.solver.solve(self.model, t_eval=self.t_eval) + + +class TimeSolveSPMe: + param_names = ['solve first', 'parameter'] + params = ( + [False, True], + [ + "Marquis2019", + "ORegan2021", + "NCA_Kim2011", + "Prada2013", + # "Ai2020", + "Ramadass2004", + "Mohtat2020", + "Chen2020", + "Chen2020_plating", + "Ecker2015", + ], + ) + solver = pybamm.CasadiSolver() + + def setup(self, solve_first, parameters): + self.model = pybamm.lithium_ion.SPMe() + c_rate = 1 + tmax = 4000 / c_rate + nb_points = 500 + self.t_eval = np.linspace(0, tmax, nb_points) + geometry = self.model.default_geometry + + # load parameter values and process model and geometry + param = pybamm.ParameterValues(parameters) + param.process_model(self.model) + param.process_geometry(geometry) + + # set mesh + var_pts = { + "x_n": 20, + "x_s": 20, + "x_p": 20, + "r_n": 30, + "r_p": 30, + "y": 10, + "z": 10, + } + mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + + # discretise model + disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) + disc.process_model(self.model) + if solve_first: + solve_model_once(self.model, TimeSolveSPMe.solver, self.t_eval) + + def time_solve_model(self, solve_first, parameters): + TimeSolveSPMe.solver.solve(self.model, t_eval=self.t_eval) + + +class TimeSolveDFN: + param_names = ['solve first', 'parameter'] + params = ( + [False, True], + [ + "Marquis2019", + "ORegan2021", + # "NCA_Kim2011", + "Prada2013", + "Ai2020", + "Ramadass2004", + # "Mohtat2020", + "Chen2020", + "Chen2020_plating", + "Ecker2015", + ], + ) + solver = pybamm.CasadiSolver() + + def setup(self, solve_first, parameters): + self.model = pybamm.lithium_ion.DFN() + c_rate = 1 + tmax = 4000 / c_rate + nb_points = 500 + self.t_eval = np.linspace(0, tmax, nb_points) + geometry = self.model.default_geometry + + # load parameter values and process model and geometry + param = pybamm.ParameterValues(parameters) + param.process_model(self.model) + param.process_geometry(geometry) + + # set mesh + var_pts = { + "x_n": 20, + "x_s": 20, + "x_p": 20, + "r_n": 30, + "r_p": 30, + "y": 10, + "z": 10, + } + mesh = pybamm.Mesh(geometry, self.model.default_submesh_types, var_pts) + + # discretise model + disc = pybamm.Discretisation(mesh, self.model.default_spatial_methods) + disc.process_model(self.model) + if solve_first: + solve_model_once(self.model, TimeSolveDFN.solver, self.t_eval) + + def time_solve_model(self, solve_first, parameters): + TimeSolveDFN.solver.solve(self.model, t_eval=self.t_eval) diff --git a/benchmarks/unit_benchmarks.py b/benchmarks/unit_benchmarks.py index 3d747f77e3..acee9c210a 100644 --- a/benchmarks/unit_benchmarks.py +++ b/benchmarks/unit_benchmarks.py @@ -1,85 +1,85 @@ -# import pybamm -# import numpy as np - - -# class TimeCreateExpression: -# def time_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, -# } - - -# class TimeParameteriseModel: -# def setup(self): -# TimeCreateExpression.time_create_expression(self) - -# def time_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) - - -# class TimeDiscretiseModel: -# def setup(self): -# TimeCreateExpression.time_create_expression(self) -# TimeParameteriseModel.time_parameterise(self) - -# def time_discretise(self): -# TimeCreateExpression.time_create_expression(self) -# TimeParameteriseModel.time_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) - - -# class TimeSolveModel: -# def setup(self): -# TimeCreateExpression.time_create_expression(self) -# TimeParameteriseModel.time_parameterise(self) -# TimeDiscretiseModel.time_discretise(self) - -# def time_solve(self): -# solver = pybamm.ScipySolver() -# t = np.linspace(0, 3600, 600) -# solver.solve(self.model, t) +import pybamm +import numpy as np + + +class TimeCreateExpression: + def time_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, + } + + +class TimeParameteriseModel: + def setup(self): + TimeCreateExpression.time_create_expression(self) + + def time_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) + + +class TimeDiscretiseModel: + def setup(self): + TimeCreateExpression.time_create_expression(self) + TimeParameteriseModel.time_parameterise(self) + + def time_discretise(self): + TimeCreateExpression.time_create_expression(self) + TimeParameteriseModel.time_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) + + +class TimeSolveModel: + def setup(self): + TimeCreateExpression.time_create_expression(self) + TimeParameteriseModel.time_parameterise(self) + TimeDiscretiseModel.time_discretise(self) + + def time_solve(self): + solver = pybamm.ScipySolver() + t = np.linspace(0, 3600, 600) + solver.solve(self.model, t) From 62cf140f93164eadca3b23ef4990121bb20f96c6 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 23 Jun 2022 19:42:20 +0530 Subject: [PATCH 05/10] flake8 --- benchmarks/memory_sims.py | 2 +- benchmarks/memory_unit_benchmarks.py | 2 +- benchmarks/time_solve_models.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmarks/memory_sims.py b/benchmarks/memory_sims.py index fb11eb9ac1..bee2621506 100644 --- a/benchmarks/memory_sims.py +++ b/benchmarks/memory_sims.py @@ -59,4 +59,4 @@ # [("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 \ No newline at end of file +# return self.sim diff --git a/benchmarks/memory_unit_benchmarks.py b/benchmarks/memory_unit_benchmarks.py index 2b5e106cc4..4b20996b75 100644 --- a/benchmarks/memory_unit_benchmarks.py +++ b/benchmarks/memory_unit_benchmarks.py @@ -86,4 +86,4 @@ def mem_solve(self): solver = pybamm.ScipySolver() t = np.linspace(0, 3600, 600) solver.solve(self.model, t) - return solver \ No newline at end of file + 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], [ From 85386d79669a6a5e874b98ff2323cc4711f949c0 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Thu, 23 Jun 2022 19:45:12 +0530 Subject: [PATCH 06/10] uncommented code --- benchmarks/memory_sims.py | 141 +++++++++++++++++++++----------------- 1 file changed, 79 insertions(+), 62 deletions(-) diff --git a/benchmarks/memory_sims.py b/benchmarks/memory_sims.py index bee2621506..1857873476 100644 --- a/benchmarks/memory_sims.py +++ b/benchmarks/memory_sims.py @@ -1,62 +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 +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 From 424899db9986a077a84afb50e5cabc94aecdd47a Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Sun, 26 Jun 2022 18:56:16 +0530 Subject: [PATCH 07/10] remove benchmark docs from contributing.md --- CONTRIBUTING.md | 84 ------------------------------------------------- 1 file changed, 84 deletions(-) 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 From 729280a05aac0af648821de8021fca14c0c6c6fc Mon Sep 17 00:00:00 2001 From: tinosulzer Date: Tue, 28 Jun 2022 10:12:54 +0000 Subject: [PATCH 08/10] Update version to v22.6 --- CHANGELOG.md | 2 ++ CITATION.cff | 2 +- docs/conf.py | 2 +- pybamm/version.py | 2 +- vcpkg.json | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eea1055b77..3d7ccbd095 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # [Unreleased](https://github.com/pybamm-team/PyBaMM/) ## Features +# [v22.6](https://github.com/pybamm-team/PyBaMM/tree/v22.6) - 2022-06-30 + - Added partially reversible lithium plating model and new `OKane2022` parameter set to go with it ([#2043](https://github.com/pybamm-team/PyBaMM/pull/2043)) 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/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/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", { From c3d3efa2c1274c68a17e181b2b0f53bb269e8216 Mon Sep 17 00:00:00 2001 From: Priyanshu Agarwal Date: Tue, 28 Jun 2022 15:45:31 +0530 Subject: [PATCH 09/10] Update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d7ccbd095..1e0b8261d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ # [Unreleased](https://github.com/pybamm-team/PyBaMM/) -## Features + # [v22.6](https://github.com/pybamm-team/PyBaMM/tree/v22.6) - 2022-06-30 +## Features - Added partially reversible lithium plating model and new `OKane2022` parameter set to go with it ([#2043](https://github.com/pybamm-team/PyBaMM/pull/2043)) From 28e66a2d007714a9f5536c2e449f0b0145e8a02b Mon Sep 17 00:00:00 2001 From: Saransh Date: Tue, 28 Jun 2022 21:22:44 +0530 Subject: [PATCH 10/10] Use `imageio.v2` --- pybamm/plotting/quick_plot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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