diff --git a/examples/notebooks/battery_parameterisation/ecm_multipulse_identification.ipynb b/examples/notebooks/battery_parameterisation/ecm_multipulse_identification.ipynb index 51c852358..65f4623b6 100644 --- a/examples/notebooks/battery_parameterisation/ecm_multipulse_identification.ipynb +++ b/examples/notebooks/battery_parameterisation/ecm_multipulse_identification.ipynb @@ -304,6 +304,7 @@ " parameter_values=parameter_values,\n", " protocol=dataset,\n", " solver=pybamm.CasadiSolver(mode=\"safe\", dt_max=40),\n", + " cache_esoh=False,\n", ")\n", "cost = pybop.SumSquaredError(dataset)\n", "problem = pybop.Problem(simulator, cost)" @@ -539,7 +540,7 @@ "source": [ "parameter_values.update(result.best_inputs)\n", "sol = pybamm.Simulation(\n", - " model, parameter_values=parameter_values, experiment=experiment\n", + " model, parameter_values=parameter_values, experiment=experiment, cache_esoh=False\n", ").solve(initial_soc=0.95)\n", "# sol.plot();" ] diff --git a/examples/notebooks/battery_parameterisation/lgm50_pulse_validation.ipynb b/examples/notebooks/battery_parameterisation/lgm50_pulse_validation.ipynb index ae8a0d3ba..7cd0c65b0 100644 --- a/examples/notebooks/battery_parameterisation/lgm50_pulse_validation.ipynb +++ b/examples/notebooks/battery_parameterisation/lgm50_pulse_validation.ipynb @@ -315,7 +315,7 @@ "outputs": [], "source": [ "simulator = pybop.pybamm.Simulator(\n", - " model, parameter_values=parameter_values, protocol=dataset\n", + " model, parameter_values=parameter_values, protocol=dataset, cache_esoh=False\n", ")\n", "cost = pybop.SumSquaredError(dataset)\n", "problem = pybop.Problem(simulator, cost)" @@ -571,6 +571,7 @@ " parameter_values=parameter_values,\n", " protocol=dataset_two_pulse,\n", " initial_state={\"Initial SoC\": 0.8 - 0.0075},\n", + " cache_esoh=False,\n", ")\n", "cost_two_pulse = pybop.SumSquaredError(dataset_two_pulse)\n", "problem = pybop.Problem(simulator, cost_two_pulse)" diff --git a/examples/scripts/battery_parameterisation/thermal_model.py b/examples/scripts/battery_parameterisation/thermal_model.py index 11a05a7c2..8c8433aa5 100644 --- a/examples/scripts/battery_parameterisation/thermal_model.py +++ b/examples/scripts/battery_parameterisation/thermal_model.py @@ -22,7 +22,7 @@ parameter_values = pybamm.ParameterValues("Chen2020") model = pybamm.lithium_ion.SPM() solution = pybamm.Simulation( - model, parameter_values=parameter_values, experiment=experiment + model, parameter_values=parameter_values, experiment=experiment, cache_esoh=False ).solve(initial_soc=init_soc) # Add thermal parameters and the voltage data @@ -61,6 +61,6 @@ # Run an example thermal simulation thermal_model = pybop.lithium_ion.CellTemperature() solution = pybamm.Simulation( - thermal_model, parameter_values=grouped_parameter_values + thermal_model, parameter_values=grouped_parameter_values, cache_esoh=False ).solve(initial_soc=init_soc, t_eval=solution.t) solution.plot(["Current [A]", "SoC", "Voltage [V]", "Cell temperature [K]"]) diff --git a/examples/scripts/comparison_examples/grouped_SPMe.py b/examples/scripts/comparison_examples/grouped_SPMe.py index 012104f32..de4c897ab 100644 --- a/examples/scripts/comparison_examples/grouped_SPMe.py +++ b/examples/scripts/comparison_examples/grouped_SPMe.py @@ -53,7 +53,7 @@ strict=False, ): solution = pybamm.Simulation( - model, parameter_values=param, experiment=experiment + model, parameter_values=param, experiment=experiment, cache_esoh=False ).solve(initial_soc=init_soc) dataset = pybop.import_pybamm_solution(solution) plot_dict.add_traces( diff --git a/pybop/pybamm/eis_simulator.py b/pybop/pybamm/eis_simulator.py index 2963abffd..d5dc05dfa 100644 --- a/pybop/pybamm/eis_simulator.py +++ b/pybop/pybamm/eis_simulator.py @@ -55,6 +55,9 @@ class EISSimulator(BaseSimulator): discretisation_kwargs : dict, optional Any keyword arguments to pass to the Discretisation class. See :class:`pybamm.Discretisation` for details. + cache_esoh : bool, optional + If True, the electrode SOH computation is cached for repeated calls to `pybamm.Simulation.solve` + (default: True). build_every_time : bool, optional If True, the model will be rebuilt every evaluation. Otherwise, the need to rebuild will be determined automatically. @@ -72,6 +75,7 @@ def __init__( var_pts: dict | None = None, spatial_methods: dict | None = None, discretisation_kwargs: dict | None = None, + cache_esoh: bool = True, build_every_time: bool = False, ): # Set-up model for EIS @@ -93,6 +97,7 @@ def __init__( var_pts=var_pts, spatial_methods=spatial_methods, discretisation_kwargs=discretisation_kwargs, + cache_esoh=cache_esoh, build_every_time=build_every_time, ) self.debug_mode = False diff --git a/pybop/pybamm/simulator.py b/pybop/pybamm/simulator.py index e1e4dc8dc..109382ccc 100644 --- a/pybop/pybamm/simulator.py +++ b/pybop/pybamm/simulator.py @@ -53,6 +53,9 @@ class Simulator(BaseSimulator): discretisation_kwargs : dict, optional Any keyword arguments to pass to the Discretisation class. See :class:`pybamm.Discretisation` for details. + cache_esoh : bool, optional + If True, the electrode SOH computation is cached for repeated calls to `pybamm.Simulation.solve` + (default: True). build_every_time : bool, optional If True, the model will be rebuilt every evaluation. Otherwise, the need to rebuild will be determined automatically. @@ -71,6 +74,7 @@ def __init__( var_pts: dict | None = None, spatial_methods: dict | None = None, discretisation_kwargs: dict | None = None, + cache_esoh: bool = True, build_every_time: bool = False, ): # Core @@ -114,6 +118,7 @@ def __init__( self._var_pts = var_pts or model.default_var_pts self._spatial_methods = spatial_methods or model.default_spatial_methods self._discretisation_kwargs = discretisation_kwargs or {"check_model": True} + self._cache_esoh = cache_esoh # State self._simulation = None @@ -388,6 +393,7 @@ def create_simulation(self) -> pybamm.Simulation: var_pts=self._var_pts, spatial_methods=self._spatial_methods, discretisation_kwargs=self._discretisation_kwargs, + cache_esoh=self._cache_esoh, ) def _simulate_without_rebuild( diff --git a/pyproject.toml b/pyproject.toml index 29ab831e3..15145f92f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ classifiers = [ # versions in the tests in nightly_dependency_tests.yml as appropriate requires-python = ">=3.10, <3.14" dependencies = [ - "pybamm>=25.12.0", + "pybamm @ git+https://github.com/pybamm-team/PyBaMM@main", # update after next PyBaMM release "numpy>=1.26", "scipy>=1.12", "pints>=0.6.0",