Skip to content

Commit

Permalink
Merge branch 'develop' into Saswatsusmoy-#3441-Call-processed-variabl…
Browse files Browse the repository at this point in the history
…es-with-custom-spatial-coordinates
  • Loading branch information
arjxn-py authored Feb 7, 2024
2 parents aa338d9 + 84bfd61 commit 22caa58
Show file tree
Hide file tree
Showing 15 changed files with 148 additions and 25 deletions.
7 changes: 5 additions & 2 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@
"profile": "https://github.com/jonchapman1",
"contributions": [
"ideas",
"fundingFinding"
"fundingFinding",
"doc"
]
},
{
Expand Down Expand Up @@ -772,7 +773,9 @@
"avatar_url": "https://avatars.githubusercontent.com/u/99216956?v=4",
"profile": "https://github.com/prady0t",
"contributions": [
"infra"
"infra",
"code",
"test"
]
},
{
Expand Down
44 changes: 39 additions & 5 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ jobs:
CIBW_REPAIR_WHEEL_COMMAND_LINUX: auditwheel repair -w {dest_dir} {wheel}
CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()"

- name: Build wheels on macOS
- name: Build wheels on macOS amd64
if: matrix.os == 'macos-latest'
run: pipx run cibuildwheel --output-dir wheelhouse
env:
Expand All @@ -150,11 +150,45 @@ jobs:
path: ./wheelhouse/*.whl
if-no-files-found: error

- name: Upload wheels for macOS
- name: Upload wheels for macOS amd64
uses: actions/upload-artifact@v4
if: matrix.os == 'macos-latest'
with:
name: macos_wheels
name: macos_amd64_wheels
path: ./wheelhouse/*.whl
if-no-files-found: error

build_macos_arm64_wheels:
name: Wheels (macos-arm64)
# Current runner is macOS X 14+ on GitHub-hosted runners
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Clone pybind11 repo (no history)
run: git clone --depth 1 --branch v2.11.1 https://github.com/pybind/pybind11.git

- name: Install SuiteSparse and SUNDIALS on macOS
run: |
brew install graphviz openblas libomp
brew reinstall gcc
python -m pip install cmake pipx
python scripts/install_KLU_Sundials.py
- name: Build wheels on macOS arm64
run: python -m pipx run cibuildwheel --output-dir wheelhouse
env:
CIBW_BEFORE_BUILD: python -m pip install cmake casadi setuptools wheel delocate
CIBW_REPAIR_WHEEL_COMMAND: delocate-listdeps {wheel} && delocate-wheel -v -w {dest_dir} {wheel}
CIBW_TEST_COMMAND: python -c "import pybamm; pybamm.IDAKLUSolver()"

- name: Upload wheels for macOS arm64
uses: actions/upload-artifact@v4
with:
name: macos_arm64_wheels
path: ./wheelhouse/*.whl
if-no-files-found: error

Expand Down Expand Up @@ -182,7 +216,7 @@ jobs:
# This job is only of value to PyBaMM and would always be skipped in forks
if: github.event_name != 'schedule' && github.repository == 'pybamm-team/PyBaMM'
name: Upload package to PyPI
needs: [build_macos_and_linux_wheels, build_windows_wheels, build_sdist]
needs: [build_macos_and_linux_wheels, build_macos_arm64_wheels, build_windows_wheels, build_sdist]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
Expand All @@ -191,7 +225,7 @@ jobs:
- name: Move all package files to files/
run: |
mkdir files
mv windows_wheels/* linux_wheels/* macos_wheels/* sdist/* files/
mv windows_wheels/* linux_wheels/* macos_amd64_wheels/* macos_arm64_wheels/* sdist/* files/
- name: Publish on PyPI
if: github.event.inputs.target == 'pypi' || github.event_name == 'release'
Expand Down
52 changes: 43 additions & 9 deletions .github/workflows/run_periodic_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,21 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# Include macOS M1 runners
include:
- os: macos-14
python-version: "3.10"
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"

steps:
- uses: actions/checkout@v4
- name: Check out PyBaMM repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
Expand Down Expand Up @@ -89,7 +101,9 @@ jobs:

- name: Upload coverage report
if: matrix.os == 'ubuntu-latest' && matrix.python-version == 3.11
uses: codecov/[email protected]
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: Run integration tests
run: python -m nox -s integration
Expand All @@ -110,42 +124,54 @@ jobs:
if: matrix.os == 'ubuntu-latest'
run: python -m nox -s scripts

#M-series Mac Mini
# M-series Mac Mini
build-apple-mseries:
if: github.repository_owner == 'pybamm-team'
needs: style
runs-on: [self-hosted, macOS, ARM64]
env:
GITHUB_PATH: ${PYENV_ROOT/bin:$PATH}
LD_LIBRARY_PATH: $HOME/.local/lib
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4
- name: Install python & create virtualenv
- name: Install Python & create virtualenv
shell: bash
run: |
eval "$(pyenv init -)"
pyenv install ${{ matrix.python-version }} -s
pyenv virtualenv ${{ matrix.python-version }} pybamm-${{ matrix.python-version }}
- name: Install dependencies & run unit tests for Windows and MacOS
- name: Install build-time dependencies & run unit tests for M-series macOS runner
shell: bash
env:
# Point scikits.odes to the correct SUNDIALS installation
SUNDIALS_INST: $HOME/.local/lib
# Homebrew environment variables
HOMEBREW_NO_INSTALL_CLEANUP: 1
NONINTERACTIVE: 1
run: |
eval "$(pyenv init -)"
pyenv activate pybamm-${{ matrix.python-version }}
python -m pip install --upgrade pip wheel setuptools nox
python -m pip install --upgrade pip nox
# Don't use Homebrew to install SUNDIALS because scikits.odes looks for
# in Homebrew folders instead, which we don't want
brew uninstall sundials --force
pip cache remove scikits.odes
python -m nox -s pybamm-requires -- --force
python -m nox -s unit
- name: Run integration tests for Windows and MacOS
- name: Run integration tests for M-series macOS runner
run: |
eval "$(pyenv init -)"
pyenv activate pybamm-${{ matrix.python-version }}
python -m nox -s integration
- name: Uninstall pyenv-virtualenv & python
- name: Uninstall pyenv-virtualenv & Python
if: always()
shell: bash
run: |
Expand All @@ -159,8 +185,16 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
# Include macOS M1 runners
include:
- os: macos-14
python-version: "3.10"
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"
fail-fast: false
name: Test pybamm_install_odes on ${{ matrix.os }}
name: Test pybamm_install_odes (${{ matrix.os }} / Python ${{ matrix.python-version }})

steps:
- name: Check out PyBaMM repository
Expand Down
24 changes: 21 additions & 3 deletions .github/workflows/test_on_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ jobs:
exclude:
- os: ubuntu-latest
python-version: "3.11"
# Include macOS M1 runners
include:
- os: macos-14
python-version: "3.10"
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"
name: Unit tests (${{ matrix.os }} / Python ${{ matrix.python-version }})

steps:
Expand All @@ -66,7 +74,7 @@ jobs:
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
- name: Install macOS system dependencies
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
env:
# Homebrew environment variables
HOMEBREW_NO_INSTALL_CLEANUP: 1
Expand Down Expand Up @@ -170,7 +178,9 @@ jobs:
run: python -m nox -s coverage

- name: Upload coverage report
uses: codecov/[email protected]
uses: codecov/[email protected]
with:
token: ${{ secrets.CODECOV_TOKEN }}

run_integration_tests:
needs: style
Expand All @@ -180,6 +190,14 @@ jobs:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
# Include macOS M1 runners
include:
- os: macos-14
python-version: "3.10"
- os: macos-14
python-version: "3.11"
- os: macos-14
python-version: "3.12"
name: Integration tests (${{ matrix.os }} / Python ${{ matrix.python-version }})

steps:
Expand All @@ -203,7 +221,7 @@ jobs:
sudo apt-get install libopenblas-dev texlive-latex-extra dvipng
- name: Install macOS system dependencies
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-latest' || matrix.os == 'macos-14'
env:
# Homebrew environment variables
HOMEBREW_NO_INSTALL_CLEANUP: 1
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
# create a pull request updating versions in develop
- name: Create Pull Request
id: version_pr
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
delete-branch: true
branch-suffix: short-commit-hash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/work_precision_sets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
python benchmarks/work_precision_sets/time_vs_reltols.py
python benchmarks/work_precision_sets/time_vs_abstols.py
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v6
with:
delete-branch: true
branch-suffix: short-commit-hash
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.1.14"
rev: "v0.2.0"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- Added support for macOS arm64 (M-series) platforms. ([#3789](https://github.com/pybamm-team/PyBaMM/pull/3789))
- Renamed "electrode diffusivity" to "particle diffusivity" as a non-breaking change with a deprecation warning ([#3624](https://github.com/pybamm-team/PyBaMM/pull/3624))
- Add support for BPX version 0.4.0 which allows for blended electrodes and user-defined parameters in BPX([#3414](https://github.com/pybamm-team/PyBaMM/pull/3414))
- Added the ability to specify a custom solver tolerance in `get_initial_stoichiometries` and related functions ([#3714](https://github.com/pybamm-team/PyBaMM/pull/3714))
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://www.rse.ox.ac.uk/"><img src="https://avatars3.githubusercontent.com/u/3770306?v=4?s=100" width="100px;" alt="Fergus Cooper"/><br /><sub><b>Fergus Cooper</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=fcooper8472" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=fcooper8472" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jonchapman1"><img src="https://avatars1.githubusercontent.com/u/28925818?v=4?s=100" width="100px;" alt="jonchapman1"/><br /><sub><b>jonchapman1</b></sub></a><br /><a href="#ideas-jonchapman1" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-jonchapman1" title="Funding Finding">🔍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jonchapman1"><img src="https://avatars1.githubusercontent.com/u/28925818?v=4?s=100" width="100px;" alt="jonchapman1"/><br /><sub><b>jonchapman1</b></sub></a><br /><a href="#ideas-jonchapman1" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-jonchapman1" title="Funding Finding">🔍</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=jonchapman1" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/colinplease"><img src="https://avatars3.githubusercontent.com/u/44977104?v=4?s=100" width="100px;" alt="Colin Please"/><br /><sub><b>Colin Please</b></sub></a><br /><a href="#ideas-colinplease" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-colinplease" title="Funding Finding">🔍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/cwmonroe"><img src="https://avatars.githubusercontent.com/u/92099819?v=4?s=100" width="100px;" alt="cwmonroe"/><br /><sub><b>cwmonroe</b></sub></a><br /><a href="#ideas-cwmonroe" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-cwmonroe" title="Funding Finding">🔍</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/gjo97"><img src="https://avatars.githubusercontent.com/u/18349157?v=4?s=100" width="100px;" alt="Greg"/><br /><sub><b>Greg</b></sub></a><br /><a href="#ideas-gjo97" title="Ideas, Planning, & Feedback">🤔</a> <a href="#fundingFinding-gjo97" title="Funding Finding">🔍</a></td>
Expand Down Expand Up @@ -276,7 +276,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/jlauber18"><img src="https://avatars.githubusercontent.com/u/28939653?v=4?s=100" width="100px;" alt="Jonathan Lauber"/><br /><sub><b>Jonathan Lauber</b></sub></a><br /><a href="#infra-jlauber18" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
</tr>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/prady0t"><img src="https://avatars.githubusercontent.com/u/99216956?v=4?s=100" width="100px;" alt="Pradyot Ranjan"/><br /><sub><b>Pradyot Ranjan</b></sub></a><br /><a href="#infra-prady0t" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/prady0t"><img src="https://avatars.githubusercontent.com/u/99216956?v=4?s=100" width="100px;" alt="Pradyot Ranjan"/><br /><sub><b>Pradyot Ranjan</b></sub></a><br /><a href="#infra-prady0t" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=prady0t" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=prady0t" title="Tests">⚠️</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/XuboGU"><img src="https://avatars.githubusercontent.com/u/53944452?v=4?s=100" width="100px;" alt="XuboGU"/><br /><sub><b>XuboGU</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=XuboGU" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3AXuboGU" title="Bug reports">🐛</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/cringeyburger"><img src="https://avatars.githubusercontent.com/u/121183876?v=4?s=100" width="100px;" alt="Ankit Meda"/><br /><sub><b>Ankit Meda</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=cringeyburger" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/AlessioBugetti"><img src="https://avatars.githubusercontent.com/u/38499721?v=4?s=100" width="100px;" alt="Alessio Bugetti"/><br /><sub><b>Alessio Bugetti</b></sub></a><br /><a href="#infra-AlessioBugetti" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AlessioBugetti" title="Code">💻</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AlessioBugetti" title="Documentation">📖</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=AlessioBugetti" title="Tests">⚠️</a></td>
Expand Down
3 changes: 2 additions & 1 deletion pybamm/batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ def create_gif(self, number_of_images=80, duration=0.1, output_filename="plot.gi
Name of the generated GIF file.
"""

if not hasattr(self, "sims"):
raise ValueError("The simulations have not been solved yet.")
if self.quick_plot is None:
self.quick_plot = pybamm.QuickPlot(self.sims)

Expand Down
15 changes: 15 additions & 0 deletions pybamm/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ def __repr__(self):
def read_termination(termination):
"""
Read the termination reason. If this condition is hit, the experiment will stop.
Parameters
----------
termination : str or list[str], optional
A single string, or a list of strings, representing the conditions to terminate the experiment.
Only capacity or voltage can be provided as a termination reason.
e.g. '4 Ah capacity' or ['80% capacity', '2.5 V']
Returns
-------
dict
A dictionary of the termination conditions.
e.g. {'capacity': (4.0, 'Ah')} or
{'capacity': (80.0, '%'), 'voltage': (2.5, 'V')}
"""
if termination is None:
return {}
Expand Down
5 changes: 5 additions & 0 deletions pybamm/install_odes.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ def main(arguments=None):
os.environ["SUNDIALS_INST"] = SUNDIALS_LIB_DIR
env = os.environ.copy()
logger.info("Installing scikits.odes via pip")
logger.info("Purging scikits.odes whels from pip cache if present")
subprocess.run(
[f"{sys.executable}", "-m", "pip", "cache", "remove", "scikits.odes"],
check=True,
)
subprocess.run(
[f"{sys.executable}", "-m", "pip", "install", "scikits.odes", "--verbose"],
env=env,
Expand Down
2 changes: 2 additions & 0 deletions pybamm/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,8 @@ def create_gif(self, number_of_images=80, duration=0.1, output_filename="plot.gi
Name of the generated GIF file.
"""
if self.solution is None:
raise ValueError("The simulation has not been solved yet.")
if self.quick_plot is None:
self.quick_plot = pybamm.QuickPlot(self._solution)

Expand Down
6 changes: 6 additions & 0 deletions tests/unit/test_batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ def test_solve(self):
def test_create_gif(self):
with TemporaryDirectory() as dir_name:
bs = pybamm.BatchStudy({"spm": pybamm.lithium_ion.SPM()})
with self.assertRaisesRegex(
ValueError, "The simulations have not been solved yet."
):
pybamm.BatchStudy(
models={"SPM": spm, "SPM uniform": spm_uniform}
).create_gif()
bs.solve([0, 10])

# Create a temporary file name
Expand Down
4 changes: 4 additions & 0 deletions tests/unit/test_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ def test_plot(self):
def test_create_gif(self):
with TemporaryDirectory() as dir_name:
sim = pybamm.Simulation(pybamm.lithium_ion.SPM())
with self.assertRaisesRegex(
ValueError, "The simulation has not been solved yet."
):
sim.create_gif()
sim.solve(t_eval=[0, 10])

# Create a temporary file name
Expand Down

0 comments on commit 22caa58

Please sign in to comment.