Learn how to load built-in parameter sets, modify individual parameters, define custom parameter functions, and load parameters from BPX files.
pybamm.ParameterValues holds all the numerical values that define a specific battery cell — geometry, material properties, transport coefficients, kinetic parameters, and more. Every parameter in PyBaMM carries SI units in its name.
param = pybamm.ParameterValues("Chen2020")# Access a single parameterprint(param["Nominal cell capacity [A.h]"])# List all keysprint(list(param.keys()))# Get parameter metadata (units, category, etc.)info = param.get_info("Reference temperature [K]")print(info.units) # 'K'# List parameters by categoryneg_electrode_params = param.list_by_category("negative electrode")
Many parameters are functions (e.g. diffusivity as a function of concentration and temperature). Define them as Python callables:
import pybamm# Diffusivity as a function of concentration and temperaturedef my_diffusivity(c_e, T): return 1.0e-10 * pybamm.exp(-500 / T)param = pybamm.ParameterValues("Chen2020")param["Electrolyte diffusivity [m2.s-1]"] = my_diffusivity
The function arguments must use pybamm symbolic expressions so they can be differentiated and compiled.
BPX support requires the optional bpx dependency: pip install pybamm[bpx]
Loading from a BPX file
param = pybamm.ParameterValues.create_from_bpx("my_cell.json")# Load at a specific target SOCparam = pybamm.ParameterValues.create_from_bpx("my_cell.json", target_soc=0.8)
For parameter sweeps or sensitivity analysis, mark a parameter as an "[input]" to pass it at solve time without rebuilding the model:
param = pybamm.ParameterValues("Chen2020")param["Current function [A]"] = "[input]"model = pybamm.lithium_ion.SPM()sim = pybamm.Simulation(model, parameter_values=param)sim.build()# Solve with different currents without rebuildingfor current in [1.0, 2.0, 5.0]: sol = sim.solve([0, 3600], inputs={"Current function [A]": current}) print(current, sol["Battery voltage [V]"].entries[-1])