From 51d915604c6c522154fec4a821c5a74c7ed5dcac Mon Sep 17 00:00:00 2001 From: R-Yash Date: Mon, 22 Jan 2024 13:26:20 +0530 Subject: [PATCH 1/8] Added more information to error when drive cycle starts at t>0 --- docs/source/api/experiment/experiment_steps.rst | 2 +- pybamm/experiment/step/_steps_util.py | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/source/api/experiment/experiment_steps.rst b/docs/source/api/experiment/experiment_steps.rst index 6a2e2abc31..61d800d922 100644 --- a/docs/source/api/experiment/experiment_steps.rst +++ b/docs/source/api/experiment/experiment_steps.rst @@ -1,7 +1,7 @@ Experiment step functions ========================= -The following functions can be used to define steps in an experiment. +The following functions can be used to define steps in an experiment. Note that the drive cycle must start at t=0 .. autofunction:: pybamm.step.string diff --git a/pybamm/experiment/step/_steps_util.py b/pybamm/experiment/step/_steps_util.py index f44cf52113..74ca01e215 100644 --- a/pybamm/experiment/step/_steps_util.py +++ b/pybamm/experiment/step/_steps_util.py @@ -120,8 +120,12 @@ def __init__( t, y = value[:, 0], value[:, 1] self.duration = t.max() + # Check that drive cycle starts at t=0 + if t[0] > 0: + raise ValueError("Drive cycle must start at t=0") + self.value = pybamm.Interpolant( - t, y, pybamm.t - pybamm.InputParameter("start time") + t, y, pybamm.t - pybamm.InputParameter("start time"),name = 'Current Drive Cycle' ) self.period = np.diff(t).min() else: From 7213645ea5df8396342debfd1d6441f90e10d2b6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jan 2024 08:04:02 +0000 Subject: [PATCH 2/8] style: pre-commit fixes --- pybamm/experiment/step/_steps_util.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pybamm/experiment/step/_steps_util.py b/pybamm/experiment/step/_steps_util.py index 74ca01e215..c22cdb8962 100644 --- a/pybamm/experiment/step/_steps_util.py +++ b/pybamm/experiment/step/_steps_util.py @@ -125,7 +125,10 @@ def __init__( raise ValueError("Drive cycle must start at t=0") self.value = pybamm.Interpolant( - t, y, pybamm.t - pybamm.InputParameter("start time"),name = 'Current Drive Cycle' + t, + y, + pybamm.t - pybamm.InputParameter("start time"), + name="Current Drive Cycle", ) self.period = np.diff(t).min() else: From 299857e720da600fec2d639954dcb255dd1e14b9 Mon Sep 17 00:00:00 2001 From: R-Yash Date: Mon, 22 Jan 2024 21:19:36 +0530 Subject: [PATCH 3/8] Changed Interpolant name to Drive Cycle and updated changelog.md accordingly --- CHANGELOG.md | 2 ++ pybamm/experiment/step/_steps_util.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1651ed889c..b4b9c94776 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Bug Fixes +- updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 + - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). - The SEI thickness decreased at some intervals when the 'electron-migration limited' model was used. It has been corrected ([#3622](https://github.com/pybamm-team/PyBaMM/pull/3622)) diff --git a/pybamm/experiment/step/_steps_util.py b/pybamm/experiment/step/_steps_util.py index c22cdb8962..6bf137ed1b 100644 --- a/pybamm/experiment/step/_steps_util.py +++ b/pybamm/experiment/step/_steps_util.py @@ -128,7 +128,7 @@ def __init__( t, y, pybamm.t - pybamm.InputParameter("start time"), - name="Current Drive Cycle", + name="Drive Cycle", ) self.period = np.diff(t).min() else: From 064cf54a55b6228fe9b07e9dc5d515b6afd2f15a Mon Sep 17 00:00:00 2001 From: "Eric G. Kratz" Date: Mon, 22 Jan 2024 10:55:39 -0500 Subject: [PATCH 4/8] Update CHANGELOG.md --- CHANGELOG.md | 1 - 1 file changed, 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b4b9c94776..5d48086eec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ ## Bug Fixes - updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 - - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). - The SEI thickness decreased at some intervals when the 'electron-migration limited' model was used. It has been corrected ([#3622](https://github.com/pybamm-team/PyBaMM/pull/3622)) From e3ddf7eb7586a03e1c5adc8bbae933334176075c Mon Sep 17 00:00:00 2001 From: R-Yash Date: Tue, 23 Jan 2024 13:02:40 +0530 Subject: [PATCH 5/8] Added test for Exception raised when drive cycle starts at t>0 --- tests/unit/test_experiments/test_experiment_steps.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/unit/test_experiments/test_experiment_steps.py b/tests/unit/test_experiments/test_experiment_steps.py index b99ae22395..1174394f80 100644 --- a/tests/unit/test_experiments/test_experiment_steps.py +++ b/tests/unit/test_experiments/test_experiment_steps.py @@ -5,7 +5,7 @@ import unittest import numpy as np from datetime import datetime - +from pybamm.experiment.step import _Step class TestExperimentSteps(unittest.TestCase): def test_step(self): @@ -275,7 +275,13 @@ def neg_stoich_cutoff(variables): event = neg_stoich_termination.get_event(variables, None) self.assertEqual(event.name, "Negative stoichiometry cut-off [experiment]") self.assertEqual(event.expression, 2) + + def test_drive_cycle_start_time(self): + # An example where start_time t>0 + t = np.array([[1, 1], [2, 2], [3, 3]]) + with self.assertRaisesRegex(ValueError, "Drive cycle must start at t=0"): + _Step('current', t) if __name__ == "__main__": print("Add -v for more debug output") From 07afa52835eb33dddba2e683a8f26c47689ccd2b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 Jan 2024 07:33:08 +0000 Subject: [PATCH 6/8] style: pre-commit fixes --- tests/unit/test_experiments/test_experiment_steps.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_experiments/test_experiment_steps.py b/tests/unit/test_experiments/test_experiment_steps.py index 1174394f80..7fc21bc14f 100644 --- a/tests/unit/test_experiments/test_experiment_steps.py +++ b/tests/unit/test_experiments/test_experiment_steps.py @@ -7,6 +7,7 @@ from datetime import datetime from pybamm.experiment.step import _Step + class TestExperimentSteps(unittest.TestCase): def test_step(self): step = pybamm.step._Step("current", 1, duration=3600) @@ -275,13 +276,14 @@ def neg_stoich_cutoff(variables): event = neg_stoich_termination.get_event(variables, None) self.assertEqual(event.name, "Negative stoichiometry cut-off [experiment]") self.assertEqual(event.expression, 2) - + def test_drive_cycle_start_time(self): # An example where start_time t>0 t = np.array([[1, 1], [2, 2], [3, 3]]) with self.assertRaisesRegex(ValueError, "Drive cycle must start at t=0"): - _Step('current', t) + _Step("current", t) + if __name__ == "__main__": print("Add -v for more debug output") From 21c460f249a8470693641c48daee5924056729c6 Mon Sep 17 00:00:00 2001 From: "Eric G. Kratz" Date: Wed, 24 Jan 2024 08:59:38 -0500 Subject: [PATCH 7/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f0ed82cd..dbb58ddd3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Bug Fixes -- updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 +- Updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). - The SEI thickness decreased at some intervals when the 'electron-migration limited' model was used. It has been corrected ([#3622](https://github.com/pybamm-team/PyBaMM/pull/3622)) From c13f153f74004bc28d056f501844a34417505137 Mon Sep 17 00:00:00 2001 From: "Eric G. Kratz" Date: Wed, 24 Jan 2024 09:37:11 -0500 Subject: [PATCH 8/8] Update CHANGELOG.md Co-authored-by: Arjun --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dbb58ddd3f..7d36a0c4bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,7 @@ ## Bug Fixes -- Updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 +- Updated `_steps_util.py` to throw a specific exception when drive cycle starts at t>0 ([#3756](https://github.com/pybamm-team/PyBaMM/pull/3756)) - Updated `plot_voltage_components.py` to support both `Simulation` and `Solution` objects. Added new methods in both `Simulation` and `Solution` classes for allow the syntax `simulation.plot_voltage_components` and `solution.plot_voltage_components`. Updated `test_plot_voltage_components.py` to reflect these changes ([#3723](https://github.com/pybamm-team/PyBaMM/pull/3723)). - The SEI thickness decreased at some intervals when the 'electron-migration limited' model was used. It has been corrected ([#3622](https://github.com/pybamm-team/PyBaMM/pull/3622))