Skip to content

Commit

Permalink
Merge branch 'pybamm-team:develop' into casadi-windows-wheels
Browse files Browse the repository at this point in the history
  • Loading branch information
agriyakhetarpal authored Dec 22, 2023
2 parents 65a9d6e + 7e72c38 commit c14ed01
Show file tree
Hide file tree
Showing 13 changed files with 435 additions and 137 deletions.
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,16 @@
"contributions": [
"infra"
]
},
{
"login": "XuboGU",
"name": "XuboGU",
"avatar_url": "https://avatars.githubusercontent.com/u/53944452?v=4",
"profile": "https://github.com/XuboGU",
"contributions": [
"code",
"bug"
]
}
],
"contributorsPerLine": 7,
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/periodic_benchmarks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ jobs:
LD_LIBRARY_PATH: $HOME/.local/lib

- name: Upload results as artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: asv_new_results
name: asv_periodic_results
path: results

publish-results:
Expand All @@ -73,9 +73,9 @@ jobs:
token: ${{ secrets.BENCH_PAT }}

- name: Download results artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: asv_new_results
name: asv_periodic_results
path: new_results

- name: Copy new results and push to pybamm-bench repo
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/publish_pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
CIBW_ARCHS: "AMD64"

- name: Upload Windows wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: windows_wheels
path: ./wheelhouse/*.whl
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
CIBW_SKIP: "pp* *musllinux*"

- name: Upload wheels
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: wheels
path: ./wheelhouse/*.whl
Expand All @@ -133,7 +133,7 @@ jobs:
run: pipx run build --sdist

- name: Upload SDist
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: sdist
path: ./dist/*.tar.gz
Expand All @@ -146,7 +146,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4

- name: Move all package files to files/
run: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/run_benchmarks_over_history.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ jobs:
asv run -m "GitHubRunner" -s ${{ github.event.inputs.ncommits }} \
${{ github.event.inputs.commit_start }}..${{ github.event.inputs.commit_end }}
- name: Upload results as artifact
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: asv_new_results
name: asv_over_history_results
path: results

publish-results:
Expand All @@ -65,9 +65,9 @@ jobs:
repository: pybamm-team/pybamm-bench
token: ${{ secrets.BENCH_PAT }}
- name: Download results artifact
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: asv_new_results
name: asv_over_history_results
path: new_results
- name: Copy new results and push to pybamm-bench repo
env:
Expand Down
3 changes: 2 additions & 1 deletion 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-71-orange.svg)](#-contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-72-orange.svg)](#-contributors)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

</div>
Expand Down Expand Up @@ -277,6 +277,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://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/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>
</tr>
</tbody>
</table>
Expand Down
331 changes: 254 additions & 77 deletions docs/source/examples/notebooks/solvers/speed-up-solver.ipynb

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ def run_coverage(session):
"""Run the coverage tests and generate an XML report."""
set_environment_variables(PYBAMM_ENV, session=session)
session.install("coverage", silent=False)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
Expand All @@ -79,6 +83,10 @@ def run_coverage(session):
def run_integration(session):
"""Run the integration tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
Expand All @@ -95,6 +103,10 @@ def run_integration(session):
@nox.session(name="doctests")
def run_doctests(session):
"""Run the doctests and generate the output(s) in the docs/build/ directory."""
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,docs]", silent=False)
session.run("python", "run-tests.py", "--doctest")

Expand All @@ -103,6 +115,10 @@ def run_doctests(session):
def run_unit(session):
"""Run the unit tests."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
Expand All @@ -120,6 +136,10 @@ def run_unit(session):
def run_examples(session):
"""Run the examples tests for Jupyter notebooks."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all,dev]", silent=False)
notebooks_to_test = session.posargs if session.posargs else []
session.run("pytest", "--nbmake", *notebooks_to_test, external=True)
Expand All @@ -129,6 +149,10 @@ def run_examples(session):
def run_scripts(session):
"""Run the scripts tests for Python scripts."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.install("-e", ".[all]", silent=False)
session.run("python", "run-tests.py", "--scripts")

Expand All @@ -140,6 +164,10 @@ def set_dev(session):
session.install("virtualenv", "cmake")
session.run("virtualenv", os.fsdecode(VENV_DIR), silent=True)
python = os.fsdecode(VENV_DIR.joinpath("bin/python"))
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.run(python, "-m", "pip", "install", "setuptools", external=True)
if sys.platform == "linux":
if sys.version_info > (3, 12):
session.run(
Expand Down Expand Up @@ -188,6 +216,10 @@ def set_dev(session):
def run_tests(session):
"""Run the unit tests and integration tests sequentially."""
set_environment_variables(PYBAMM_ENV, session=session)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
if sys.platform != "win32":
if sys.version_info > (3, 12):
session.install("-e", ".[all,jax]", silent=False)
Expand All @@ -206,6 +238,10 @@ def build_docs(session):
"""Build the documentation and load it in a browser tab, rebuilding on changes."""
envbindir = session.bin
session.install("-e", ".[all,docs]", silent=False)
# Temporary fix for Python 3.12 CI. TODO: remove after
# https://bitbucket.org/pybtex-devs/pybtex/issues/169/replace-pkg_resources-with
# is fixed
session.install("setuptools", silent=False)
session.chdir("docs")
# Local development
if session.interactive:
Expand Down
38 changes: 31 additions & 7 deletions pybamm/expression_tree/binary_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1239,11 +1239,14 @@ def minimum(left, right):
if out is not None:
return out

k = pybamm.settings.min_smoothing
mode = pybamm.settings.min_max_mode
k = pybamm.settings.min_max_smoothing
# Return exact approximation if that is the setting or the outcome is a constant
# (i.e. no need for smoothing)
if k == "exact" or (left.is_constant() and right.is_constant()):
if mode == "exact" or (left.is_constant() and right.is_constant()):
out = Minimum(left, right)
elif mode == "smooth":
out = pybamm.smooth_min(left, right, k)
else:
out = pybamm.softminus(left, right, k)
return pybamm.simplify_if_constant(out)
Expand All @@ -1260,11 +1263,14 @@ def maximum(left, right):
if out is not None:
return out

k = pybamm.settings.max_smoothing
mode = pybamm.settings.min_max_mode
k = pybamm.settings.min_max_smoothing
# Return exact approximation if that is the setting or the outcome is a constant
# (i.e. no need for smoothing)
if k == "exact" or (left.is_constant() and right.is_constant()):
if mode == "exact" or (left.is_constant() and right.is_constant()):
out = Maximum(left, right)
elif mode == "smooth":
out = pybamm.smooth_max(left, right, k)
else:
out = pybamm.softplus(left, right, k)
return pybamm.simplify_if_constant(out)
Expand Down Expand Up @@ -1311,20 +1317,38 @@ def _heaviside(left, right, equal):

def softminus(left, right, k):
"""
Softplus approximation to the minimum function. k is the smoothing parameter,
set by `pybamm.settings.min_smoothing`. The recommended value is k=10.
Softminus approximation to the minimum function. k is the smoothing parameter,
set by `pybamm.settings.min_max_smoothing`. The recommended value is k=10.
"""
return pybamm.log(pybamm.exp(-k * left) + pybamm.exp(-k * right)) / -k


def softplus(left, right, k):
"""
Softplus approximation to the maximum function. k is the smoothing parameter,
set by `pybamm.settings.max_smoothing`. The recommended value is k=10.
set by `pybamm.settings.min_max_smoothing`. The recommended value is k=10.
"""
return pybamm.log(pybamm.exp(k * left) + pybamm.exp(k * right)) / k


def smooth_min(left, right, k):
"""
Smooth_min approximation to the minimum function. k is the smoothing parameter,
set by `pybamm.settings.min_max_smoothing`. The recommended value is k=100.
"""
sigma = (1.0 / k)**2
return ((left + right) - (pybamm.sqrt((left - right)**2 + sigma))) / 2


def smooth_max(left, right, k):
"""
Smooth_max approximation to the maximum function. k is the smoothing parameter,
set by `pybamm.settings.min_max_smoothing`. The recommended value is k=100.
"""
sigma = (1.0 / k) ** 2
return (pybamm.sqrt((left - right)**2 + sigma) + (left + right)) / 2


def sigmoid(left, right, k):
"""
Sigmoidal approximation to the heaviside function. k is the smoothing parameter,
Expand Down
2 changes: 1 addition & 1 deletion pybamm/input/parameters/lithium_ion/Ai2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ def electrolyte_diffusivity_Ai2020(c_e, T):
Solid diffusivity
"""

D_c_e = 10 ** (-8.43 - 54 / (T - 229 - 5e-3 * c_e) - 0.22e-3 * c_e)
D_c_e = 10 ** (-4.43 - 54 / (T - 229 - 5e-3 * c_e) - 0.22e-3 * c_e)

return D_c_e

Expand Down
52 changes: 33 additions & 19 deletions pybamm/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
class Settings:
_debug_mode = False
_simplify = True
_min_smoothing = "exact"
_max_smoothing = "exact"
_min_max_mode = "exact"
_min_max_smoothing = 10
_heaviside_smoothing = "exact"
_abs_smoothing = "exact"
max_words_in_line = 4
Expand Down Expand Up @@ -43,35 +43,49 @@ def simplify(self, value):
self._simplify = value

def set_smoothing_parameters(self, k):
"Helper function to set all smoothing parameters"
self.min_smoothing = k
self.max_smoothing = k
"""Helper function to set all smoothing parameters"""
if k == "exact":
self.min_max_mode = "exact"
else:
self.min_max_smoothing = k
self.min_max_mode = "soft"
self.heaviside_smoothing = k
self.abs_smoothing = k

def check_k(self, k):
@staticmethod
def check_k(k):
if k != "exact" and k <= 0:
raise ValueError(
"smoothing parameter must be 'exact' or a strictly positive number"
"Smoothing parameter must be 'exact' or a strictly positive number"
)

@property
def min_smoothing(self):
return self._min_smoothing
def min_max_mode(self):
return self._min_max_mode

@min_smoothing.setter
def min_smoothing(self, k):
self.check_k(k)
self._min_smoothing = k
@min_max_mode.setter
def min_max_mode(self, mode):
if mode not in ["exact", "soft", "smooth"]:
raise ValueError(
"Smoothing mode must be 'exact', 'soft', or 'smooth'"
)
self._min_max_mode = mode

@property
def max_smoothing(self):
return self._max_smoothing
def min_max_smoothing(self):
return self._min_max_smoothing

@max_smoothing.setter
def max_smoothing(self, k):
self.check_k(k)
self._max_smoothing = k
@min_max_smoothing.setter
def min_max_smoothing(self, k):
if self._min_max_mode == "soft" and k <= 0:
raise ValueError(
"Smoothing parameter must be a strictly positive number"
)
if self._min_max_mode == "smooth" and k < 1:
raise ValueError(
"Smoothing parameter must be greater than 1"
)
self._min_max_smoothing = k

@property
def heaviside_smoothing(self):
Expand Down
Loading

0 comments on commit c14ed01

Please sign in to comment.