How can I pause a PyBaMM experiment at fixed simulated-time intervals, update ECM parameters, and resume from the same point in the experiment?

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:

  1. Run the experiment until a specified simulated time.

  2. Extract and preserve the model state and solution at that time.

  3. Update parameters such as the resistances or capacitances.

  4. Continue the experiment from exactly the same point, including when the interruption occurs partway through an experiment step.

  5. 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?

Hi Ivan. I’m not aware of any functionality for periodically pausing and resuming an experiment, but you might be able to do something similar by defining your parameter as a series of heavyside functions defining the timepoints and values that you want to change at (or perhaps even as an interpolant). If you use a series of heavysides, then PyBaMM will detect these discontinuties and insert stop events for the solver automatically.