Skip to content

Commit

Permalink
Merge branch 'develop' into install_odes
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Oct 11, 2023
2 parents 906683b + eb50d90 commit a36ec4f
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 198 deletions.
11 changes: 10 additions & 1 deletion .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@
"login": "wigging",
"name": "Gavin Wiggins",
"avatar_url": "https://avatars.githubusercontent.com/u/6828967?v=4",
"profile": "https://wigging.me",
"profile": "https://gavinw.me",
"contributions": [
"bug",
"code"
Expand Down Expand Up @@ -708,6 +708,15 @@
"contributions": [
"infra"
]
},
{
"login": "Agnik7",
"name": "Agnik Bakshi",
"avatar_url": "https://avatars.githubusercontent.com/u/77234005?v=4",
"profile": "https://github.com/Agnik7",
"contributions": [
"doc"
]
}
],
"contributorsPerLine": 7,
Expand Down
1 change: 1 addition & 0 deletions .github/release_reminder.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
title: Create {{ date | date('YY.MM') }} (final or rc0) release
labels: priority:high
---
Quarterly reminder to create a -

Expand Down
6 changes: 6 additions & 0 deletions .github/wheel_failure.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: Fortnightly build for wheels failed
labels: priority:high, bug
---

The build is failing with the following logs - {{ env.LOGS }}
75 changes: 75 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Build & Push Docker Images

on:
workflow_dispatch:
push:
branches:
- develop

jobs:
pre_job:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: List built images
run: docker images

- name: Build and Push Docker Image (Without Solvers)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:latest
push: true

- name: Build and Push Docker Image (With JAX Solver)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:jax
push: true
build-args: |
JAX=true
- name: Build and Push Docker Image (With ODES & DAE Solver)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:odes
push: true
build-args: |
ODES=true
- name: Build and Push Docker Image (With IDAKLU Solver)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:idaklu
push: true
build-args: |
IDAKLU=true
- name: Build and Push Docker Image (With All Solvers)
uses: docker/build-push-action@v5
with:
context: .
file: scripts/Dockerfile
tags: pybamm/pybamm:latest
push: true
build-args: |
ALL=true
22 changes: 19 additions & 3 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Build and publish package to PyPI
on:
release:
types: [published]
schedule:
# Run at 10 am UTC on day-of-month 1 and 15.
- cron: "0 10 1,15 * *"
workflow_dispatch:
inputs:
target:
Expand Down Expand Up @@ -151,6 +154,7 @@ jobs:
if-no-files-found: error

publish_pypi:
if: github.event_name != 'schedule'
name: Upload package to PyPI
needs: [build_wheels, build_windows_wheels, build_sdist]
runs-on: ubuntu-latest
Expand All @@ -164,9 +168,7 @@ jobs:
mv windows_wheels/* wheels/* sdist/* files/
- name: Publish on PyPI
if: |
github.event.inputs.target == 'pypi' ||
(github.event_name == 'push' && github.ref == 'refs/heads/main')
if: github.event.inputs.target == 'pypi' || github.event_name == 'release'
uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
Expand All @@ -181,3 +183,17 @@ jobs:
password: ${{ secrets.TESTPYPI_TOKEN }}
packages-dir: files/
repository-url: https://test.pypi.org/legacy/

open_failure_issue:
needs: [build_windows_wheels, build_wheels, build_sdist]
name: Open an issue if build fails
if: ${{ always() && contains(needs.*.result, 'failure') }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: JasonEtco/create-an-issue@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
LOGS: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
with:
filename: .github/wheel_failure.md
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
additional_dependencies: [black==22.12.0]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-added-large-files
- id: check-case-conflict
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ You now have everything you need to start making changes!

### B. Writing your code

6. PyBaMM is developed in [Python](https://en.wikipedia.org/wiki/Python_(programming_language)), and makes heavy use of [NumPy](https://en.wikipedia.org/wiki/NumPy) (see also [NumPy for MatLab users](https://numpy.org/doc/stable/user/numpy-for-matlab-users.html) and [Python for R users](http://blog.hackerearth.com/how-can-r-users-learn-python-for-data-science)).
6. PyBaMM is developed in [Python](https://en.wikipedia.org/wiki/Python_(programming_language)), and makes heavy use of [NumPy](https://en.wikipedia.org/wiki/NumPy) (see also [NumPy for MatLab users](https://numpy.org/doc/stable/user/numpy-for-matlab-users.html) and [Python for R users](https://www.rebeccabarter.com/blog/2023-09-11-from_r_to_python)).
7. Make sure to follow our [coding style guidelines](#coding-style-guidelines).
8. Commit your changes to your branch with [useful, descriptive commit messages](https://chris.beams.io/posts/git-commit/): Remember these are publicly visible and should still make sense a few months ahead in time. While developing, you can keep using the GitHub issue you're working on as a place for discussion. [Refer to your commits](https://stackoverflow.com/questions/8910271/how-can-i-reference-a-commit-in-an-issue-comment-on-github) when discussing specific lines of code.
9. If you want to add a dependency on another library, or re-use code you found somewhere else, have a look at [these guidelines](#dependencies-and-reusing-code).
Expand Down Expand Up @@ -185,7 +185,7 @@ You may also test multiple notebooks this way. Passing the path to a folder will
nox -s examples -- docs/source/examples/notebooks/models/
```

You may also use an appropriate [glob pattern](https://www.malikbrowne.com/blog/a-beginners-guide-glob-patterns) to run all notebooks matching a particular folder or name pattern.
You may also use an appropriate [glob pattern](https://docs.python.org/3/library/glob.html) to run all notebooks matching a particular folder or name pattern.

To edit the structure and how the Jupyter notebooks get rendered in the Sphinx documentation (using `nbsphinx`), install [Pandoc](https://pandoc.org/installing.html) on your system, either using `conda` (through the `conda-forge` channel)

Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
[![code style](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-64-orange.svg)](#-contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-65-orange.svg)](#-contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

</div>
Expand Down Expand Up @@ -233,7 +233,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/chuckliu1979"><img src="https://avatars.githubusercontent.com/u/13491954?v=4?s=100" width="100px;" alt="Chuck Liu"/><br /><sub><b>Chuck Liu</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Achuckliu1979" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=chuckliu1979" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/partben"><img src="https://avatars.githubusercontent.com/u/88316576?v=4?s=100" width="100px;" alt="partben"/><br /><sub><b>partben</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=partben" title="Documentation">📖</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://wigging.me"><img src="https://avatars.githubusercontent.com/u/6828967?v=4?s=100" width="100px;" alt="Gavin Wiggins"/><br /><sub><b>Gavin Wiggins</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Awigging" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=wigging" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://gavinw.me"><img src="https://avatars.githubusercontent.com/u/6828967?v=4?s=100" width="100px;" alt="Gavin Wiggins"/><br /><sub><b>Gavin Wiggins</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Awigging" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=wigging" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/dion-w"><img src="https://avatars.githubusercontent.com/u/91852142?v=4?s=100" width="100px;" alt="Dion Wilde"/><br /><sub><b>Dion Wilde</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3Adion-w" title="Bug reports">🐛</a> <a href="https://github.com/pybamm-team/PyBaMM/commits?author=dion-w" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.ehtec.co"><img src="https://avatars.githubusercontent.com/u/48386220?v=4?s=100" width="100px;" alt="Elias Hohl"/><br /><sub><b>Elias Hohl</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=ehtec" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/KAschad"><img src="https://avatars.githubusercontent.com/u/93784399?v=4?s=100" width="100px;" alt="KAschad"/><br /><sub><b>KAschad</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/issues?q=author%3AKAschad" title="Bug reports">🐛</a></td>
Expand Down Expand Up @@ -268,6 +268,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://aitorres.com"><img src="https://avatars.githubusercontent.com/u/26191851?v=4?s=100" width="100px;" alt="Andrés Ignacio Torres"/><br /><sub><b>Andrés Ignacio Torres</b></sub></a><br /><a href="#infra-aitorres" title="Infrastructure (Hosting, Build-Tools, etc)">🚇</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Agnik7"><img src="https://avatars.githubusercontent.com/u/77234005?v=4?s=100" width="100px;" alt="Agnik Bakshi"/><br /><sub><b>Agnik Bakshi</b></sub></a><br /><a href="https://github.com/pybamm-team/PyBaMM/commits?author=Agnik7" title="Documentation">📖</a></td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 4 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@
# add Algolia to the persistent navbar, this removes the default search icon
"navbar_persistent": "algolia-searchbox",
"use_edit_page_button": True,
"analytics": {
"plausible_analytics_domain": "docs.pybamm.org",
"plausible_analytics_url": "https://plausible.io/js/script.js",
},
"pygment_light_style": "xcode",
"pygment_dark_style": "monokai",
"footer_start": [
Expand Down
23 changes: 11 additions & 12 deletions tests/unit/test_batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import pybamm
import unittest
from tempfile import TemporaryDirectory

spm = pybamm.lithium_ion.SPM()
spm_uniform = pybamm.lithium_ion.SPM({"particle": "uniform profile"})
Expand Down Expand Up @@ -90,21 +91,19 @@ def test_solve(self):
self.assertIn(output_experiment, experiments_list)

def test_create_gif(self):
bs = pybamm.BatchStudy({"spm": pybamm.lithium_ion.SPM()})
bs.solve([0, 10])
with TemporaryDirectory() as dir_name:
bs = pybamm.BatchStudy({"spm": pybamm.lithium_ion.SPM()})
bs.solve([0, 10])

# Create a temporary file name
test_stub = "batch_study_test"
test_file = f"{test_stub}.gif"
# Create a temporary file name
test_file = os.path.join(dir_name, "batch_study_test.gif")

# create a GIF before calling the plot method
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)
# create a GIF before calling the plot method
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)

# create a GIF after calling the plot method
bs.plot(testing=True)
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)

os.remove(test_file)
# create a GIF after calling the plot method
bs.plot(testing=True)
bs.create_gif(number_of_images=3, duration=1, output_filename=test_file)


if __name__ == "__main__":
Expand Down
18 changes: 11 additions & 7 deletions tests/unit/test_expression_tree/test_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from tests import TestCase
import os
import unittest
from tempfile import TemporaryDirectory

import numpy as np
from scipy.sparse import csr_matrix, coo_matrix
Expand Down Expand Up @@ -386,13 +387,16 @@ def test_symbol_repr(self):
)

def test_symbol_visualise(self):
c = pybamm.Variable("c", "negative electrode")
d = pybamm.Variable("d", "negative electrode")
sym = pybamm.div(c * pybamm.grad(c)) + (c / d + c - d) ** 5
sym.visualise("test_visualize.png")
self.assertTrue(os.path.exists("test_visualize.png"))
with self.assertRaises(ValueError):
sym.visualise("test_visualize")
with TemporaryDirectory() as dir_name:
test_stub = os.path.join(dir_name, "test_visualize")
test_name = f"{test_stub}.png"
c = pybamm.Variable("c", "negative electrode")
d = pybamm.Variable("d", "negative electrode")
sym = pybamm.div(c * pybamm.grad(c)) + (c / d + c - d) ** 5
sym.visualise(test_name)
self.assertTrue(os.path.exists(test_name))
with self.assertRaises(ValueError):
sym.visualise(test_stub)

def test_has_spatial_derivatives(self):
var = pybamm.Variable("var", domain="test")
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/test_parameters/test_lead_acid_parameters.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#
# Test for the standard lead acid parameters
#
import os
from tests import TestCase
import pybamm
from tests import get_discretisation_for_testing

from tempfile import TemporaryDirectory
import unittest


Expand All @@ -15,10 +16,11 @@ def test_scipy_constants(self):
self.assertAlmostEqual(constants.F.evaluate(), 96485, places=0)

def test_print_parameters(self):
parameters = pybamm.LeadAcidParameters()
parameter_values = pybamm.lead_acid.BaseModel().default_parameter_values
output_file = "lead_acid_parameters.txt"
parameter_values.print_parameters(parameters, output_file)
with TemporaryDirectory() as dir_name:
parameters = pybamm.LeadAcidParameters()
parameter_values = pybamm.lead_acid.BaseModel().default_parameter_values
output_file = os.path.join(dir_name, "lead_acid_parameters.txt")
parameter_values.print_parameters(parameters, output_file)

def test_parameters_defaults_lead_acid(self):
# Load parameters to be tested
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/test_parameters/test_lithium_ion_parameters.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#
# Tests lithium ion parameters load and give expected values
# Tests lithium-ion parameters load and give expected values
#
import os
from tests import TestCase
import pybamm

from tempfile import TemporaryDirectory
import unittest
import numpy as np


class TestLithiumIonParameterValues(TestCase):
def test_print_parameters(self):
parameters = pybamm.LithiumIonParameters()
parameter_values = pybamm.lithium_ion.BaseModel().default_parameter_values
output_file = "lithium_ion_parameters.txt"
parameter_values.print_parameters(parameters, output_file)
with TemporaryDirectory() as dir_name:
parameters = pybamm.LithiumIonParameters()
parameter_values = pybamm.lithium_ion.BaseModel().default_parameter_values
output_file = os.path.join(dir_name, "lithium_ion_parameters.txt")
parameter_values.print_parameters(parameters, output_file)

def test_lithium_ion(self):
"""This test checks that all the parameters are being calculated
Expand Down
14 changes: 8 additions & 6 deletions tests/unit/test_plotting/test_quick_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import unittest
from tests import TestCase
import numpy as np
from tempfile import TemporaryDirectory


class TestQuickPlot(TestCase):
Expand Down Expand Up @@ -290,12 +291,13 @@ def test_spm_simulation(self):
quick_plot.plot(0)

# test creating a GIF
test_stub = "spm_sim_test"
test_file = f"{test_stub}.gif"
quick_plot.create_gif(number_of_images=3, duration=3, output_filename=test_file)
assert not os.path.exists(f"{test_stub}*.png")
assert os.path.exists(test_file)
os.remove(test_file)
with TemporaryDirectory() as dir_name:
test_stub = os.path.join(dir_name, "spm_sim_test")
test_file = f"{test_stub}.gif"
quick_plot.create_gif(number_of_images=3, duration=3,
output_filename=test_file)
assert not os.path.exists(f"{test_stub}*.png")
assert os.path.exists(test_file)
pybamm.close_plots()

def test_loqs_spme(self):
Expand Down
Loading

0 comments on commit a36ec4f

Please sign in to comment.