A differentiable simulation framework for solving forward and inverse problems of 🔋 lithium-ion batteries 🔋, with the backend support of the modern scientific computing framework JAX and the differentiable finite element analysis library JAX-FEM.
🔆 High-fidelity modeling: Modeling with real battery geometries
🔆 Automatic computation of Jacobian: Ready to incoprate multi-physics coupling mechanisms
🔆 End-to-end differentiability: Automatic computation of parameter sensitivities
First intsall JAX
(see JAX installation guide), then follow the JAX-FEM instructions to install JAX-FEM
, which will create a new conda environment. Activate the environment and clone the repository:
git clone https://github.com/xwpken/DiffLiB.git
cd DiffLiB
then install the package locally:
pip install -e .
Change to the cloned directory and run
python -m examples.forward.main
Variation of the terminal voltage during the constant-discharge.(Solid lines: DiffLiB; markers: PyBaMM)
Change to the cloned directory and run
python -m examples.gradient.main
Taylor test results for the validation of gradient computations.
Validation with the finite difference method
grad_ad.shape = (8,)
grad_fd.shape = ()
grad_ad can give the gradient all at once, but grad_fd can only give one value!
Let's compare the value by both methods:
grad_ad[0] = -3.883050e+00
grad_fd = -3.883050e+00
Relative error = 0.000013%
📣 Coming soon!
This project is licensed under the GNU General Public License v3 - see the LICENSE for details.
If you found this library useful, we appreciate your support if you consider citing the following paper:
@article{xu2025difflib,
title={DiffLiB: High-fidelity differentiable modeling of lithium-ion batteries and efficient gradient-based parameter identification},
author={Xu, Weipeng and Yang, Kaiqi and Zhang, Yuzhi and Sun, Shichao and Mao, Sheng and Xue, Tianju},
journal={arXiv preprint arXiv:2504.20674},
year={2025}
}