pybamm.BatchStudy automates running many pybamm.Simulation instances — useful for parameter sweeps, model comparisons, and sensitivity analyses. After solving, results from all simulations are available via batch.sims and can be plotted together with batch.plot().
Constructor
Parameters
| Parameter | Type | Description |
|---|---|---|
models | dict | Required. {name: model} mapping of models to simulate |
experiments | dict, optional | {name: experiment} mapping of pybamm.Experiment objects |
geometries | dict, optional | Custom geometry dicts |
parameter_values | dict, optional | {name: pybamm.ParameterValues} objects |
submesh_types | dict, optional | Custom submesh type dicts |
var_pts | dict, optional | Mesh resolution dicts |
spatial_methods | dict, optional | Spatial method dicts |
solvers | dict, optional | {name: solver} mapping |
output_variables | dict, optional | Variables to plot automatically |
C_rates | dict, optional | Constant-current (dis)charge C-rates |
repeats | int | Number of times to call solve per simulation (for timing averages). Default 1 |
permutations | bool | If False (default), pair models with corresponding entries by position. If True, run the Cartesian product of all inputs |
When
permutations=False, every non-None dict must have the same number of entries as models. A ValueError is raised otherwise.solve()
pybamm.Simulation.solve() for each simulation. After calling solve(), batch.sims contains a list of the solved pybamm.Simulation objects in the order they were run.
Use cases
Model comparison
Model comparison
Compare SPM, SPMe, and DFN under identical conditions:
model_comparison.py
Parameter sweep
Parameter sweep
Sweep over different C-rates using
permutations=False (one model, one C-rate per entry) or pair models with different parameter sets:parameter_sweep.py
Cartesian product of models and solvers
Cartesian product of models and solvers
With
permutations=True, every combination of the provided inputs is run:permutations.py
Accessing results
Afterbatch.solve(), iterate over batch.sims:
access_results.py
repeats > 1, sim.solution.solve_time and sim.solution.integration_time hold the average across repeats:
timing.py
Plotting
batch.plot() calls pybamm.dynamic_plot(batch.sims, ...) and returns a QuickPlot instance stored in batch.quick_plot.