Skip to content

Commit

Permalink
Merge pull request #2293 from pybamm-team/save-git-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinsulzer committed Sep 13, 2022
2 parents 2065f6d + 8026dac commit 256da26
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 10 deletions.
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 function `pybamm.get_git_commit_info()`, which returns information about the last git commit, useful for reproducibility ([#2293](https://github.com/pybamm-team/PyBaMM/pull/2293))
- For experiments, the simulation now automatically checks and skips steps that cannot be performed (e.g. "Charge at 1C until 4.2V" from 100% SOC) ([#2212](https://github.com/pybamm-team/PyBaMM/pull/2212))

## Bug fixes
Expand Down
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ casadi >= 3.5.0
imageio>=2.9.0
jupyter # For example notebooks
pybtex
sympy >= 1.8
# Note: Matplotlib is loaded for debug plots but to ensure pybamm runs
# on systems without an attached display it should never be imported
# outside of plot() methods.
Expand All @@ -17,4 +18,3 @@ matplotlib >= 2.0
#
guzzle-sphinx-theme
sphinx>4.0
sympy >= 1.8
20 changes: 19 additions & 1 deletion docs/source/util.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,29 @@ Utility functions

.. autofunction:: pybamm.get_infinite_nested_dict

.. autofunction:: pybamm.load_function
.. autofunction:: pybamm.get_git_commit_info

.. autofunction:: pybamm.rmse

.. autofunction:: pybamm.root_dir

.. autoclass:: pybamm.Timer
:members:

.. autoclass:: pybamm.TimerTime
:members:

.. autoclass:: pybamm.FuzzyDict
:members:

.. autofunction:: pybamm.load_function

.. autofunction:: pybamm.load

.. autofunction:: pybamm.get_parameters_filepath

.. autofunction:: pybamm.have_julia

.. autofunction:: pybamm.have_jax

.. autofunction:: pybamm.is_jax_compatible
1 change: 1 addition & 0 deletions pybamm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
install_jax,
is_jax_compatible,
have_julia,
get_git_commit_info,
)
from .logger import logger, set_logging_level
from .logger import logger, set_logging_level, get_new_logger
Expand Down
6 changes: 3 additions & 3 deletions pybamm/batch_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,11 @@ def create_gif(self, number_of_images=80, duration=0.1, output_filename="plot.gi
Parameters
----------
number_of_images : int (optional)
number_of_images : int, optional
Number of images/plots to be compiled for a GIF.
duration : float (optional)
duration : float, optional
Duration of visibility of a single image/plot in the created GIF.
output_filename : str (optional)
output_filename : str, optional
Name of the generated GIF file.
"""
Expand Down
2 changes: 1 addition & 1 deletion pybamm/spatial_methods/finite_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def spatial_variable(self, symbol):
the FiniteVolume method.
Parameters
-----------
----------
symbol : :class:`pybamm.SpatialVariable`
The spatial variable to be discretised.
Expand Down
4 changes: 2 additions & 2 deletions pybamm/spatial_methods/scikit_finite_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def spatial_variable(self, symbol):
the FiniteElement method.
Parameters
-----------
----------
symbol : :class:`pybamm.SpatialVariable`
The spatial variable to be discretised.
Expand Down Expand Up @@ -128,7 +128,7 @@ def gradient_squared(self, symbol, discretised_symbol, boundary_conditions):
"""
grad = self.gradient(symbol, discretised_symbol, boundary_conditions)
grad_y, grad_z = grad.orphans
return grad_y ** 2 + grad_z ** 2
return grad_y**2 + grad_z**2

def gradient_matrix(self, symbol, boundary_conditions):
"""
Expand Down
4 changes: 2 additions & 2 deletions pybamm/spatial_methods/spatial_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def spatial_variable(self, symbol):
edges).
Parameters
-----------
----------
symbol : :class:`pybamm.SpatialVariable`
The spatial variable to be discretised.
Expand Down Expand Up @@ -341,7 +341,7 @@ def boundary_value_or_flux(self, symbol, discretised_child, bcs=None):
'discretised_child'.
Parameters
-----------
----------
symbol: :class:`pybamm.Symbol`
The boundary value or flux symbol
discretised_child : :class:`pybamm.StateVector`
Expand Down
17 changes: 17 additions & 0 deletions pybamm/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@ def root_dir():
return str(pathlib.Path(pybamm.__path__[0]).parent)


def get_git_commit_info():
"""
Get the git commit info for the current PyBaMM version, e.g. v22.8-39-gb25ce8c41
(version 22.8, commit b25ce8c41)
"""
try:
# Get the latest git commit hash
return str(
subprocess.check_output(["git", "describe", "--tags"], cwd=root_dir())
.strip()
.decode()
)
except subprocess.CalledProcessError: # pragma: no cover
# Not a git repository so just return the version number
return f"v{pybamm.__version__}"


class FuzzyDict(dict):
def get_best_matches(self, key):
"""Get best matches from keys"""
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@ def test_is_jax_compatible(self):
compatible = pybamm.is_jax_compatible()
self.assertTrue(compatible)

def test_git_commit_info(self):
git_commit_info = pybamm.get_git_commit_info()
self.assertIsInstance(git_commit_info, str)
self.assertEqual(git_commit_info[:2], "v2")


class TestSearch(unittest.TestCase):
def test_url_gets_to_stdout(self):
Expand Down

0 comments on commit 256da26

Please sign in to comment.