PyBaMM-GEM 0.2.0__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pybamm_gem-0.2.2/.github/workflows/ci.yml +63 -0
- pybamm_gem-0.2.2/.github/workflows/monthly-report.yml +63 -0
- pybamm_gem-0.2.2/.github/workflows/release.yml +103 -0
- pybamm_gem-0.2.2/CHANGELOG.md +26 -0
- pybamm_gem-0.2.2/PKG-INFO +115 -0
- pybamm_gem-0.2.2/README.md +97 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/pyproject.toml +2 -2
- pybamm_gem-0.2.2/scripts/health_report.py +135 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/__init__.py +2 -1
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/_registry.py +29 -10
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/tests/test_registry.py +35 -0
- pybamm_gem-0.2.2/tests/test_zoo_contract.py +30 -0
- pybamm_gem-0.2.0/.github/workflows/ci.yml +0 -53
- pybamm_gem-0.2.0/CHANGELOG.md +0 -11
- pybamm_gem-0.2.0/PKG-INFO +0 -63
- pybamm_gem-0.2.0/README.md +0 -46
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/.gitignore +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/LICENSE.txt +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/LICENSES-bundled.txt +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/examples/higher_dimensional_models.ipynb +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/CITATION.bib +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/README.md +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/__init__.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/examples/run_dfn_2d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/model.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/model.toml +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_2d/tests/test_dfn_2d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/CITATION.bib +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/README.md +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/__init__.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/examples/run_dfn_3d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/model.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/model.toml +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/dfn_3d/tests/test_dfn_3d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/lithium_ion/__init__.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/CITATION.bib +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/README.md +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/__init__.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/examples/run_spm_2d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/model.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/model.toml +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_2d/tests/test_spm_2d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/CITATION.bib +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/README.md +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/__init__.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/examples/run_spm_3d.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/model.py +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/model.toml +0 -0
- {pybamm_gem-0.2.0 → pybamm_gem-0.2.2}/src/pybamm_gem/spm_3d/tests/test_spm_3d.py +0 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Runs on every push and pull request, and every Monday against the newest PyBaMM and the newest
|
|
2
|
+
# PyBaMM model zoo (pybamm-model-zoo): ruff, GEM's tests and the zoo's contract checks.
|
|
3
|
+
# Weekly runs only: if a check fails, ONE issue is opened (or commented on) and @mohammedasher is
|
|
4
|
+
# mentioned, so GitHub emails him. When the weekly run passes again, the issue is closed.
|
|
5
|
+
# It never changes any code.
|
|
6
|
+
name: CI
|
|
7
|
+
|
|
8
|
+
on:
|
|
9
|
+
push:
|
|
10
|
+
pull_request:
|
|
11
|
+
schedule:
|
|
12
|
+
- cron: "17 6 * * 1"
|
|
13
|
+
workflow_dispatch:
|
|
14
|
+
|
|
15
|
+
permissions:
|
|
16
|
+
contents: read
|
|
17
|
+
issues: write
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
test:
|
|
21
|
+
name: Newest PyBaMM and model zoo
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.12"
|
|
28
|
+
- name: Install
|
|
29
|
+
run: |
|
|
30
|
+
pip install --upgrade pip
|
|
31
|
+
pip install --upgrade pybamm pybamm-model-zoo
|
|
32
|
+
pip install -e ".[dev]"
|
|
33
|
+
python -c "import pybamm, pybamm_model_zoo; print('PyBaMM', pybamm.__version__, ' zoo', pybamm_model_zoo.__version__)"
|
|
34
|
+
- name: Lint
|
|
35
|
+
run: ruff check src tests scripts
|
|
36
|
+
- name: Test (GEM's tests and the zoo's contract checks)
|
|
37
|
+
run: pytest
|
|
38
|
+
|
|
39
|
+
report:
|
|
40
|
+
name: Weekly report
|
|
41
|
+
needs: [test]
|
|
42
|
+
if: ${{ always() && github.event_name == 'schedule' }}
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
steps:
|
|
45
|
+
- name: Open, update or close the "Weekly check failed" issue
|
|
46
|
+
env:
|
|
47
|
+
GH_TOKEN: ${{ github.token }}
|
|
48
|
+
REPO: ${{ github.repository }}
|
|
49
|
+
RESULT: ${{ needs.test.result }}
|
|
50
|
+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
51
|
+
run: |
|
|
52
|
+
TITLE="Weekly check failed"
|
|
53
|
+
NUMBER=$(gh issue list --repo "$REPO" --state open --search "$TITLE in:title" --json number --jq '.[0].number')
|
|
54
|
+
if [ "$RESULT" = "success" ]; then
|
|
55
|
+
if [ -n "$NUMBER" ]; then
|
|
56
|
+
gh issue comment "$NUMBER" --repo "$REPO" --body "Passing again with the newest PyBaMM and model zoo: $RUN_URL"
|
|
57
|
+
gh issue close "$NUMBER" --repo "$REPO"
|
|
58
|
+
fi
|
|
59
|
+
elif [ -z "$NUMBER" ]; then
|
|
60
|
+
gh issue create --repo "$REPO" --title "$TITLE" --body "@mohammedasher the weekly check against the newest PyBaMM and model zoo failed: $RUN_URL"
|
|
61
|
+
else
|
|
62
|
+
gh issue comment "$NUMBER" --repo "$REPO" --body "@mohammedasher failed again: $RUN_URL"
|
|
63
|
+
fi
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# On the 1st of every month: installs PyBaMM-GEM from PyPI (what users get) with the newest
|
|
2
|
+
# PyBaMM and model zoo, runs the tests and scripts/health_report.py, and posts the result as a
|
|
3
|
+
# comment on the pinned "Monthly health report" issue, mentioning the people below so GitHub
|
|
4
|
+
# emails them. It never changes any code.
|
|
5
|
+
name: Monthly health report
|
|
6
|
+
|
|
7
|
+
on:
|
|
8
|
+
schedule:
|
|
9
|
+
- cron: "0 7 1 * *"
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
permissions:
|
|
13
|
+
contents: read
|
|
14
|
+
issues: write
|
|
15
|
+
actions: read
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
report:
|
|
19
|
+
runs-on: ubuntu-latest
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v4
|
|
22
|
+
- uses: actions/setup-python@v5
|
|
23
|
+
with:
|
|
24
|
+
python-version: "3.12"
|
|
25
|
+
- name: Install PyBaMM-GEM from PyPI with the newest PyBaMM and model zoo
|
|
26
|
+
run: |
|
|
27
|
+
pip install --upgrade pip
|
|
28
|
+
pip install --upgrade pybamm-gem pybamm pybamm-model-zoo pytest
|
|
29
|
+
- name: Run the tests and the health report
|
|
30
|
+
run: |
|
|
31
|
+
cd /tmp
|
|
32
|
+
pytest --import-mode=importlib --pyargs pybamm_gem -q > tests.txt 2>&1 || true
|
|
33
|
+
python "$GITHUB_WORKSPACE/scripts/health_report.py" report.md
|
|
34
|
+
- name: Post the report
|
|
35
|
+
env:
|
|
36
|
+
GH_TOKEN: ${{ github.token }}
|
|
37
|
+
REPO: ${{ github.repository }}
|
|
38
|
+
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
39
|
+
PEOPLE: "@gjo97 @MonicaMarinescu @mohammedasher"
|
|
40
|
+
run: |
|
|
41
|
+
cd /tmp
|
|
42
|
+
WEEKLY=$(gh run list --repo "$REPO" --workflow ci.yml --event schedule --limit 4 --json conclusion --jq '[.[].conclusion] | join(", ")')
|
|
43
|
+
{
|
|
44
|
+
echo "## PyBaMM-GEM health report, $(date -u +%Y-%m)"
|
|
45
|
+
echo
|
|
46
|
+
echo "$PEOPLE: the monthly check of PyBaMM-GEM (as installed from PyPI) with the newest PyBaMM and PyBaMM model zoo."
|
|
47
|
+
echo
|
|
48
|
+
cat report.md
|
|
49
|
+
echo
|
|
50
|
+
echo "**Model tests:** $(tail -n 1 tests.txt)"
|
|
51
|
+
echo
|
|
52
|
+
echo "**Last weekly checks (newest first):** ${WEEKLY:-none yet}"
|
|
53
|
+
echo
|
|
54
|
+
echo "Details: $RUN_URL"
|
|
55
|
+
} > body.md
|
|
56
|
+
TITLE="Monthly health report"
|
|
57
|
+
NUMBER=$(gh issue list --repo "$REPO" --state open --search "$TITLE in:title" --json number --jq '.[0].number')
|
|
58
|
+
if [ -z "$NUMBER" ]; then
|
|
59
|
+
URL=$(gh issue create --repo "$REPO" --title "$TITLE" --body "A health report of PyBaMM-GEM is added here as a comment on the 1st of every month.")
|
|
60
|
+
NUMBER=${URL##*/}
|
|
61
|
+
gh issue pin "$NUMBER" --repo "$REPO" || true
|
|
62
|
+
fi
|
|
63
|
+
gh issue comment "$NUMBER" --repo "$REPO" --body-file body.md
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# Publishes PyBaMM-GEM when a GitHub release is published (tag "v" + the version in pyproject.toml).
|
|
2
|
+
# 1. Build the package and run its tests.
|
|
3
|
+
# 2. Upload to TestPyPI, install it from there and run the tests again.
|
|
4
|
+
# 3. Upload to PyPI. This step waits until a maintainer approves it (GitHub environment "pypi").
|
|
5
|
+
# No tokens are stored anywhere: PyPI and TestPyPI trust this workflow ("trusted publishing").
|
|
6
|
+
# Running it by hand (Actions -> Release -> Run workflow) only does steps 1 and 2, as a test.
|
|
7
|
+
name: Release
|
|
8
|
+
|
|
9
|
+
on:
|
|
10
|
+
release:
|
|
11
|
+
types: [published]
|
|
12
|
+
workflow_dispatch:
|
|
13
|
+
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
build:
|
|
19
|
+
name: Build and test
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
steps:
|
|
22
|
+
- uses: actions/checkout@v4
|
|
23
|
+
- uses: actions/setup-python@v5
|
|
24
|
+
with:
|
|
25
|
+
python-version: "3.12"
|
|
26
|
+
- name: Check that the release tag matches the version
|
|
27
|
+
if: github.event_name == 'release'
|
|
28
|
+
run: |
|
|
29
|
+
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
30
|
+
if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then
|
|
31
|
+
echo "The tag is $GITHUB_REF_NAME but pyproject.toml says version $VERSION"
|
|
32
|
+
exit 1
|
|
33
|
+
fi
|
|
34
|
+
- name: Build
|
|
35
|
+
run: |
|
|
36
|
+
pip install build twine
|
|
37
|
+
python -m build
|
|
38
|
+
twine check dist/*
|
|
39
|
+
- name: Test the built package
|
|
40
|
+
run: |
|
|
41
|
+
pip install dist/*.whl pytest
|
|
42
|
+
cd /tmp
|
|
43
|
+
pytest --import-mode=importlib --pyargs pybamm_gem
|
|
44
|
+
- uses: actions/upload-artifact@v4
|
|
45
|
+
with:
|
|
46
|
+
name: dist
|
|
47
|
+
path: dist/
|
|
48
|
+
|
|
49
|
+
testpypi:
|
|
50
|
+
name: Upload to TestPyPI
|
|
51
|
+
needs: build
|
|
52
|
+
runs-on: ubuntu-latest
|
|
53
|
+
environment: testpypi
|
|
54
|
+
permissions:
|
|
55
|
+
id-token: write
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/download-artifact@v4
|
|
58
|
+
with:
|
|
59
|
+
name: dist
|
|
60
|
+
path: dist/
|
|
61
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
62
|
+
with:
|
|
63
|
+
repository-url: https://test.pypi.org/legacy/
|
|
64
|
+
skip-existing: true
|
|
65
|
+
|
|
66
|
+
check-testpypi:
|
|
67
|
+
name: Install from TestPyPI and test
|
|
68
|
+
needs: testpypi
|
|
69
|
+
runs-on: ubuntu-latest
|
|
70
|
+
steps:
|
|
71
|
+
- uses: actions/checkout@v4
|
|
72
|
+
- uses: actions/setup-python@v5
|
|
73
|
+
with:
|
|
74
|
+
python-version: "3.12"
|
|
75
|
+
- name: Install and test
|
|
76
|
+
run: |
|
|
77
|
+
VERSION=$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")
|
|
78
|
+
pip install "pybamm[cite]>=26.9" pytest
|
|
79
|
+
# A new upload can take up to 15 minutes to appear on TestPyPI
|
|
80
|
+
for attempt in $(seq 1 30); do
|
|
81
|
+
if pip install --no-cache-dir --no-deps --index-url https://test.pypi.org/simple/ "pybamm-gem==$VERSION"; then
|
|
82
|
+
break
|
|
83
|
+
fi
|
|
84
|
+
sleep 30
|
|
85
|
+
done
|
|
86
|
+
cd /tmp
|
|
87
|
+
python -c "import pybamm_gem; print(pybamm_gem.__version__, pybamm_gem.list_models())"
|
|
88
|
+
pytest --import-mode=importlib --pyargs pybamm_gem
|
|
89
|
+
|
|
90
|
+
pypi:
|
|
91
|
+
name: Upload to PyPI (needs approval)
|
|
92
|
+
needs: check-testpypi
|
|
93
|
+
if: github.event_name == 'release'
|
|
94
|
+
runs-on: ubuntu-latest
|
|
95
|
+
environment: pypi
|
|
96
|
+
permissions:
|
|
97
|
+
id-token: write
|
|
98
|
+
steps:
|
|
99
|
+
- uses: actions/download-artifact@v4
|
|
100
|
+
with:
|
|
101
|
+
name: dist
|
|
102
|
+
path: dist/
|
|
103
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.2
|
|
4
|
+
|
|
5
|
+
- README: the models first, then installation and usage, then a description of PyBaMM-GEM.
|
|
6
|
+
- Tests: the PyBaMM model zoo's contract checks run on every GEM model
|
|
7
|
+
(`pybamm-model-zoo` added to the `dev` extra).
|
|
8
|
+
- CI: weekly checks against the newest PyBaMM and PyBaMM model zoo, and a monthly health report.
|
|
9
|
+
- Release workflow: waits up to 15 minutes for TestPyPI to list a new upload.
|
|
10
|
+
|
|
11
|
+
## 0.2.1
|
|
12
|
+
|
|
13
|
+
- `pybamm_gem` now has the same commands as the PyBaMM model zoo: `require()` is new, and
|
|
14
|
+
`info()`, `load()`, `require()` and `register_citation()` accept the class name (for example
|
|
15
|
+
`"BasicSPM2D"`) as well as the slug (`"spm_2d"`).
|
|
16
|
+
- `info()` fields can be read as `info.title` as well as `info["title"]`.
|
|
17
|
+
|
|
18
|
+
## 0.2.0
|
|
19
|
+
|
|
20
|
+
- Rebuilt in the PyBaMM model-zoo layout: one folder per model, each with a `model.toml`
|
|
21
|
+
manifest, `CITATION.bib`, `README.md`, tests and an example.
|
|
22
|
+
- Models: `spm_2d` (`BasicSPM2D`), `spm_3d` (`BasicSPM3D`), `dfn_2d` (`DFN2D`) and `dfn_3d` (`DFN3D`).
|
|
23
|
+
- Registry: `pybamm_gem.list_models()`, `pybamm_gem.info()` and `pybamm_gem.load()`.
|
|
24
|
+
- Example notebook: `examples/higher_dimensional_models.ipynb`.
|
|
25
|
+
- Needs PyBaMM 26.9 or newer.
|
|
26
|
+
- The previous code is kept on the branch `legacy-2026-11`.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: PyBaMM-GEM
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Spatially resolved (2D and 3D) battery models for PyBaMM
|
|
5
|
+
Author: Mohammed Asheruddin N
|
|
6
|
+
License-Expression: BSD-3-Clause
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
License-File: LICENSES-bundled.txt
|
|
9
|
+
Keywords: battery,electrochemistry,lithium-ion,modelling,pybamm,simulation
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Requires-Dist: pybamm[cite]>=26.9
|
|
12
|
+
Requires-Dist: tomli>=2.0.1; python_version < '3.11'
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pybamm-model-zoo; extra == 'dev'
|
|
15
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
16
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
17
|
+
Description-Content-Type: text/markdown
|
|
18
|
+
|
|
19
|
+
# PyBaMM-GEM
|
|
20
|
+
|
|
21
|
+
An open-source extension package for PyBaMM providing advanced battery models, degradation
|
|
22
|
+
models, and simulation tools.
|
|
23
|
+
|
|
24
|
+
## Models
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
import pybamm_gem as gem
|
|
28
|
+
|
|
29
|
+
print(gem.list_models())
|
|
30
|
+
# ['dfn_2d', 'dfn_3d', 'spm_2d', 'spm_3d']
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Model | Class | What it is |
|
|
34
|
+
|---|---|---|
|
|
35
|
+
| `dfn_2d` | `DFN2D` | Doyle-Fuller-Newman model resolved in x and z |
|
|
36
|
+
| `dfn_3d` | `DFN3D` | The same, resolved in x, y and z |
|
|
37
|
+
| `spm_2d` | `BasicSPM2D` | Single Particle Model with a pair of particles at every height z |
|
|
38
|
+
| `spm_3d` | `BasicSPM3D` | The same, over a y-z grid of points |
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
pip install pybamm-gem
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
PyBaMM 26.9 or newer is needed. To get the newest code from GitHub instead:
|
|
47
|
+
`pip install git+https://github.com/ImperialCollegeLondon/PyBaMM-GEM`
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
import pybamm
|
|
53
|
+
import pybamm_gem as gem
|
|
54
|
+
|
|
55
|
+
print(gem.list_models())
|
|
56
|
+
model = gem.load("spm_2d")()
|
|
57
|
+
simulation = pybamm.Simulation(model)
|
|
58
|
+
solution = simulation.solve([0, 3000])
|
|
59
|
+
print(solution["Voltage [V]"](1500))
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
|
|
63
|
+
`gem.lithium_ion.DFN2D`.
|
|
64
|
+
|
|
65
|
+
The commands are the same as in the PyBaMM model zoo (`pybamm_model_zoo`): `list_models()`,
|
|
66
|
+
`info()`, `load()`, `require()` and `register_citation()`. `info()`, `load()`, `require()` and
|
|
67
|
+
`register_citation()` take either the slug (`"spm_2d"`) or the class name (`"BasicSPM2D"`);
|
|
68
|
+
`list_models()` returns the slugs. With `pybamm-model-zoo` installed, the GEM models are also
|
|
69
|
+
listed by `pybamm_model_zoo.list_models()`.
|
|
70
|
+
|
|
71
|
+
The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
|
|
72
|
+
the stock PyBaMM models and shows a temperature that changes with height.
|
|
73
|
+
|
|
74
|
+
## About PyBaMM-GEM
|
|
75
|
+
|
|
76
|
+
PyBaMM-GEM is an open, collaborative home for battery models that extend
|
|
77
|
+
[PyBaMM](https://pybamm.org). Many new models are experimental, specialised or still under active
|
|
78
|
+
research, which makes them unsuitable for the core PyBaMM project in their early stages. GEM is
|
|
79
|
+
where they can be developed, validated, compared and shared, while staying close to PyBaMM. Some
|
|
80
|
+
GEM models may later move into PyBaMM; others stay in GEM because they answer specialised
|
|
81
|
+
questions. Both outcomes count as success.
|
|
82
|
+
|
|
83
|
+
**Stay close to PyBaMM. Explore beyond it.** GEM models follow PyBaMM's design, options and user
|
|
84
|
+
experience, so PyBaMM users feel at home. Where a GEM model differs scientifically from a PyBaMM
|
|
85
|
+
model, it is a separate, explicitly named model. Every release states the PyBaMM versions it
|
|
86
|
+
supports.
|
|
87
|
+
|
|
88
|
+
GEM stands for **General Enough Model** and **Good Enough Model**: the fewest physical processes
|
|
89
|
+
needed to explain the behaviour of interest. The name also honours Professor John B. Goodenough.
|
|
90
|
+
|
|
91
|
+
The models are laid out like the PyBaMM model zoo: one folder per model, each with a `model.toml`
|
|
92
|
+
manifest, a `CITATION.bib`, a README, tests and an example.
|
|
93
|
+
|
|
94
|
+
## Automatic checks
|
|
95
|
+
|
|
96
|
+
- **Every push and pull request, and every Monday:** ruff, GEM's tests and the PyBaMM model zoo's
|
|
97
|
+
contract checks, against the newest PyBaMM and `pybamm-model-zoo`. If the Monday run fails, an
|
|
98
|
+
issue "Weekly check failed" is opened; it is closed when the check passes again.
|
|
99
|
+
- **1st of every month:** a health report of the released package (installed from PyPI) with the
|
|
100
|
+
newest PyBaMM and model zoo, posted on the pinned issue "Monthly health report". It can also be
|
|
101
|
+
run by hand with `python scripts/health_report.py`.
|
|
102
|
+
|
|
103
|
+
## Releasing a new version
|
|
104
|
+
|
|
105
|
+
1. In a pull request, raise `version` in `pyproject.toml` (for example `0.2.2`) and add a
|
|
106
|
+
`CHANGELOG.md` entry. Merge it.
|
|
107
|
+
2. On GitHub, go to Releases, then "Draft a new release". Create the tag `v0.2.2` (a "v" and
|
|
108
|
+
the version), add a title and notes, and publish.
|
|
109
|
+
3. The Release workflow builds and tests the package, uploads it to TestPyPI and tests it again.
|
|
110
|
+
It then waits for a maintainer to approve the upload to PyPI (GitHub sends an email).
|
|
111
|
+
|
|
112
|
+
## Licence
|
|
113
|
+
|
|
114
|
+
BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
|
|
115
|
+
Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# PyBaMM-GEM
|
|
2
|
+
|
|
3
|
+
An open-source extension package for PyBaMM providing advanced battery models, degradation
|
|
4
|
+
models, and simulation tools.
|
|
5
|
+
|
|
6
|
+
## Models
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
import pybamm_gem as gem
|
|
10
|
+
|
|
11
|
+
print(gem.list_models())
|
|
12
|
+
# ['dfn_2d', 'dfn_3d', 'spm_2d', 'spm_3d']
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
| Model | Class | What it is |
|
|
16
|
+
|---|---|---|
|
|
17
|
+
| `dfn_2d` | `DFN2D` | Doyle-Fuller-Newman model resolved in x and z |
|
|
18
|
+
| `dfn_3d` | `DFN3D` | The same, resolved in x, y and z |
|
|
19
|
+
| `spm_2d` | `BasicSPM2D` | Single Particle Model with a pair of particles at every height z |
|
|
20
|
+
| `spm_3d` | `BasicSPM3D` | The same, over a y-z grid of points |
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
pip install pybamm-gem
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
PyBaMM 26.9 or newer is needed. To get the newest code from GitHub instead:
|
|
29
|
+
`pip install git+https://github.com/ImperialCollegeLondon/PyBaMM-GEM`
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
import pybamm
|
|
35
|
+
import pybamm_gem as gem
|
|
36
|
+
|
|
37
|
+
print(gem.list_models())
|
|
38
|
+
model = gem.load("spm_2d")()
|
|
39
|
+
simulation = pybamm.Simulation(model)
|
|
40
|
+
solution = simulation.solve([0, 3000])
|
|
41
|
+
print(solution["Voltage [V]"](1500))
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
|
|
45
|
+
`gem.lithium_ion.DFN2D`.
|
|
46
|
+
|
|
47
|
+
The commands are the same as in the PyBaMM model zoo (`pybamm_model_zoo`): `list_models()`,
|
|
48
|
+
`info()`, `load()`, `require()` and `register_citation()`. `info()`, `load()`, `require()` and
|
|
49
|
+
`register_citation()` take either the slug (`"spm_2d"`) or the class name (`"BasicSPM2D"`);
|
|
50
|
+
`list_models()` returns the slugs. With `pybamm-model-zoo` installed, the GEM models are also
|
|
51
|
+
listed by `pybamm_model_zoo.list_models()`.
|
|
52
|
+
|
|
53
|
+
The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
|
|
54
|
+
the stock PyBaMM models and shows a temperature that changes with height.
|
|
55
|
+
|
|
56
|
+
## About PyBaMM-GEM
|
|
57
|
+
|
|
58
|
+
PyBaMM-GEM is an open, collaborative home for battery models that extend
|
|
59
|
+
[PyBaMM](https://pybamm.org). Many new models are experimental, specialised or still under active
|
|
60
|
+
research, which makes them unsuitable for the core PyBaMM project in their early stages. GEM is
|
|
61
|
+
where they can be developed, validated, compared and shared, while staying close to PyBaMM. Some
|
|
62
|
+
GEM models may later move into PyBaMM; others stay in GEM because they answer specialised
|
|
63
|
+
questions. Both outcomes count as success.
|
|
64
|
+
|
|
65
|
+
**Stay close to PyBaMM. Explore beyond it.** GEM models follow PyBaMM's design, options and user
|
|
66
|
+
experience, so PyBaMM users feel at home. Where a GEM model differs scientifically from a PyBaMM
|
|
67
|
+
model, it is a separate, explicitly named model. Every release states the PyBaMM versions it
|
|
68
|
+
supports.
|
|
69
|
+
|
|
70
|
+
GEM stands for **General Enough Model** and **Good Enough Model**: the fewest physical processes
|
|
71
|
+
needed to explain the behaviour of interest. The name also honours Professor John B. Goodenough.
|
|
72
|
+
|
|
73
|
+
The models are laid out like the PyBaMM model zoo: one folder per model, each with a `model.toml`
|
|
74
|
+
manifest, a `CITATION.bib`, a README, tests and an example.
|
|
75
|
+
|
|
76
|
+
## Automatic checks
|
|
77
|
+
|
|
78
|
+
- **Every push and pull request, and every Monday:** ruff, GEM's tests and the PyBaMM model zoo's
|
|
79
|
+
contract checks, against the newest PyBaMM and `pybamm-model-zoo`. If the Monday run fails, an
|
|
80
|
+
issue "Weekly check failed" is opened; it is closed when the check passes again.
|
|
81
|
+
- **1st of every month:** a health report of the released package (installed from PyPI) with the
|
|
82
|
+
newest PyBaMM and model zoo, posted on the pinned issue "Monthly health report". It can also be
|
|
83
|
+
run by hand with `python scripts/health_report.py`.
|
|
84
|
+
|
|
85
|
+
## Releasing a new version
|
|
86
|
+
|
|
87
|
+
1. In a pull request, raise `version` in `pyproject.toml` (for example `0.2.2`) and add a
|
|
88
|
+
`CHANGELOG.md` entry. Merge it.
|
|
89
|
+
2. On GitHub, go to Releases, then "Draft a new release". Create the tag `v0.2.2` (a "v" and
|
|
90
|
+
the version), add a title and notes, and publish.
|
|
91
|
+
3. The Release workflow builds and tests the package, uploads it to TestPyPI and tests it again.
|
|
92
|
+
It then waits for a maintainer to approve the upload to PyPI (GitHub sends an email).
|
|
93
|
+
|
|
94
|
+
## Licence
|
|
95
|
+
|
|
96
|
+
BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
|
|
97
|
+
Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
|
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "PyBaMM-GEM"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.2"
|
|
8
8
|
license = "BSD-3-Clause"
|
|
9
9
|
license-files = ["LICENSE.txt", "LICENSES-bundled.txt"]
|
|
10
10
|
description = "Spatially resolved (2D and 3D) battery models for PyBaMM"
|
|
@@ -18,7 +18,7 @@ dependencies = [
|
|
|
18
18
|
]
|
|
19
19
|
|
|
20
20
|
[project.optional-dependencies]
|
|
21
|
-
dev = ["pytest", "ruff"]
|
|
21
|
+
dev = ["pytest", "ruff", "pybamm-model-zoo"]
|
|
22
22
|
|
|
23
23
|
# Lets the PyBaMM model zoo list these models too, if the zoo is installed.
|
|
24
24
|
[project.entry-points."pybamm_zoo_models"]
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Monthly health report for PyBaMM-GEM (simple Python).
|
|
2
|
+
#
|
|
3
|
+
# It starts with the models from gem.list_models(). Then, for every GEM model, it checks:
|
|
4
|
+
# 1. the PyBaMM model zoo finds it and its contract checks pass,
|
|
5
|
+
# 2. it solves a 1C discharge, and how long that takes,
|
|
6
|
+
# 3. how far its voltage is from the matching stock PyBaMM model.
|
|
7
|
+
# It writes the result as Markdown to the file named on the command line (default report.md).
|
|
8
|
+
#
|
|
9
|
+
# How to use it:
|
|
10
|
+
# python scripts/health_report.py report.md
|
|
11
|
+
|
|
12
|
+
import sys
|
|
13
|
+
import time
|
|
14
|
+
import warnings
|
|
15
|
+
|
|
16
|
+
import numpy as np
|
|
17
|
+
import pybamm
|
|
18
|
+
import pybamm_model_zoo as zoo
|
|
19
|
+
from pybamm_model_zoo.testing import contract
|
|
20
|
+
|
|
21
|
+
import pybamm_gem as gem
|
|
22
|
+
|
|
23
|
+
OUTPUT = "report.md"
|
|
24
|
+
if len(sys.argv) > 1:
|
|
25
|
+
OUTPUT = sys.argv[1]
|
|
26
|
+
|
|
27
|
+
END_TIME = 3000 # seconds of a 1C discharge
|
|
28
|
+
POINTS = 3 # cells in each extra direction, kept small so the report runs quickly
|
|
29
|
+
TOLERANCE = 1e-3 # volts, the same as the model tests
|
|
30
|
+
|
|
31
|
+
warnings.simplefilter("ignore")
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def stock_model(slug):
|
|
35
|
+
if slug.startswith("spm"):
|
|
36
|
+
return pybamm.lithium_ion.SPM()
|
|
37
|
+
return pybamm.lithium_ion.DFN()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def solve_gem_model(slug):
|
|
41
|
+
model_class = gem.load(slug)
|
|
42
|
+
if slug == "spm_3d":
|
|
43
|
+
model = model_class(points_y=POINTS, points_z=POINTS)
|
|
44
|
+
return pybamm.Simulation(model).solve([0, END_TIME])
|
|
45
|
+
if slug.startswith("spm"):
|
|
46
|
+
return pybamm.Simulation(model_class()).solve([0, END_TIME])
|
|
47
|
+
var_pts = dict(pybamm.lithium_ion.DFN().default_var_pts)
|
|
48
|
+
var_pts["z"] = POINTS
|
|
49
|
+
if slug == "dfn_3d":
|
|
50
|
+
var_pts["y"] = POINTS
|
|
51
|
+
return pybamm.Simulation(model_class(), var_pts=var_pts).solve([0, END_TIME])
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
lines = []
|
|
55
|
+
|
|
56
|
+
# The models, from gem.list_models() and each model's model.toml
|
|
57
|
+
lines.append("### Models in GEM")
|
|
58
|
+
lines.append("")
|
|
59
|
+
lines.append("`gem.list_models()` = `" + str(gem.list_models()) + "`")
|
|
60
|
+
lines.append("")
|
|
61
|
+
lines.append("| Model | Class | What it is |")
|
|
62
|
+
lines.append("|---|---|---|")
|
|
63
|
+
for slug in gem.list_models():
|
|
64
|
+
manifest = gem.info(slug)
|
|
65
|
+
lines.append("| `" + slug + "` | `" + manifest["name"] + "` | " + manifest["summary"] + " |")
|
|
66
|
+
lines.append("")
|
|
67
|
+
|
|
68
|
+
lines.append("### Health")
|
|
69
|
+
lines.append("")
|
|
70
|
+
lines.append("| | Version |")
|
|
71
|
+
lines.append("|---|---|")
|
|
72
|
+
lines.append("| PyBaMM-GEM | " + gem.__version__ + " |")
|
|
73
|
+
lines.append("| PyBaMM | " + pybamm.__version__ + " |")
|
|
74
|
+
lines.append("| pybamm-model-zoo | " + zoo.__version__ + " |")
|
|
75
|
+
lines.append("| Python | " + sys.version.split()[0] + " |")
|
|
76
|
+
lines.append("")
|
|
77
|
+
lines.append("| Model | Zoo checks | Solves | Solve time [s] | Voltage vs stock PyBaMM [mV] | Health |")
|
|
78
|
+
lines.append("|---|---|---|---|---|---|")
|
|
79
|
+
|
|
80
|
+
all_healthy = True
|
|
81
|
+
check_names = [check.name for check in contract.checks_in_scope(contract.MODEL)]
|
|
82
|
+
times = np.linspace(100, END_TIME - 100, 30)
|
|
83
|
+
|
|
84
|
+
for slug in gem.list_models():
|
|
85
|
+
class_name = gem.info(slug)["name"]
|
|
86
|
+
|
|
87
|
+
# 1. The zoo contract checks
|
|
88
|
+
failed_checks = []
|
|
89
|
+
if class_name not in zoo.list_models():
|
|
90
|
+
failed_checks.append("not found by the zoo")
|
|
91
|
+
else:
|
|
92
|
+
entry = zoo.info(class_name)
|
|
93
|
+
for name in check_names:
|
|
94
|
+
try:
|
|
95
|
+
contract.CHECKS[name].run(entry)
|
|
96
|
+
except Exception: # noqa: BLE001 (any failure is reported in the table)
|
|
97
|
+
failed_checks.append(name)
|
|
98
|
+
if failed_checks:
|
|
99
|
+
zoo_result = "failed: " + ", ".join(failed_checks)
|
|
100
|
+
else:
|
|
101
|
+
zoo_result = str(len(check_names)) + "/" + str(len(check_names)) + " pass"
|
|
102
|
+
|
|
103
|
+
# 2. and 3. Solve and compare with the stock model
|
|
104
|
+
solves = "yes"
|
|
105
|
+
solve_time = "-"
|
|
106
|
+
difference = "-"
|
|
107
|
+
healthy = len(failed_checks) == 0
|
|
108
|
+
try:
|
|
109
|
+
began = time.time()
|
|
110
|
+
solution = solve_gem_model(slug)
|
|
111
|
+
solve_time = str(round(time.time() - began, 1))
|
|
112
|
+
stock_solution = pybamm.Simulation(stock_model(slug)).solve([0, END_TIME])
|
|
113
|
+
largest = np.max(np.abs(solution["Voltage [V]"](times) - stock_solution["Voltage [V]"](times)))
|
|
114
|
+
difference = str(round(1000 * largest, 3))
|
|
115
|
+
if largest > TOLERANCE:
|
|
116
|
+
healthy = False
|
|
117
|
+
except Exception as error: # noqa: BLE001 (any failure is reported in the table)
|
|
118
|
+
solves = "no (" + type(error).__name__ + ")"
|
|
119
|
+
healthy = False
|
|
120
|
+
|
|
121
|
+
if not healthy:
|
|
122
|
+
all_healthy = False
|
|
123
|
+
health = "OK" if healthy else "PROBLEM"
|
|
124
|
+
lines.append("| " + slug + " (" + class_name + ") | " + zoo_result + " | " + solves + " | "
|
|
125
|
+
+ solve_time + " | " + difference + " | " + health + " |")
|
|
126
|
+
|
|
127
|
+
lines.append("")
|
|
128
|
+
if all_healthy:
|
|
129
|
+
lines.append("**All models healthy.**")
|
|
130
|
+
else:
|
|
131
|
+
lines.append("**At least one model has a problem; see the table.**")
|
|
132
|
+
|
|
133
|
+
with open(OUTPUT, "w", encoding="utf-8") as file:
|
|
134
|
+
file.write("\n".join(lines) + "\n")
|
|
135
|
+
print("\n".join(lines))
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
from importlib.metadata import version
|
|
4
4
|
|
|
5
5
|
from pybamm_gem import lithium_ion
|
|
6
|
-
from pybamm_gem._registry import info, list_models, load, register_citation
|
|
6
|
+
from pybamm_gem._registry import info, list_models, load, register_citation, require
|
|
7
7
|
|
|
8
8
|
__version__ = version("PyBaMM-GEM")
|
|
9
9
|
|
|
@@ -14,4 +14,5 @@ __all__ = [
|
|
|
14
14
|
"lithium_ion",
|
|
15
15
|
"load",
|
|
16
16
|
"register_citation",
|
|
17
|
+
"require",
|
|
17
18
|
]
|
|
@@ -26,26 +26,45 @@ def _manifests() -> dict:
|
|
|
26
26
|
return manifests
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
class ModelInfo(dict):
|
|
30
|
+
"""The manifest of one model. Read a field as ``info["title"]`` or ``info.title``."""
|
|
31
|
+
|
|
32
|
+
def __getattr__(self, field):
|
|
33
|
+
if field in self:
|
|
34
|
+
return self[field]
|
|
35
|
+
raise AttributeError(field)
|
|
36
|
+
|
|
37
|
+
|
|
29
38
|
def list_models() -> list[str]:
|
|
30
39
|
"""Return the slug of every model in the package."""
|
|
31
40
|
return sorted(_manifests())
|
|
32
41
|
|
|
33
42
|
|
|
34
|
-
def info(
|
|
35
|
-
"""Return the manifest of one model
|
|
43
|
+
def info(name: str) -> ModelInfo:
|
|
44
|
+
"""Return the manifest of one model, found by its slug ("spm_2d") or class name ("BasicSPM2D")."""
|
|
36
45
|
manifests = _manifests()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
for slug in manifests:
|
|
47
|
+
if name == slug or name == manifests[slug]["name"]:
|
|
48
|
+
return ModelInfo(manifests[slug])
|
|
49
|
+
raise KeyError(f"No model '{name}'. Available: {sorted(manifests)}")
|
|
40
50
|
|
|
41
51
|
|
|
42
|
-
def load(
|
|
43
|
-
"""Return the model class
|
|
44
|
-
module_path, class_name = info(
|
|
52
|
+
def load(name: str) -> type:
|
|
53
|
+
"""Return the model class, e.g. ``load("spm_2d")()`` or ``load("BasicSPM2D")()``."""
|
|
54
|
+
module_path, class_name = info(name)["class"].split(":")
|
|
45
55
|
module = importlib.import_module(module_path)
|
|
46
56
|
return getattr(module, class_name)
|
|
47
57
|
|
|
48
58
|
|
|
59
|
+
def require(name: str) -> None:
|
|
60
|
+
"""Check that a model exists (raises KeyError if not).
|
|
61
|
+
|
|
62
|
+
The same command as in the PyBaMM model zoo. GEM models need no optional
|
|
63
|
+
packages, so there is nothing else to check.
|
|
64
|
+
"""
|
|
65
|
+
info(name)
|
|
66
|
+
|
|
67
|
+
|
|
49
68
|
def _read_bibtex(path: Path) -> dict:
|
|
50
69
|
# Split a BibTeX file into {key: entry text} by matching braces.
|
|
51
70
|
text = path.read_text(encoding="utf-8")
|
|
@@ -69,9 +88,9 @@ def _read_bibtex(path: Path) -> dict:
|
|
|
69
88
|
return entries
|
|
70
89
|
|
|
71
90
|
|
|
72
|
-
def register_citation(
|
|
91
|
+
def register_citation(name: str) -> None:
|
|
73
92
|
"""Make ``pybamm.print_citations()`` credit the model's key from its ``CITATION.bib``."""
|
|
74
|
-
manifest = info(
|
|
93
|
+
manifest = info(name)
|
|
75
94
|
entries = _read_bibtex(manifest["path"] / "CITATION.bib")
|
|
76
95
|
key = manifest["citation"]["key"]
|
|
77
96
|
pybamm.citations.register(entries[key])
|
|
@@ -35,3 +35,38 @@ def test_every_model_folder_has_the_zoo_files():
|
|
|
35
35
|
assert (folder / name).is_file(), f"{slug}: missing {name}"
|
|
36
36
|
assert any((folder / "tests").glob("*.py")), f"{slug}: no tests"
|
|
37
37
|
assert any((folder / "examples").glob("*.py")), f"{slug}: no examples"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# The same commands as the PyBaMM model zoo (pybamm_model_zoo)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def test_load_by_slug_or_class_name_gives_the_same_class():
|
|
44
|
+
for slug in gem.list_models():
|
|
45
|
+
class_name = gem.info(slug)["name"]
|
|
46
|
+
assert gem.load(class_name) is gem.load(slug)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_info_by_class_name():
|
|
50
|
+
assert gem.info("BasicSPM2D")["slug"] == "spm_2d"
|
|
51
|
+
assert gem.info("DFN3D")["slug"] == "dfn_3d"
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_info_fields_as_attributes_or_items():
|
|
55
|
+
manifest = gem.info("spm_2d")
|
|
56
|
+
assert manifest.title == manifest["title"]
|
|
57
|
+
assert manifest.license == "BSD-3-Clause"
|
|
58
|
+
with pytest.raises(AttributeError):
|
|
59
|
+
print(manifest.no_such_field)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_require():
|
|
63
|
+
for slug in gem.list_models():
|
|
64
|
+
gem.require(slug)
|
|
65
|
+
gem.require("BasicSPM3D")
|
|
66
|
+
with pytest.raises(KeyError):
|
|
67
|
+
gem.require("no_such_model")
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def test_register_citation_by_slug_or_class_name():
|
|
71
|
+
gem.register_citation("spm_2d")
|
|
72
|
+
gem.register_citation("DFN2D")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""The PyBaMM model zoo's own checks (pybamm_model_zoo.testing.contract) on every GEM model.
|
|
2
|
+
|
|
3
|
+
These are the portable checks the zoo applies to models from other packages: manifest,
|
|
4
|
+
layout, import, citation, well_posed, build and solve. Skipped if pybamm-model-zoo is
|
|
5
|
+
not installed.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
pytest.importorskip("pybamm_model_zoo")
|
|
11
|
+
|
|
12
|
+
import pybamm_model_zoo as zoo
|
|
13
|
+
from pybamm_model_zoo.testing import contract
|
|
14
|
+
|
|
15
|
+
import pybamm_gem as gem
|
|
16
|
+
|
|
17
|
+
CHECK_NAMES = [check.name for check in contract.checks_in_scope(contract.MODEL)]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def test_the_zoo_finds_every_gem_model():
|
|
21
|
+
for slug in gem.list_models():
|
|
22
|
+
class_name = gem.info(slug)["name"]
|
|
23
|
+
assert class_name in zoo.list_models()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize("slug", gem.list_models())
|
|
27
|
+
@pytest.mark.parametrize("check_name", CHECK_NAMES)
|
|
28
|
+
def test_zoo_contract(slug, check_name):
|
|
29
|
+
entry = zoo.info(gem.info(slug)["name"])
|
|
30
|
+
contract.CHECKS[check_name].run(entry)
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# Runs the tests on every push and pull request, and every Monday, against the latest
|
|
2
|
-
# PyBaMM release. A failing scheduled run opens ONE issue (or adds a comment to the open
|
|
3
|
-
# one). It never changes any code.
|
|
4
|
-
name: CI
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
push:
|
|
8
|
-
pull_request:
|
|
9
|
-
schedule:
|
|
10
|
-
- cron: "17 6 * * 1"
|
|
11
|
-
workflow_dispatch:
|
|
12
|
-
|
|
13
|
-
permissions:
|
|
14
|
-
contents: read
|
|
15
|
-
issues: write
|
|
16
|
-
|
|
17
|
-
jobs:
|
|
18
|
-
release:
|
|
19
|
-
name: PyBaMM release
|
|
20
|
-
runs-on: ubuntu-latest
|
|
21
|
-
steps:
|
|
22
|
-
- uses: actions/checkout@v4
|
|
23
|
-
- uses: actions/setup-python@v5
|
|
24
|
-
with:
|
|
25
|
-
python-version: "3.12"
|
|
26
|
-
- name: Install
|
|
27
|
-
run: |
|
|
28
|
-
pip install --upgrade pip
|
|
29
|
-
pip install -e ".[dev]"
|
|
30
|
-
- name: Lint
|
|
31
|
-
run: ruff check src tests
|
|
32
|
-
- name: Test
|
|
33
|
-
run: pytest
|
|
34
|
-
|
|
35
|
-
report:
|
|
36
|
-
name: Report a failure
|
|
37
|
-
needs: [release]
|
|
38
|
-
if: ${{ always() && github.event_name == 'schedule' && needs.release.result == 'failure' }}
|
|
39
|
-
runs-on: ubuntu-latest
|
|
40
|
-
steps:
|
|
41
|
-
- name: Open an issue, or comment on the open one
|
|
42
|
-
env:
|
|
43
|
-
GH_TOKEN: ${{ github.token }}
|
|
44
|
-
REPO: ${{ github.repository }}
|
|
45
|
-
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
|
|
46
|
-
run: |
|
|
47
|
-
TITLE="Weekly check failed"
|
|
48
|
-
NUMBER=$(gh issue list --repo "$REPO" --state open --search "$TITLE in:title" --json number --jq '.[0].number')
|
|
49
|
-
if [ -z "$NUMBER" ]; then
|
|
50
|
-
gh issue create --repo "$REPO" --title "$TITLE" --body "The weekly check failed. See $RUN_URL"
|
|
51
|
-
else
|
|
52
|
-
gh issue comment "$NUMBER" --repo "$REPO" --body "Failed again. See $RUN_URL"
|
|
53
|
-
fi
|
pybamm_gem-0.2.0/CHANGELOG.md
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 0.2.0
|
|
4
|
-
|
|
5
|
-
- Rebuilt in the PyBaMM model-zoo layout: one folder per model, each with a `model.toml`
|
|
6
|
-
manifest, `CITATION.bib`, `README.md`, tests and an example.
|
|
7
|
-
- Models: `spm_2d` (`BasicSPM2D`), `spm_3d` (`BasicSPM3D`), `dfn_2d` (`DFN2D`) and `dfn_3d` (`DFN3D`).
|
|
8
|
-
- Registry: `pybamm_gem.list_models()`, `pybamm_gem.info()` and `pybamm_gem.load()`.
|
|
9
|
-
- Example notebook: `examples/higher_dimensional_models.ipynb`.
|
|
10
|
-
- Needs PyBaMM 26.9 or newer.
|
|
11
|
-
- The previous code is kept on the branch `legacy-2026-11`.
|
pybamm_gem-0.2.0/PKG-INFO
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: PyBaMM-GEM
|
|
3
|
-
Version: 0.2.0
|
|
4
|
-
Summary: Spatially resolved (2D and 3D) battery models for PyBaMM
|
|
5
|
-
Author: Mohammed Asheruddin N
|
|
6
|
-
License-Expression: BSD-3-Clause
|
|
7
|
-
License-File: LICENSE.txt
|
|
8
|
-
License-File: LICENSES-bundled.txt
|
|
9
|
-
Keywords: battery,electrochemistry,lithium-ion,modelling,pybamm,simulation
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Requires-Dist: pybamm[cite]>=26.9
|
|
12
|
-
Requires-Dist: tomli>=2.0.1; python_version < '3.11'
|
|
13
|
-
Provides-Extra: dev
|
|
14
|
-
Requires-Dist: pytest; extra == 'dev'
|
|
15
|
-
Requires-Dist: ruff; extra == 'dev'
|
|
16
|
-
Description-Content-Type: text/markdown
|
|
17
|
-
|
|
18
|
-
# PyBaMM-GEM
|
|
19
|
-
|
|
20
|
-
Spatially resolved (2D and 3D) battery models built on [PyBaMM](https://pybamm.org), laid out
|
|
21
|
-
like the PyBaMM model zoo: one folder per model, each with a `model.toml` manifest, a
|
|
22
|
-
`CITATION.bib`, a README, tests and an example.
|
|
23
|
-
|
|
24
|
-
## Models
|
|
25
|
-
|
|
26
|
-
| Slug | Class | What it is |
|
|
27
|
-
|---|---|---|
|
|
28
|
-
| `spm_2d` | `BasicSPM2D` | Single Particle Model with a pair of particles at every height z |
|
|
29
|
-
| `spm_3d` | `BasicSPM3D` | The same, over a y-z grid of points |
|
|
30
|
-
| `dfn_2d` | `DFN2D` | Doyle-Fuller-Newman model resolved in x and z |
|
|
31
|
-
| `dfn_3d` | `DFN3D` | The same, resolved in x, y and z |
|
|
32
|
-
|
|
33
|
-
## Installation
|
|
34
|
-
|
|
35
|
-
```
|
|
36
|
-
pip install git+https://github.com/ImperialCollegeLondon/PyBaMM-GEM
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
PyBaMM 26.9 or newer is needed.
|
|
40
|
-
|
|
41
|
-
## Usage
|
|
42
|
-
|
|
43
|
-
```python
|
|
44
|
-
import pybamm
|
|
45
|
-
import pybamm_gem as gem
|
|
46
|
-
|
|
47
|
-
print(gem.list_models())
|
|
48
|
-
model = gem.load("spm_2d")()
|
|
49
|
-
simulation = pybamm.Simulation(model)
|
|
50
|
-
solution = simulation.solve([0, 3000])
|
|
51
|
-
print(solution["Voltage [V]"](1500))
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
|
|
55
|
-
`gem.lithium_ion.DFN2D`.
|
|
56
|
-
|
|
57
|
-
The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
|
|
58
|
-
the stock PyBaMM models and shows a temperature that changes with height.
|
|
59
|
-
|
|
60
|
-
## Licence
|
|
61
|
-
|
|
62
|
-
BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
|
|
63
|
-
Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
|
pybamm_gem-0.2.0/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# PyBaMM-GEM
|
|
2
|
-
|
|
3
|
-
Spatially resolved (2D and 3D) battery models built on [PyBaMM](https://pybamm.org), laid out
|
|
4
|
-
like the PyBaMM model zoo: one folder per model, each with a `model.toml` manifest, a
|
|
5
|
-
`CITATION.bib`, a README, tests and an example.
|
|
6
|
-
|
|
7
|
-
## Models
|
|
8
|
-
|
|
9
|
-
| Slug | Class | What it is |
|
|
10
|
-
|---|---|---|
|
|
11
|
-
| `spm_2d` | `BasicSPM2D` | Single Particle Model with a pair of particles at every height z |
|
|
12
|
-
| `spm_3d` | `BasicSPM3D` | The same, over a y-z grid of points |
|
|
13
|
-
| `dfn_2d` | `DFN2D` | Doyle-Fuller-Newman model resolved in x and z |
|
|
14
|
-
| `dfn_3d` | `DFN3D` | The same, resolved in x, y and z |
|
|
15
|
-
|
|
16
|
-
## Installation
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
pip install git+https://github.com/ImperialCollegeLondon/PyBaMM-GEM
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
PyBaMM 26.9 or newer is needed.
|
|
23
|
-
|
|
24
|
-
## Usage
|
|
25
|
-
|
|
26
|
-
```python
|
|
27
|
-
import pybamm
|
|
28
|
-
import pybamm_gem as gem
|
|
29
|
-
|
|
30
|
-
print(gem.list_models())
|
|
31
|
-
model = gem.load("spm_2d")()
|
|
32
|
-
simulation = pybamm.Simulation(model)
|
|
33
|
-
solution = simulation.solve([0, 3000])
|
|
34
|
-
print(solution["Voltage [V]"](1500))
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
|
|
38
|
-
`gem.lithium_ion.DFN2D`.
|
|
39
|
-
|
|
40
|
-
The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
|
|
41
|
-
the stock PyBaMM models and shows a temperature that changes with height.
|
|
42
|
-
|
|
43
|
-
## Licence
|
|
44
|
-
|
|
45
|
-
BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
|
|
46
|
-
Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|