PyBaMM-GEM 0.2.0__tar.gz → 0.2.1__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.
Files changed (42) hide show
  1. pybamm_gem-0.2.1/.github/workflows/release.yml +103 -0
  2. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/CHANGELOG.md +7 -0
  3. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/PKG-INFO +16 -1
  4. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/README.md +15 -0
  5. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/pyproject.toml +1 -1
  6. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/__init__.py +2 -1
  7. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/_registry.py +29 -10
  8. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/tests/test_registry.py +35 -0
  9. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/.github/workflows/ci.yml +0 -0
  10. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/.gitignore +0 -0
  11. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/LICENSE.txt +0 -0
  12. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/LICENSES-bundled.txt +0 -0
  13. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/examples/higher_dimensional_models.ipynb +0 -0
  14. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/CITATION.bib +0 -0
  15. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/README.md +0 -0
  16. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/__init__.py +0 -0
  17. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/examples/run_dfn_2d.py +0 -0
  18. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/model.py +0 -0
  19. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/model.toml +0 -0
  20. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_2d/tests/test_dfn_2d.py +0 -0
  21. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/CITATION.bib +0 -0
  22. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/README.md +0 -0
  23. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/__init__.py +0 -0
  24. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/examples/run_dfn_3d.py +0 -0
  25. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/model.py +0 -0
  26. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/model.toml +0 -0
  27. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/dfn_3d/tests/test_dfn_3d.py +0 -0
  28. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/lithium_ion/__init__.py +0 -0
  29. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/CITATION.bib +0 -0
  30. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/README.md +0 -0
  31. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/__init__.py +0 -0
  32. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/examples/run_spm_2d.py +0 -0
  33. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/model.py +0 -0
  34. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/model.toml +0 -0
  35. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_2d/tests/test_spm_2d.py +0 -0
  36. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/CITATION.bib +0 -0
  37. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/README.md +0 -0
  38. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/__init__.py +0 -0
  39. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/examples/run_spm_3d.py +0 -0
  40. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/model.py +0 -0
  41. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/model.toml +0 -0
  42. {pybamm_gem-0.2.0 → pybamm_gem-0.2.1}/src/pybamm_gem/spm_3d/tests/test_spm_3d.py +0 -0
@@ -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 a few minutes to appear on TestPyPI
80
+ for attempt in 1 2 3 4 5 6 7 8 9 10; do
81
+ if pip install --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
@@ -1,5 +1,12 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.1
4
+
5
+ - `pybamm_gem` now has the same commands as the PyBaMM model zoo: `require()` is new, and
6
+ `info()`, `load()`, `require()` and `register_citation()` accept the class name (for example
7
+ `"BasicSPM2D"`) as well as the slug (`"spm_2d"`).
8
+ - `info()` fields can be read as `info.title` as well as `info["title"]`.
9
+
3
10
  ## 0.2.0
4
11
 
5
12
  - Rebuilt in the PyBaMM model-zoo layout: one folder per model, each with a `model.toml`
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: PyBaMM-GEM
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Spatially resolved (2D and 3D) battery models for PyBaMM
5
5
  Author: Mohammed Asheruddin N
6
6
  License-Expression: BSD-3-Clause
@@ -54,6 +54,12 @@ print(solution["Voltage [V]"](1500))
54
54
  The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
55
55
  `gem.lithium_ion.DFN2D`.
56
56
 
57
+ The commands are the same as in the PyBaMM model zoo (`pybamm_model_zoo`): `list_models()`,
58
+ `info()`, `load()`, `require()` and `register_citation()`. `info()`, `load()`, `require()` and
59
+ `register_citation()` take either the slug (`"spm_2d"`) or the class name (`"BasicSPM2D"`);
60
+ `list_models()` returns the slugs. With `pybamm-model-zoo` installed, the GEM models are also
61
+ listed by `pybamm_model_zoo.list_models()`.
62
+
57
63
  The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
58
64
  the stock PyBaMM models and shows a temperature that changes with height.
59
65
 
@@ -61,3 +67,12 @@ the stock PyBaMM models and shows a temperature that changes with height.
61
67
 
62
68
  BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
63
69
  Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
70
+
71
+ ## Releasing a new version
72
+
73
+ 1. In a pull request, raise `version` in `pyproject.toml` (for example `0.2.1`) and add a
74
+ `CHANGELOG.md` entry. Merge it.
75
+ 2. On GitHub, go to Releases, then "Draft a new release". Create the tag `v0.2.1` (a "v" and
76
+ the version), add a title and notes, and publish.
77
+ 3. The Release workflow builds and tests the package, uploads it to TestPyPI and tests it again.
78
+ It then waits for a maintainer to approve the upload to PyPI (GitHub sends an email).
@@ -37,6 +37,12 @@ print(solution["Voltage [V]"](1500))
37
37
  The classes are also available directly, for example `gem.lithium_ion.BasicSPM2D` or
38
38
  `gem.lithium_ion.DFN2D`.
39
39
 
40
+ The commands are the same as in the PyBaMM model zoo (`pybamm_model_zoo`): `list_models()`,
41
+ `info()`, `load()`, `require()` and `register_citation()`. `info()`, `load()`, `require()` and
42
+ `register_citation()` take either the slug (`"spm_2d"`) or the class name (`"BasicSPM2D"`);
43
+ `list_models()` returns the slugs. With `pybamm-model-zoo` installed, the GEM models are also
44
+ listed by `pybamm_model_zoo.list_models()`.
45
+
40
46
  The notebook `examples/higher_dimensional_models.ipynb` runs all four models, compares them with
41
47
  the stock PyBaMM models and shows a temperature that changes with height.
42
48
 
@@ -44,3 +50,12 @@ the stock PyBaMM models and shows a temperature that changes with height.
44
50
 
45
51
  BSD 3-Clause, see `LICENSE.txt`. Copyright (c) 2026, Imperial College London.
46
52
  Some of the model code is adapted from PyBaMM; see `LICENSES-bundled.txt`.
53
+
54
+ ## Releasing a new version
55
+
56
+ 1. In a pull request, raise `version` in `pyproject.toml` (for example `0.2.1`) and add a
57
+ `CHANGELOG.md` entry. Merge it.
58
+ 2. On GitHub, go to Releases, then "Draft a new release". Create the tag `v0.2.1` (a "v" and
59
+ the version), add a title and notes, and publish.
60
+ 3. The Release workflow builds and tests the package, uploads it to TestPyPI and tests it again.
61
+ It then waits for a maintainer to approve the upload to PyPI (GitHub sends an email).
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "PyBaMM-GEM"
7
- version = "0.2.0"
7
+ version = "0.2.1"
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"
@@ -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(slug: str) -> dict:
35
- """Return the manifest of one model as a dictionary."""
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
- if slug not in manifests:
38
- raise KeyError(f"No model '{slug}'. Available: {sorted(manifests)}")
39
- return manifests[slug]
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(slug: str) -> type:
43
- """Return the model class for a slug. Call it to get a model, e.g. ``load("spm_2d")()``."""
44
- module_path, class_name = info(slug)["class"].split(":")
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(slug: str) -> None:
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(slug)
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")
File without changes
File without changes