Ways to contribute
Bug reports
Found something broken? Open a bug report on GitHub with a minimal reproducible example.
Feature requests
Propose new models, solvers, or API improvements by opening an issue for discussion before writing code.
Documentation
Fix typos, clarify explanations, improve docstrings, or add example notebooks to help other users.
Parameter sets
Add published battery parameter sets with full references so the community can reproduce experimental results.
Development setup
Fork and clone
Create a fork of the PyBaMM repository on GitHub, then clone your fork locally:Create a new branch for your changes:
Create a virtual environment
Use a virtual environment to keep your PyBaMM development dependencies isolated:
Install PyBaMM with all dependencies
Install PyBaMM in editable mode together with all optional and development dependencies:The
[all] extra installs scikit-fem, meshio, matplotlib, pybtex, bpx, tqdm, and other optional packages. The dev dependency group adds pytest, ruff, nox, pre-commit, and related tooling.docs and dev dependencies are declared as PEP 735 dependency groups in pyproject.toml. If your pip version does not support --group, install them individually or use uv sync --group dev.Install pre-commit hooks
PyBaMM uses pre-commit to run code style and quality checks automatically on every commit:To run all checks immediately on every file (without committing):Hooks include
ruff-check, ruff-format, blacken-docs, and several file-integrity checks. See .pre-commit-config.yaml for the full list.Code style
PyBaMM follows PEP 8 and enforces it automatically with ruff.Ruff
Ruff handles both linting and formatting. Run it manually at any time:pyproject.toml under [tool.ruff].
Naming conventions
- Classes: CamelCase starting with an uppercase letter — e.g.,
MyBatteryModel. - Methods and variables: lowercase with underscores — e.g.,
iteration_count. - Prefer descriptive names over abbreviations:
meanis better thanmu.
Testing
Every new feature or bug fix must include tests. PyBaMM uses pytest with the following plugins:| Plugin | Purpose |
|---|---|
pytest-xdist | Run tests in parallel (-nauto by default) |
nbmake | Test example Jupyter notebooks |
pytest-mock | Mocking and patching |
hypothesis | Property-based testing |
Nox sessions
| Command | What it runs |
|---|---|
nox -s unit | Unit tests only |
nox -s tests | Unit and integration tests |
nox -s examples | All example notebooks in docs/source/examples/ |
nox -s scripts | All example scripts in examples/ |
nox -s docs | Build the documentation and serve at http://127.0.0.1:8000 |
Running a single test
Writing tests
Look in thetests/ directory for a test covering a similar method, copy it as a starting point, and add assert statements to verify your output. Tests should be fast — unit tests check individual functions, integration tests check end-to-end behaviour.
Adding citations
PyBaMM automatically tracks which papers are used by a simulation. When your code is used, PyBaMM can cite the relevant publications:- Add the BibTeX entry for your paper to
src/pybamm/CITATIONS.bib. - Register the citation in the code where it is used:
register call in the __init__ method of a model or solver class, or inside the function that uses the cited method. Pass a filename to print_citations to write BibTeX to a file instead of printing to the terminal.
Pull request process
- Open an issue first for any non-trivial change so the approach can be discussed before you write code.
- Write and test your code, following the style guidelines above.
- Run
pre-commit run --all-filesand fix any remaining issues. - Run
nox -s unit(at minimum) to confirm all tests pass. - Open a pull request on PyBaMM’s GitHub page. Describe what the change does and why.
- A community member will review your PR. Address any requested changes by pushing new commits to the same branch.
- Once approved, a maintainer with write access will merge the PR.
GitHub Actions runs the full test suite against every pull request across multiple operating systems and all supported Python versions (3.10–3.14). A green check on all workflows is required before merging.
Community
- Discourse forum: https://www.pybamm.org/ — ask questions and discuss ideas with other PyBaMM users and developers.
- GitHub issues: github.com/pybamm-team/PyBaMM/issues — bug reports and feature requests.
- GitHub discussions: for broader questions about the project direction.
- Contact: [email protected]