Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 the max_wall_time parameter to BaseSolver (and child classes) for optional wall-clock timeout handling during solver steps, raising SolverError on exceedance while preserving partial solutions. ([#5240](https://github.com/pybamm-team/PyBaMM/pull/5240))
- Added the `electrode_phases` kwarg to `plot_voltage_components()` which allows choosing between plotting primary or secondary phase overpotentials. ([#5229](https://github.com/pybamm-team/PyBaMM/pull/5229))
- Added the `num_steps_no_progress` and `t_no_progress` options in the `IDAKLUSolver` to early terminate the simulation if little progress is detected. ([#5201](https://github.com/pybamm-team/PyBaMM/pull/5201))
- EvaluateAt symbol: add support for children evaluated at edges ([#5190](https://github.com/pybamm-team/PyBaMM/pull/5190))
Expand Down
23 changes: 23 additions & 0 deletions src/pybamm/simulation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import pickle
import time
import warnings
from copy import copy
from datetime import timedelta
Expand Down Expand Up @@ -380,6 +381,7 @@ def solve(
inputs=None,
t_interp=None,
initial_conditions=None,
max_wall_time=None,
**kwargs,
):
"""
Expand Down Expand Up @@ -425,16 +427,28 @@ def solve(
Initial State of Charge (SOC) for the simulation. Must be between 0 and 1.
If given, overwrites the initial concentrations provided in the parameter
set.
direction : str, optional
Direction of the solve ("forward" or "backward"). Defaults to "forward".
callbacks : list of callbacks, optional
A list of callbacks to be called at each time step. Each callback must
implement all the methods defined in :class:`pybamm.callbacks.BaseCallback`.
showprogress : bool, optional
Whether to show a progress bar for cycling. If true, shows a progress bar
for cycles. Has no effect when not used with an experiment.
Default is False.
inputs : dict, optional
Dictionary of input values to override model defaults. If None, uses built-in
values from the parameter set.
t_interp : None, list or ndarray, optional
The times (in seconds) at which to interpolate the solution. Defaults to None.
Only valid for solvers that support intra-solve interpolation (`IDAKLUSolver`).
initial_conditions : dict, optional
Dictionary of initial conditions for the variables. If None, the initial
conditions are inferred from the model.
max_wall_time : float, optional
Maximum wall-clock time (in seconds) for the entire solve process. If
exceeded during solver steps, raises a :class:`pybamm.SolverError` while
preserving partial solution data. Defaults to None (no limit).
**kwargs
Additional key-word arguments passed to `solver.solve`.
See :meth:`pybamm.BaseSolver.solve`.
Expand All @@ -448,6 +462,12 @@ def solve(
if solver is None:
solver = self._solver

if max_wall_time is not None:
solver.max_wall_time = max_wall_time

if solver.max_wall_time is not None and solver._wall_time_start is None:
solver._wall_time_start = time.time()

if calc_esoh is None:
calc_esoh = self._model.calc_esoh
else:
Expand Down Expand Up @@ -764,6 +784,9 @@ def solve(
**kwargs,
)
except pybamm.SolverError as error:
if "Wall time limit" in str(error):
raise

if (
"non-positive at initial conditions" in error.message
and "[experiment]" in error.message
Expand Down
Loading