From 89cc4b551f99b3319ecfd5e31ccf1cc864b83e9a Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 27 Feb 2024 15:27:22 -0500 Subject: [PATCH 1/3] fix some minor annoyances --- .../full_battery_models/lithium_ion/electrode_soh.py | 2 +- .../lithium_ion/electrode_soh_half_cell.py | 2 +- pybamm/plotting/plot.py | 11 ++++++----- pybamm/plotting/plot2D.py | 11 ++++++----- pybamm/plotting/plot_summary_variables.py | 9 +++++---- pybamm/plotting/plot_voltage_components.py | 7 ++++--- pybamm/plotting/quick_plot.py | 10 +++++----- pybamm/simulation.py | 9 +++++---- pybamm/solvers/solution.py | 9 +++++---- tests/unit/test_batch_study.py | 7 ++++--- tests/unit/test_plotting/test_plot.py | 10 +++++----- .../test_plotting/test_plot_summary_variables.py | 4 ++-- .../test_plotting/test_plot_voltage_components.py | 12 ++++++++---- tests/unit/test_plotting/test_quick_plot.py | 10 +++++----- tests/unit/test_serialisation/test_serialisation.py | 4 ++-- tests/unit/test_simulation.py | 4 ++-- tests/unit/test_solvers/test_solution.py | 2 +- 17 files changed, 67 insertions(+), 56 deletions(-) diff --git a/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py b/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py index c43ba05b1f..9c4406f145 100644 --- a/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py +++ b/pybamm/models/full_battery_models/lithium_ion/electrode_soh.py @@ -667,7 +667,7 @@ def get_initial_stoichiometries(self, initial_value, tol=1e-6): V_min = parameter_values.evaluate(param.ocp_soc_0_dimensional) V_max = parameter_values.evaluate(param.ocp_soc_100_dimensional) - if not V_min < V_init < V_max: + if not V_min <= V_init <= V_max: raise ValueError( f"Initial voltage {V_init}V is outside the voltage limits " f"({V_min}, {V_max})" diff --git a/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py b/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py index 8c22cf2ada..4fc8c904b6 100644 --- a/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py +++ b/pybamm/models/full_battery_models/lithium_ion/electrode_soh_half_cell.py @@ -93,7 +93,7 @@ def get_initial_stoichiometry_half_cell( V_min = parameter_values.evaluate(param.voltage_low_cut) V_max = parameter_values.evaluate(param.voltage_high_cut) - if not V_min < V_init < V_max: + if not V_min <= V_init <= V_max: raise ValueError( f"Initial voltage {V_init}V is outside the voltage limits " f"({V_min}, {V_max})" diff --git a/pybamm/plotting/plot.py b/pybamm/plotting/plot.py index 88c8dfe442..cf5c972a87 100644 --- a/pybamm/plotting/plot.py +++ b/pybamm/plotting/plot.py @@ -6,7 +6,7 @@ from pybamm.util import have_optional_dependency -def plot(x, y, ax=None, testing=False, **kwargs): +def plot(x, y, ax=None, show_plot=True, **kwargs): """ Generate a simple 1D plot. Calls `matplotlib.pyplot.plot` with keyword arguments 'kwargs'. For a list of 'kwargs' see the @@ -20,8 +20,9 @@ def plot(x, y, ax=None, testing=False, **kwargs): The array to plot on the y axis ax : matplotlib Axis, optional The axis on which to put the plot. If None, a new figure and axis is created. - testing : bool, optional - Whether to actually make the plot (turned off for unit tests) + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. kwargs Keyword arguments, passed to plt.plot @@ -34,14 +35,14 @@ def plot(x, y, ax=None, testing=False, **kwargs): raise TypeError("y must be 'pybamm.Array'") if ax is not None: - testing = True + show_plot = False else: _, ax = plt.subplots() ax.plot(x.entries, y.entries, **kwargs) ax.set_ylim([ax_min(y.entries), ax_max(y.entries)]) - if not testing: # pragma: no cover + if show_plot: # pragma: no cover plt.show() return ax diff --git a/pybamm/plotting/plot2D.py b/pybamm/plotting/plot2D.py index 3a69bab803..a37cd1e2ed 100644 --- a/pybamm/plotting/plot2D.py +++ b/pybamm/plotting/plot2D.py @@ -6,7 +6,7 @@ from pybamm.util import have_optional_dependency -def plot2D(x, y, z, ax=None, testing=False, **kwargs): +def plot2D(x, y, z, ax=None, show_plot=True, **kwargs): """ Generate a simple 2D plot. Calls `matplotlib.pyplot.contourf` with keyword arguments 'kwargs'. For a list of 'kwargs' see the @@ -22,8 +22,9 @@ def plot2D(x, y, z, ax=None, testing=False, **kwargs): The array to plot on the z axis. Is of shape (M, N) ax : matplotlib Axis, optional The axis on which to put the plot. If None, a new figure and axis is created. - testing : bool, optional - Whether to actually make the plot (turned off for unit tests) + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. """ plt = have_optional_dependency("matplotlib.pyplot") @@ -36,7 +37,7 @@ def plot2D(x, y, z, ax=None, testing=False, **kwargs): raise TypeError("z must be 'pybamm.Array'") if ax is not None: - testing = True + show_plot = False else: _, ax = plt.subplots() @@ -58,7 +59,7 @@ def plot2D(x, y, z, ax=None, testing=False, **kwargs): ) plt.colorbar(plot, ax=ax) - if not testing: # pragma: no cover + if show_plot: # pragma: no cover plt.show() return ax diff --git a/pybamm/plotting/plot_summary_variables.py b/pybamm/plotting/plot_summary_variables.py index e50f38fddf..33642c4d5a 100644 --- a/pybamm/plotting/plot_summary_variables.py +++ b/pybamm/plotting/plot_summary_variables.py @@ -7,7 +7,7 @@ def plot_summary_variables( - solutions, output_variables=None, labels=None, testing=False, **kwargs_fig + solutions, output_variables=None, labels=None, show_plot=True, **kwargs_fig ): """ Generate a plot showing/comparing the summary variables. @@ -20,8 +20,9 @@ def plot_summary_variables( A list of variables to plot automatically. If None, the default ones are used. labels: list (optional) A list of labels to be added to the legend. No labels are added by default. - testing : bool (optional) - Whether to actually make the plot (turned off for unit tests). + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. kwargs_fig Keyword arguments, passed to plt.subplots. @@ -74,7 +75,7 @@ def plot_summary_variables( # add labels in legend if labels is not None: # pragma: no cover fig.legend(labels, loc="lower right") - if not testing: # pragma: no cover + if show_plot: # pragma: no cover plt.show() return axes diff --git a/pybamm/plotting/plot_voltage_components.py b/pybamm/plotting/plot_voltage_components.py index a24da57932..dd011efaf0 100644 --- a/pybamm/plotting/plot_voltage_components.py +++ b/pybamm/plotting/plot_voltage_components.py @@ -13,7 +13,7 @@ def plot_voltage_components( ax=None, show_legend=True, split_by_electrode=False, - testing=False, + show_plot=True, **kwargs_fill, ): """ @@ -30,8 +30,9 @@ def plot_voltage_components( split_by_electrode : bool, optional Whether to show the overpotentials for the negative and positive electrodes separately. Default is False. - testing : bool, optional - Whether to actually make the plot (turned off for unit tests) + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. kwargs_fill Keyword arguments, passed to ax.fill_between diff --git a/pybamm/plotting/quick_plot.py b/pybamm/plotting/quick_plot.py index 9b082fd6d4..c6d3054abb 100644 --- a/pybamm/plotting/quick_plot.py +++ b/pybamm/plotting/quick_plot.py @@ -9,7 +9,6 @@ class LoopList(list): - """A list which loops over itself when accessing an index so that it never runs out""" @@ -649,7 +648,7 @@ def plot(self, t, dynamic=False): bottom = max(legend_top, slider_top) self.gridspec.tight_layout(self.fig, rect=[0, bottom, 1, 1]) - def dynamic_plot(self, testing=False, step=None): + def dynamic_plot(self, show_plot=True, step=None): """ Generate a dynamic plot with a slider to control the time. @@ -658,8 +657,9 @@ def dynamic_plot(self, testing=False, step=None): step : float For notebook mode, size of steps to allow in the slider. Defaults to 1/100th of the total time. - testing : bool - Whether to actually make the plot (turned off for unit tests) + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. """ if pybamm.is_notebook(): # pragma: no cover @@ -692,7 +692,7 @@ def dynamic_plot(self, testing=False, step=None): ) self.slider.on_changed(self.slider_update) - if not testing: # pragma: no cover + if show_plot: # pragma: no cover plt.show() def slider_update(self, t): diff --git a/pybamm/simulation.py b/pybamm/simulation.py index 5d31340a05..c1d62a47e9 100644 --- a/pybamm/simulation.py +++ b/pybamm/simulation.py @@ -1215,7 +1215,7 @@ def plot_voltage_components( ax=None, show_legend=True, split_by_electrode=False, - testing=False, + show_plot=True, **kwargs_fill, ): """ @@ -1230,8 +1230,9 @@ def plot_voltage_components( split_by_electrode : bool, optional Whether to show the overpotentials for the negative and positive electrodes separately. Default is False. - testing : bool, optional - Whether to actually make the plot (turned off for unit tests). + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. kwargs_fill Keyword arguments, passed to ax.fill_between. @@ -1244,7 +1245,7 @@ def plot_voltage_components( ax=ax, show_legend=show_legend, split_by_electrode=split_by_electrode, - testing=testing, + show_plot=show_plot, **kwargs_fill, ) diff --git a/pybamm/solvers/solution.py b/pybamm/solvers/solution.py index 3fe4915dfb..a3b3e9e6ef 100644 --- a/pybamm/solvers/solution.py +++ b/pybamm/solvers/solution.py @@ -814,7 +814,7 @@ def plot_voltage_components( ax=None, show_legend=True, split_by_electrode=False, - testing=False, + show_plot=True, **kwargs_fill, ): """ @@ -829,8 +829,9 @@ def plot_voltage_components( split_by_electrode : bool, optional Whether to show the overpotentials for the negative and positive electrodes separately. Default is False. - testing : bool, optional - Whether to actually make the plot (turned off for unit tests). + show_plot : bool, optional + Whether to show the plots. Default is True. Set to False if you want to + only display the plot after plt.show() has been called. kwargs_fill Keyword arguments, passed to ax.fill_between. @@ -841,7 +842,7 @@ def plot_voltage_components( ax=ax, show_legend=show_legend, split_by_electrode=split_by_electrode, - testing=testing, + show_plot=show_plot, **kwargs_fill, ) diff --git a/tests/unit/test_batch_study.py b/tests/unit/test_batch_study.py index 1d48bd08b0..3471914417 100644 --- a/tests/unit/test_batch_study.py +++ b/tests/unit/test_batch_study.py @@ -1,6 +1,7 @@ """ Tests for the batch_study.py """ + from tests import TestCase import os import pybamm @@ -52,7 +53,7 @@ def test_solve(self): # Tests for BatchStudy when permutations=False bs_false.solve() - bs_false.plot(testing=True) + bs_false.plot(show_plot=False) self.assertEqual(2, len(bs_false.sims)) for num in range(len(bs_false.sims)): output_model = bs_false.sims[num].model.name @@ -72,7 +73,7 @@ def test_solve(self): # Tests for BatchStudy when permutations=True bs_true.solve() - bs_true.plot(testing=True) + bs_true.plot(show_plot=False) self.assertEqual(4, len(bs_true.sims)) for num in range(len(bs_true.sims)): output_model = bs_true.sims[num].model.name @@ -108,7 +109,7 @@ def test_create_gif(self): bs.create_gif(number_of_images=3, duration=1, output_filename=test_file) # create a GIF after calling the plot method - bs.plot(testing=True) + bs.plot(show_plot=False) bs.create_gif(number_of_images=3, duration=1, output_filename=test_file) diff --git a/tests/unit/test_plotting/test_plot.py b/tests/unit/test_plotting/test_plot.py index aaa75f957c..2b5bb9cb17 100644 --- a/tests/unit/test_plotting/test_plot.py +++ b/tests/unit/test_plotting/test_plot.py @@ -9,10 +9,10 @@ class TestPlot(TestCase): def test_plot(self): x = pybamm.Array(np.array([0, 3, 10])) y = pybamm.Array(np.array([6, 16, 78])) - pybamm.plot(x, y, testing=True) + pybamm.plot(x, y, show_plot=False) _, ax = plt.subplots() - ax_out = pybamm.plot(x, y, ax=ax, testing=True) + ax_out = pybamm.plot(x, y, ax=ax, show_plot=False) self.assertEqual(ax_out, ax) def test_plot_fail(self): @@ -28,13 +28,13 @@ def test_plot2D(self): X, Y = pybamm.meshgrid(x, y) # plot with array directly - pybamm.plot2D(x, y, Y, testing=True) + pybamm.plot2D(x, y, Y, show_plot=False) # plot with meshgrid - pybamm.plot2D(X, Y, Y, testing=True) + pybamm.plot2D(X, Y, Y, show_plot=False) _, ax = plt.subplots() - ax_out = pybamm.plot2D(X, Y, Y, ax=ax, testing=True) + ax_out = pybamm.plot2D(X, Y, Y, ax=ax, show_plot=False) self.assertEqual(ax_out, ax) def test_plot2D_fail(self): diff --git a/tests/unit/test_plotting/test_plot_summary_variables.py b/tests/unit/test_plotting/test_plot_summary_variables.py index 69e32eb023..e896b1f468 100644 --- a/tests/unit/test_plotting/test_plot_summary_variables.py +++ b/tests/unit/test_plotting/test_plot_summary_variables.py @@ -36,7 +36,7 @@ def test_plot(self): ) sol = sim.solve(initial_soc=1) - axes = pybamm.plot_summary_variables(sol, testing=True) + axes = pybamm.plot_summary_variables(sol, show_plot=False) axes = axes.flatten() self.assertEqual(len(axes), 9) @@ -52,7 +52,7 @@ def test_plot(self): np.testing.assert_array_equal(var, sol.summary_variables[output_var]) axes = pybamm.plot_summary_variables( - [sol, sol], labels=["SPM", "SPM"], testing=True + [sol, sol], labels=["SPM", "SPM"], show_plot=False ) axes = axes.flatten() diff --git a/tests/unit/test_plotting/test_plot_voltage_components.py b/tests/unit/test_plotting/test_plot_voltage_components.py index eb0a84fe3a..928a15655d 100644 --- a/tests/unit/test_plotting/test_plot_voltage_components.py +++ b/tests/unit/test_plotting/test_plot_voltage_components.py @@ -12,7 +12,7 @@ def test_plot_with_solution(self): sol = sim.solve([0, 3600]) for split in [True, False]: _, ax = pybamm.plot_voltage_components( - sol, testing=True, split_by_electrode=split + sol, show_plot=False, split_by_electrode=split ) t, V = ax.get_lines()[0].get_data() np.testing.assert_array_equal(t, sol["Time [h]"].data) @@ -29,7 +29,7 @@ def test_plot_with_simulation(self): for split in [True, False]: _, ax = pybamm.plot_voltage_components( - sim, testing=True, split_by_electrode=split + sim, show_plot=False, split_by_electrode=split ) t, V = ax.get_lines()[0].get_data() np.testing.assert_array_equal(t, sim.solution["Time [h]"].data) @@ -44,7 +44,9 @@ def test_plot_from_solution(self): sim = pybamm.Simulation(model) sol = sim.solve([0, 3600]) for split in [True, False]: - _, ax = sol.plot_voltage_components(testing=True, split_by_electrode=split) + _, ax = sol.plot_voltage_components( + show_plot=False, split_by_electrode=split + ) t, V = ax.get_lines()[0].get_data() np.testing.assert_array_equal(t, sol["Time [h]"].data) np.testing.assert_array_equal(V, sol["Battery voltage [V]"].data) @@ -59,7 +61,9 @@ def test_plot_from_simulation(self): sim.solve([0, 3600]) for split in [True, False]: - _, ax = sim.plot_voltage_components(testing=True, split_by_electrode=split) + _, ax = sim.plot_voltage_components( + show_plot=False, split_by_electrode=split + ) t, V = ax.get_lines()[0].get_data() np.testing.assert_array_equal(t, sim.solution["Time [h]"].data) np.testing.assert_array_equal(V, sim.solution["Battery voltage [V]"].data) diff --git a/tests/unit/test_plotting/test_quick_plot.py b/tests/unit/test_plotting/test_quick_plot.py index 7e2a088de6..7b3511ed63 100644 --- a/tests/unit/test_plotting/test_quick_plot.py +++ b/tests/unit/test_plotting/test_quick_plot.py @@ -84,7 +84,7 @@ def test_simple_ode_model(self): self.assertNotEqual(quick_plot.axis_limits[("a",)], new_axis) # check dynamic plot loads - quick_plot.dynamic_plot(testing=True) + quick_plot.dynamic_plot(show_plot=False) quick_plot.slider_update(0.01) @@ -117,7 +117,7 @@ def test_simple_ode_model(self): self.assertNotEqual(quick_plot.axis_limits[var_key], new_axis) # check dynamic plot loads - quick_plot.dynamic_plot(testing=True) + quick_plot.dynamic_plot(show_plot=False) quick_plot.slider_update(0.01) @@ -194,7 +194,7 @@ def test_simple_ode_model(self): # Test 2D variables quick_plot = pybamm.QuickPlot(solution, ["2D variable"]) quick_plot.plot(0) - quick_plot.dynamic_plot(testing=True) + quick_plot.dynamic_plot(show_plot=False) quick_plot.slider_update(0.01) with self.assertRaisesRegex(NotImplementedError, "Cannot plot 2D variables"): @@ -440,7 +440,7 @@ def test_plot_2plus1D_spm(self): "Voltage [V]", ], ) - quick_plot.dynamic_plot(testing=True) + quick_plot.dynamic_plot(show_plot=False) quick_plot.slider_update(1) # check 2D (y,z space) variables update properly for different time units @@ -504,7 +504,7 @@ def test_model_with_inputs(self): quick_plot = pybamm.QuickPlot( solutions=[sol1, sol2], output_variables=output_variables ) - quick_plot.dynamic_plot(testing=True) + quick_plot.dynamic_plot(show_plot=False) quick_plot.slider_update(1) pybamm.close_plots() diff --git a/tests/unit/test_serialisation/test_serialisation.py b/tests/unit/test_serialisation/test_serialisation.py index 75ea33fe66..c0c1bd22cb 100644 --- a/tests/unit/test_serialisation/test_serialisation.py +++ b/tests/unit/test_serialisation/test_serialisation.py @@ -564,7 +564,7 @@ def test_serialised_model_plotting(self): new_solution = pybamm.ScipySolver().solve(new_model, np.linspace(0, 1)) # check dynamic plot loads - new_solution.plot(["c", "2c"], testing=True) + new_solution.plot(["c", "2c"], show_plot=False) # models with a mesh ---------------- model = pybamm.lithium_ion.SPM(name="test_spm_plotting") @@ -590,7 +590,7 @@ def test_serialised_model_plotting(self): new_solution = new_solver.solve(new_model, [0, 3600]) # check dynamic plot loads - new_solution.plot(testing=True) + new_solution.plot(show_plot=False) if __name__ == "__main__": diff --git a/tests/unit/test_simulation.py b/tests/unit/test_simulation.py index 6e7896bbbe..734f22eb35 100644 --- a/tests/unit/test_simulation.py +++ b/tests/unit/test_simulation.py @@ -391,7 +391,7 @@ def test_plot(self): # now solve and plot t_eval = np.linspace(0, 100, 5) sim.solve(t_eval=t_eval) - sim.plot(testing=True) + sim.plot(show_plot=False) def test_create_gif(self): with TemporaryDirectory() as dir_name: @@ -409,7 +409,7 @@ def test_create_gif(self): sim.create_gif(number_of_images=3, duration=1, output_filename=test_file) # call the plot method before creating the GIF - sim.plot(testing=True) + sim.plot(show_plot=False) sim.create_gif(number_of_images=3, duration=1, output_filename=test_file) def test_drive_cycle_interpolant(self): diff --git a/tests/unit/test_solvers/test_solution.py b/tests/unit/test_solvers/test_solution.py index c7dfb716de..ecc8d1bd8e 100644 --- a/tests/unit/test_solvers/test_solution.py +++ b/tests/unit/test_solvers/test_solution.py @@ -232,7 +232,7 @@ def test_plot(self): solution = pybamm.ScipySolver().solve(model, np.linspace(0, 1)) - solution.plot(["c", "2c"], testing=True) + solution.plot(["c", "2c"], show_plot=False) def test_save(self): with TemporaryDirectory() as dir_name: From 6ccf362cb17bd9a10350bcad88f2625f366ffae5 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 27 Feb 2024 15:30:29 -0500 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11c32a0b49..6cade77684 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ## Bug Fixes +- Initial voltage can now match upper or lower cut-offs exactly ([#3842](https://github.com/pybamm-team/PyBaMM/pull/3842)) - Fixed a bug where 1+1D and 2+1D models would not work with voltage or power controlled experiments([#3829](https://github.com/pybamm-team/PyBaMM/pull/3829)) - Update IDAKLU solver to fail gracefully when a variable is requested that was not in the solves `output_variables` list ([#3803](https://github.com/pybamm-team/PyBaMM/pull/3803)) - 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)) @@ -17,6 +18,7 @@ ## Breaking changes +- Renamed "testing" argument for plots to "show_plot" and flipped its meaning (show_plot=True is now the default and shows the plot) ([#3842](https://github.com/pybamm-team/PyBaMM/pull/3842)) - Dropped support for BPX version 0.3.0 and below ([#3414](https://github.com/pybamm-team/PyBaMM/pull/3414)) # [v24.1](https://github.com/pybamm-team/PyBaMM/tree/v24.1) - 2024-01-31 @@ -35,12 +37,11 @@ - Added a `get_parameter_info` method for models and modified "print_parameter_info" functionality to extract all parameters and their type in a tabular and readable format ([#3584](https://github.com/pybamm-team/PyBaMM/pull/3584)) - Mechanical parameters are now a function of stoichiometry and temperature ([#3576](https://github.com/pybamm-team/PyBaMM/pull/3576)) - ## Bug fixes - Fixed a bug that lead to a `ShapeError` when specifying "Ambient temperature [K]" as an `Interpolant` with an isothermal model ([#3761](https://github.com/pybamm-team/PyBaMM/pull/3761)) - Fixed a bug where if the first step(s) in a cycle are skipped then the cycle solution started from the model's initial conditions instead of from the last state of the previous cycle ([#3708](https://github.com/pybamm-team/PyBaMM/pull/3708)) -- Fixed a bug where the lumped thermal model conflates cell volume with electrode volume ([#3707](https://github.com/pybamm-team/PyBaMM/pull/3707)) +- Fixed a bug where the lumped thermal model conflates cell volume with electrode volume ([#3707](https://github.com/pybamm-team/PyBaMM/pull/3707)) - Reverted a change to the coupled degradation example notebook that caused it to be unstable for large numbers of cycles ([#3691](https://github.com/pybamm-team/PyBaMM/pull/3691)) - Fixed a bug where simulations using the CasADi-based solvers would fail randomly with the half-cell model ([#3494](https://github.com/pybamm-team/PyBaMM/pull/3494)) - Fixed bug that made identical Experiment steps with different end times crash ([#3516](https://github.com/pybamm-team/PyBaMM/pull/3516)) From d28e9370a13714270cb938243579bf4234905500 Mon Sep 17 00:00:00 2001 From: Valentin Sulzer Date: Tue, 27 Feb 2024 15:51:31 -0500 Subject: [PATCH 3/3] fix unit tests --- pybamm/plotting/dynamic_plot.py | 6 +++--- pybamm/plotting/plot_voltage_components.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pybamm/plotting/dynamic_plot.py b/pybamm/plotting/dynamic_plot.py index eb4d468be9..4cde0d3972 100644 --- a/pybamm/plotting/dynamic_plot.py +++ b/pybamm/plotting/dynamic_plot.py @@ -8,7 +8,7 @@ def dynamic_plot(*args, **kwargs): """ Creates a :class:`pybamm.QuickPlot` object (with arguments 'args' and keyword arguments 'kwargs') and then calls :meth:`pybamm.QuickPlot.dynamic_plot`. - The key-word argument 'testing' is passed to the 'dynamic_plot' method, not the + The key-word argument 'show_plot' is passed to the 'dynamic_plot' method, not the `QuickPlot` class. Returns @@ -16,7 +16,7 @@ def dynamic_plot(*args, **kwargs): plot : :class:`pybamm.QuickPlot` The 'QuickPlot' object that was created """ - kwargs_for_class = {k: v for k, v in kwargs.items() if k != "testing"} + kwargs_for_class = {k: v for k, v in kwargs.items() if k != "show_plot"} plot = pybamm.QuickPlot(*args, **kwargs_for_class) - plot.dynamic_plot(kwargs.get("testing", False)) + plot.dynamic_plot(kwargs.get("show_plot", True)) return plot diff --git a/pybamm/plotting/plot_voltage_components.py b/pybamm/plotting/plot_voltage_components.py index dd011efaf0..3b155b71de 100644 --- a/pybamm/plotting/plot_voltage_components.py +++ b/pybamm/plotting/plot_voltage_components.py @@ -49,7 +49,7 @@ def plot_voltage_components( if ax is not None: fig = None - testing = True + show_plot = False else: fig, ax = plt.subplots(figsize=(8, 4)) @@ -152,7 +152,7 @@ def plot_voltage_components( ) ax.set_ylim([y_min, y_max]) - if not testing: # pragma: no cover + if show_plot: # pragma: no cover plt.show() return fig, ax