Skip to content

Commit

Permalink
Merge pull request pybamm-team#3835 from pybamm-team/issue-3530-custo…
Browse files Browse the repository at this point in the history
…m-step

refactor experiment steps to allow customization by user
  • Loading branch information
valentinsulzer authored Mar 26, 2024
2 parents b17611e + 3670294 commit cba763a
Show file tree
Hide file tree
Showing 19 changed files with 1,046 additions and 550 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Added custom experiment steps ([#3835](https://github.com/pybamm-team/PyBaMM/pull/3835))
- Added support for macOS arm64 (M-series) platforms. ([#3789](https://github.com/pybamm-team/PyBaMM/pull/3789))
- Added the ability to specify a custom solver tolerance in `get_initial_stoichiometries` and related functions ([#3714](https://github.com/pybamm-team/PyBaMM/pull/3714))
- Modified `step` function to take an array of time `t_eval` as an argument and deprecated use of `npts`. ([#3627](https://github.com/pybamm-team/PyBaMM/pull/3627))
Expand Down
14 changes: 7 additions & 7 deletions benchmarks/different_model_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

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,
"x_n": 20,
"x_s": 20,
"x_p": 20,
"r_n": 30,
"r_p": 30,
"y": 10,
"z": 10,
}
geometry = model.default_geometry
param.process_geometry(geometry)
Expand Down
13 changes: 12 additions & 1 deletion docs/source/api/experiment/experiment_steps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ The following functions can be used to define steps in an experiment. Note that
These functions return the following step class, which is not intended to be used
directly:

.. autoclass:: pybamm.step._Step
.. autoclass:: pybamm.step.BaseStep
:members:

Custom steps
------------

Custom steps can be defined using either explicit or implicit control:

.. autoclass:: pybamm.step.CustomStepExplicit
:members:

.. autoclass:: pybamm.step.CustomStepImplicit
:members:

Step terminations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33mWARNING: pybamm 23.5 does not provide the extra 'cite'\u001b[0m\u001b[33m\n",
"\u001b[0m\u001b[33mWARNING: pybamm 23.5 does not provide the extra 'plot'\u001b[0m\u001b[33m\n",
"\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m23.0.1\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m23.2.1\u001b[0m\n",
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
"Note: you may need to restart the kernel to use updated packages.\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"At t = 57.3387, , mxstep steps taken before reaching tout.\n",
"At t = 57.3387 and h = 7.05477e-15, the corrector convergence failed repeatedly or with |h| = hmin.\n",
"At t = 57.3387, , mxstep steps taken before reaching tout.\n",
"At t = 57.3387, , mxstep steps taken before reaching tout.\n"
]
}
],
"source": [
Expand All @@ -46,21 +51,18 @@
"param = pybamm.ParameterValues(\"Ai2020\")\n",
"param.update({\"Negative electrode LAM constant proportional term [s-1]\": 1e-4 / 3600})\n",
"param.update({\"Positive electrode LAM constant proportional term [s-1]\": 1e-4 / 3600})\n",
"total_cycles = 2\n",
"experiment = pybamm.Experiment(\n",
" [\n",
" \"Discharge at 1C until 3 V\",\n",
" \"Rest for 600 seconds\",\n",
" \"Charge at 1C until 4.2 V\",\n",
" \"Hold at 4.199 V for 600 seconds\",\n",
" ]\n",
" * total_cycles\n",
")\n",
"sim = pybamm.Simulation(\n",
" model,\n",
" experiment=experiment,\n",
" parameter_values=param,\n",
" solver=pybamm.CasadiSolver(\"fast with events\"),\n",
")\n",
"solution = sim.solve(calc_esoh=False)"
]
Expand All @@ -80,12 +82,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "3558ac2f7db145baadec9a28e236483e",
"model_id": "d3d8dcb00eb7421a83a4655bfd8e1245",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=4.5113500706445695, step=0.04511350070644569"
"interactive(children=(FloatSlider(value=0.0, description='t', max=2.329196798170269, step=0.02329196798170269)"
]
},
"metadata": {},
Expand All @@ -94,7 +96,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f91cc5d2d00>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x169320050>"
]
},
"execution_count": 2,
Expand Down Expand Up @@ -129,15 +131,33 @@
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"At t = 57.3387, , mxstep steps taken before reaching tout.\n",
"At t = 57.3387 and h = 7.05477e-15, the corrector convergence failed repeatedly or with |h| = hmin.\n",
"At t = 57.3387, , mxstep steps taken before reaching tout.\n",
"At t = 57.3387, , mxstep steps taken before reaching tout.\n",
"At t = 57.3307, , mxstep steps taken before reaching tout.\n",
"At t = 57.3307, , mxstep steps taken before reaching tout.\n",
"At t = 57.3307, , mxstep steps taken before reaching tout.\n",
"At t = 57.3307, , mxstep steps taken before reaching tout.\n",
"At t = 57.2504, , mxstep steps taken before reaching tout.\n",
"At t = 57.2504, , mxstep steps taken before reaching tout.\n",
"At t = 57.2504, , mxstep steps taken before reaching tout.\n",
"At t = 57.2504, , mxstep steps taken before reaching tout.\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9ff0e45a0c8c47b2b8d21da91b6110c1",
"model_id": "6e6d0630770b475893301455ac4910c7",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=4.5113500706445695, step=0.04511350070644569"
"interactive(children=(FloatSlider(value=0.0, description='t', max=2.329196798170269, step=0.02329196798170269)"
]
},
"metadata": {},
Expand All @@ -146,7 +166,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f9179084910>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x175c86c10>"
]
},
"execution_count": 3,
Expand All @@ -166,7 +186,6 @@
" model,\n",
" experiment=experiment,\n",
" parameter_values=param,\n",
" solver=pybamm.CasadiSolver(\"fast with events\"),\n",
" )\n",
" solution = sim.solve(calc_esoh=False)\n",
" solutions.append(solution)\n",
Expand Down Expand Up @@ -204,12 +223,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "53f5eacbb94b4ae29acee57db4bf7785",
"model_id": "979c0f154595488da4fab0bd7cd66565",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=3.5075529064499813, step=0.03507552906449981"
"interactive(children=(FloatSlider(value=0.0, description='t', max=1.8531299069255607, step=0.01853129906925560"
]
},
"metadata": {},
Expand All @@ -218,7 +237,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f91cc77d9a0>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x2846e3b90>"
]
},
"execution_count": 4,
Expand All @@ -234,21 +253,7 @@
" }\n",
")\n",
"param = pybamm.ParameterValues(\"Chen2020\")\n",
"param.update(\n",
" {\n",
" \"Negative electrode reaction-driven LAM factor [m3.mol-1]\": 1e-3,\n",
" }\n",
")\n",
"total_cycles = 2\n",
"experiment = pybamm.Experiment(\n",
" [\n",
" \"Discharge at 1C until 3 V\",\n",
" \"Rest for 600 seconds\",\n",
" \"Charge at 1C until 4.2 V\",\n",
" \"Hold at 4.199 V for 600 seconds\",\n",
" ]\n",
" * total_cycles\n",
")\n",
"param.update({\"Negative electrode reaction-driven LAM factor [m3.mol-1]\": 1e-3})\n",
"sim = pybamm.Simulation(\n",
" model,\n",
" experiment=experiment,\n",
Expand Down Expand Up @@ -293,12 +298,12 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "15acf6373f874463ba95de522d12fc89",
"model_id": "42f77d86732043a795b8c3264fd755bc",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"interactive(children=(FloatSlider(value=0.0, description='t', max=3.4962610293431426, step=0.03496261029343142"
"interactive(children=(FloatSlider(value=0.0, description='t', max=1.8506642114311478, step=0.01850664211431147"
]
},
"metadata": {},
Expand All @@ -307,7 +312,7 @@
{
"data": {
"text/plain": [
"<pybamm.plotting.quick_plot.QuickPlot at 0x7f9170283dc0>"
"<pybamm.plotting.quick_plot.QuickPlot at 0x2852402d0>"
]
},
"execution_count": 5,
Expand All @@ -333,16 +338,6 @@
" },\n",
" check_already_exists=False,\n",
")\n",
"total_cycles = 2\n",
"experiment = pybamm.Experiment(\n",
" [\n",
" \"Discharge at 1C until 3 V\",\n",
" \"Rest for 600 seconds\",\n",
" \"Charge at 1C until 4.2 V\",\n",
" \"Hold at 4.199 V for 600 seconds\",\n",
" ]\n",
" * total_cycles\n",
")\n",
"sim = pybamm.Simulation(\n",
" model,\n",
" experiment=experiment,\n",
Expand Down Expand Up @@ -395,6 +390,13 @@
"source": [
"pybamm.print_citations()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit cba763a

Please sign in to comment.