Callbacks#
- class pybamm.callbacks.Callback[source]#
Base class for callbacks, for documenting callback methods.
Callbacks are used to perform actions (e.g. logging, saving) at certain points in the simulation. Each callback method is named on_<event>, where <event> describes the point at which the callback is called. For example, the callback on_experiment_start is called at the start of an experiment simulation. In general, callbacks take a single argument, logs, which is a dictionary of information about the simulation. Each callback method should return None (the output of the method is ignored).
EXPERIMENTAL - this class is experimental and the callback interface may change in future releases.
- on_experiment_error(logs)[source]#
Called when a SolverError occurs during an experiment simulation.
For example, this could be used to send an error alert with a bug report when running batch simulations in the cloud.
- on_experiment_infeasible_event(logs)[source]#
Called when an experiment simulation is infeasible due to an event.
- class pybamm.callbacks.CallbackList(callbacks)[source]#
Container abstracting a list of callbacks, so that they can be called in a single step e.g. callbacks.on_simulation_end(…).
This is done without having to redefine the method each time by using the callback_loop_decorator decorator, which is applied to every method that starts with on_, using the inspect module.
If better control over how the callbacks are called is required, it might be better to be more explicit with the for loop.
Extends:
pybamm.callbacks.Callback
- on_cycle_end(*args, **kwargs)#
Called at the end of each cycle in an experiment simulation.
- on_cycle_start(*args, **kwargs)#
Called at the start of each cycle in an experiment simulation.
- on_experiment_end(*args, **kwargs)#
Called at the end of an experiment simulation.
- on_experiment_error(*args, **kwargs)#
Called when a SolverError occurs during an experiment simulation.
For example, this could be used to send an error alert with a bug report when running batch simulations in the cloud.
- on_experiment_infeasible_event(*args, **kwargs)#
Called when an experiment simulation is infeasible due to an event.
- on_experiment_infeasible_time(*args, **kwargs)#
Called when an experiment simulation is infeasible due to reaching maximum time.
- on_experiment_start(*args, **kwargs)#
Called at the start of an experiment simulation.
- on_step_end(*args, **kwargs)#
Called at the end of each step in an experiment simulation.
- on_step_start(*args, **kwargs)#
Called at the start of each step in an experiment simulation.
- class pybamm.callbacks.LoggingCallback(logfile=None)[source]#
Logging callback, implements methods to log progress of the simulation.
- Parameters:
logfile (str, optional) – Where to send the log output. If None, uses pybamm’s logger.
Extends:
pybamm.callbacks.Callback
- on_experiment_error(logs)[source]#
Called when a SolverError occurs during an experiment simulation.
For example, this could be used to send an error alert with a bug report when running batch simulations in the cloud.
- on_experiment_infeasible_event(logs)[source]#
Called when an experiment simulation is infeasible due to an event.