I am simulating a Thevenin equivalent circuit model using pybamm.Experiment. I want to update some model parameters periodically during the simulation—for example, every 100 simulated seconds.
The intended workflow is:
-
Run the experiment until a specified simulated time.
-
Extract and preserve the model state and solution at that time.
-
Update parameters such as the resistances or capacitances.
-
Continue the experiment from exactly the same point, including when the interruption occurs partway through an experiment step.
-
Repeat this process until the complete experiment has been simulated.
Conceptually, I would like to implement something similar to:
current_solution = None
for stop_time in update_times:
solution = solve_experiment_until(
stop_time=stop_time,
starting_solution=current_solution,
parameter_values=params,
)
current_solution = solution.last_state
params.update(calculate_new_parameters(solution))
However, t_eval is ignored when pybamm.Experiment is used because the experiment controls the simulation times. An experiment-level time termination can stop the simulation at a specified time, but I am unsure how to resume the remaining experiment afterward. In particular, creating a new simulation with the same experiment and passing starting_solution appears likely to restart the experimental protocol from its first step rather than continue from the interrupted step.
Is there a supported PyBaMM approach for periodically pausing and resuming an experiment while updating model parameters? How can the current cycle, step, elapsed step time, and internal model state be preserved?