Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:kratman/PyBaMM into feat/smoothmin
Browse files Browse the repository at this point in the history
  • Loading branch information
kratman committed Oct 8, 2023
2 parents a7cc3bf + 535c034 commit 8f7f36f
Show file tree
Hide file tree
Showing 11 changed files with 294 additions and 193 deletions.
2 changes: 1 addition & 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
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
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
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
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 8f7f36f

Please sign in to comment.