Skip to main content
pybamm.BatchStudy is a convenience class for running comparative studies across multiple models, solvers, parameter sets, or experimental conditions.

Constructor

pybamm.BatchStudy(
    models,
    experiments=None,
    geometries=None,
    parameter_values=None,
    submesh_types=None,
    var_pts=None,
    spatial_methods=None,
    solvers=None,
    output_variables=None,
    C_rates=None,
    repeats=1,
    permutations=False,
)
models
dict
required
Dictionary of name → model pairs. The models to simulate.
experiments
dict | None
default:"None"
Dictionary of experimental conditions keyed by name.
geometries
dict | None
default:"None"
Dictionary of geometry overrides keyed by name.
parameter_values
dict | None
default:"None"
Dictionary of ParameterValues objects keyed by name.
submesh_types
dict | None
default:"None"
Dictionary of submesh-type dicts keyed by name.
var_pts
dict | None
default:"None"
Dictionary of var_pts dicts keyed by name.
spatial_methods
dict | None
default:"None"
Dictionary of spatial-method dicts keyed by name.
solvers
dict | None
default:"None"
Dictionary of solver objects keyed by name.
output_variables
dict | None
default:"None"
Dictionary of variable lists for plotting, keyed by name.
C_rates
dict | None
default:"None"
Dictionary of C-rates for constant-current (dis)charge simulations, keyed by name.
repeats
int
default:"1"
Number of times each simulation is solved. The reported solve time is the average across repeats. Useful for benchmarking.
permutations
bool
default:"false"
  • False (default): pair elements by position — first model with first solver, etc.
  • True: run the full Cartesian product of models × solvers × experiments.
When permutations=False, every provided dict must have the same number of entries as models, or a ValueError is raised.

solve

BatchStudy.solve(
    t_eval=None,
    solver=None,
    save_at_cycles=None,
    calc_esoh=True,
    starting_solution=None,
    initial_soc=None,
    t_interp=None,
    **kwargs,
)
Solves all simulations and stores the results in self.sims. Parameters mirror pybamm.Simulation.solve.

plot

BatchStudy.plot(output_variables=None, **kwargs)
Open an interactive dynamic_plot comparing all simulations. Returns the QuickPlot instance.

create_gif

BatchStudy.create_gif(
    number_of_images=80,
    duration=0.1,
    output_filename="plot.gif",
)
Render a GIF of the dynamic_plot across the solution time span.
number_of_images
int
default:"80"
Number of frames.
duration
float
default:"0.1"
Duration (seconds) of each frame.
output_filename
str
default:"\"plot.gif\""
Output file path.

Accessing Results

After calling solve(), the sims attribute holds the list of solved pybamm.Simulation objects:
batch.solve([0, 3600])

for sim in batch.sims:
    sol = sim.solution
    print(sol["Terminal voltage [V]"].entries[-1])
    print(f"Solve time: {sol.solve_time:.3f} s")

Examples

import pybamm

batch = pybamm.BatchStudy(
    models={
        "SPM": pybamm.lithium_ion.SPM(),
        "DFN": pybamm.lithium_ion.DFN(),
    },
    parameter_values={
        "SPM": pybamm.ParameterValues("Chen2020"),
        "DFN": pybamm.ParameterValues("Chen2020"),
    },
)

batch.solve([0, 3600])
batch.plot()

Build docs developers (and LLMs) love