1
---
2
name: pybamm
3
description: Simulates lithium-ion battery charge, discharge and rest experiments with PyBaMM, records parameter-set provenance, checks mesh and solver sensitivity, and compares predicted voltage curves with measured cycling data. Use for SPM or DFN electrochemical battery modeling, C-rate protocols, voltage cutoffs, parameter studies and numerical validation of battery simulations.
4
license: MIT
5
compatibility: Requires Python 3.12 with PyBaMM 26.9.0.0 and pybammsolvers 0.10.0 (IDAKLU). NumPy and CasADi are supplied by PyBaMM. Network is needed for installation and optional upstream dataset retrieval; bundled simulations and CSV comparisons run locally without credentials.
6
metadata:
7
version: "1.1"
8
skill-author: K-Dense Inc.
9
upstream-version: "26.9.0.0"
10
last-reviewed: "2026-10-01"
11
---
12
13
# PyBaMM battery experiments
14
15
## When to use
16
17
Use this skill to model single-cell constant-current charge/discharge and rest, examine voltage and charge
18
trajectories, or compare SPM/DFN predictions to cycling measurements. The helper runs real PyBaMM
19
experiments and three numerical resolutions; it does not control a battery cycler or establish an
20
operating envelope for hardware.
21
22
## Runtime and tested case
23
24
```bash
25
uv venv --python 3.12 battery-env
26
uv pip install --python battery-env/bin/python pybamm==26.9.0.0 pybammsolvers==0.10.0
27
```
28
29
This release requires `pybammsolvers>=0.10.0`, NumPy 2 or newer, and CasADi 3.8.1.
30
The tested environment used Python 3.12.10, NumPy 2.5.3 and SciPy 1.18.1. IDAKLU is the
31
recommended solver; `CasadiSolver` and `ScipySolver` are deprecated in this release. Refer to
32
the **26.9.0.0** manual below, since `latest` can describe unreleased APIs.
33
34
The included [assets/chen2020-protocol.json](assets/chen2020-protocol.json) is a synthetic
35
isothermal 298.15-K SPM case: 80% initial SOC, discharge at 0.5C for 600 s, rest for 120 s,
36
charge at 0.5C for 600 s. Chen2020 supplies an LG M50 parameterization with 5-Ah nominal capacity;
37
here 0.5C means 2.5 A. This is an executable reference example, not a claim that an arbitrary
38
user's cell has those parameters. The helper disables PyBaMM usage telemetry unless the caller
39
has already explicitly configured that variable.
40
41
## Workflow
42
43
1. Establish the cell chemistry, geometry, nominal capacity, initial state, temperature and
44
current-sign convention. Use an appropriate parameter set and explain its source. Distinguish
45
a paper's fitted parameters from measurements of this particular cell. Do not transplant
46
degradation parameters without checking their meaning and applicable conditions.
47
2. Convert the requested protocol to the JSON contract in
48
[references/protocol-and-comparison.md](references/protocol-and-comparison.md). Positive
49
simulation current discharges; negative current charges. Every step has a finite duration.
50
A specified voltage cutoff can end it earlier; the report records actual termination times.
51
C-rates use the selected set's nominal capacity. A change in that capacity changes current.
52
3. Choose SPM when its reduced transport assumptions are adequate; use DFN when resolving
53
electrolyte/electrode transport matters. The helper's tested models are isothermal and exclude
54
aging, mechanics, plating and pack control. Increasing rate can invalidate SPM predictions
55
even if numerical convergence is excellent.
56
4. Run the helper. It validates protocol fields, rejects unknown or overridden-by-protocol
57
parameter inputs, uses IDAKLU, and snapshots the base parameters **after SOC initialization**.
58
Keep the protocol with that snapshot: experiment steps supply their own currents.
59
Infeasible or skipped steps are errors,
60
rather than silently presenting a partial protocol as complete.
61
5. Read the two numerical comparisons separately: baseline versus tighter tolerances isolates
62
solver error; tight tolerances on the original versus doubled mesh isolates discretization.
63
Compare voltage differences and event-time differences against the accuracy the question
64
needs. Refine again when these are too large; one doubling does not prove convergence.
65
6. If measurements are available, check current, time origin, temperature, SOC and capacity
66
before interpreting residuals. Supply matching seconds, volts and amps. The helper reports
67
voltage RMSE/MAE/bias and current RMSE, preserving residuals. A small voltage error under a
68
mismatched input current does not validate the model. This workflow compares curves; it
69
does not claim to identify unique kinetic parameters from voltage alone.
70
71
## Run and inspect
72
73
From the skill directory, point `battery-env/bin/python` at the environment created above:
74
75
```bash
76
battery-env/bin/python scripts/simulate_battery.py assets/chen2020-protocol.json \
77
--output battery-reference
78
79
# measured.csv is user data with time_s,voltage_V,current_A columns.
80
battery-env/bin/python scripts/simulate_battery.py protocol.json \
81
--measured measured.csv --mesh-points 30 --output battery-comparison
82
```
83
84
The first command was executed as written with an external output location. The second uses
85
illustrative user filenames; the measurement path was exercised against a frozen synthetic
86
reference curve in the tests. Output directories must be new.
87
88
| Artifact | Interpretation |
89
| --- | --- |
90
| `curve.csv` | Baseline time, step, voltage, current and **net** discharge capacity |
91
| `tight-tolerance.csv` | Same mesh, tighter solver |
92
| `refined-mesh.csv` | Doubled mesh with tighter solver |
93
| `parameters.json` | Base parameters after SOC initialization; step currents remain in the protocol |
94
| `report.json` | Protocol/checksum, package versions, parameter source, numerical comparisons and terminations |
95
| `measurement-residuals.csv` | Prediction minus measurement and current mismatch, when measurements were supplied |
96
97
The reference case conserved integrated charge: 600 s at 2.5 A yielded 0.4166667 Ah, then equal
98
charge returned net discharge capacity to zero. Voltage stayed within the Chen2020 limits in this
99
case. Tightening tolerances changed voltage by about 1 microvolt; doubling mesh from 20 to 40
100
points changed it by about **2.17 mV**, so claiming sub-millivolt mesh accuracy would be unjustified.
101
A separate real DFN test stopped at the requested 3.9-V event and verified its charge integral.
102
Native tests also exercise charge cutoff, infeasible discharge, capacity-to-current conversion,
103
and replay of the exported SOC-adjusted parameters without reinitializing SOC.
104
The frozen reference is numerical regression evidence, not measured-cell validation.
105
106
## Primary references
107
108
- [PyBaMM experiment API examples](https://docs.pybamm.org/en/pybamm-v26.9.0.0/source/examples/notebooks/getting_started/tutorial-5-run-experiments.html)
109
- [Mesh refinement workflow](https://docs.pybamm.org/en/pybamm-v26.9.0.0/source/examples/notebooks/getting_started/tutorial-9-changing-the-mesh.html)
110
- [IDAKLU solver options](https://docs.pybamm.org/en/pybamm-v26.9.0.0/source/api/solvers/idaklu_solver.html)
111
- [Release source and changes](https://github.com/pybamm-team/PyBaMM/blob/pybamm-v26.9.0.0/CHANGELOG.md)
112
113
The linked release manuals, bundled helper, parameter serialization and optional DataLoader
114
recipe in the reference were verified against PyBaMM 26.9.0.0.
115