diff --git a/CHANGELOG.md b/CHANGELOG.md index d0fdb02d72..62f1e7c9f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) ## Optimizations diff --git a/docs/requirements.txt b/docs/requirements.txt index d8a7ccb655..0e38481d28 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -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. @@ -17,4 +18,3 @@ matplotlib >= 2.0 # guzzle-sphinx-theme sphinx>4.0 -sympy >= 1.8 diff --git a/docs/source/util.rst b/docs/source/util.rst index db8ab248c7..1cbc081c1e 100644 --- a/docs/source/util.rst +++ b/docs/source/util.rst @@ -3,7 +3,7 @@ Utility functions .. autofunction:: pybamm.get_infinite_nested_dict -.. autofunction:: pybamm.load_function +.. autofunction:: pybamm.get_git_commit_info .. autofunction:: pybamm.rmse @@ -11,3 +11,21 @@ Utility functions .. 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 diff --git a/pybamm/__init__.py b/pybamm/__init__.py index dd8e10768b..6754557e72 100644 --- a/pybamm/__init__.py +++ b/pybamm/__init__.py @@ -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 diff --git a/pybamm/batch_study.py b/pybamm/batch_study.py index e1f890aa8d..4f1c37e71c 100644 --- a/pybamm/batch_study.py +++ b/pybamm/batch_study.py @@ -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. """ diff --git a/pybamm/spatial_methods/finite_volume.py b/pybamm/spatial_methods/finite_volume.py index c5726e8d13..c77f1d95bf 100644 --- a/pybamm/spatial_methods/finite_volume.py +++ b/pybamm/spatial_methods/finite_volume.py @@ -48,7 +48,7 @@ def spatial_variable(self, symbol): the FiniteVolume method. Parameters - ----------- + ---------- symbol : :class:`pybamm.SpatialVariable` The spatial variable to be discretised. diff --git a/pybamm/spatial_methods/scikit_finite_element.py b/pybamm/spatial_methods/scikit_finite_element.py index dbdf1f063f..8dde7d5118 100644 --- a/pybamm/spatial_methods/scikit_finite_element.py +++ b/pybamm/spatial_methods/scikit_finite_element.py @@ -43,7 +43,7 @@ def spatial_variable(self, symbol): the FiniteElement method. Parameters - ----------- + ---------- symbol : :class:`pybamm.SpatialVariable` The spatial variable to be discretised. @@ -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): """ diff --git a/pybamm/spatial_methods/spatial_method.py b/pybamm/spatial_methods/spatial_method.py index 232ce4d775..267bdda3e8 100644 --- a/pybamm/spatial_methods/spatial_method.py +++ b/pybamm/spatial_methods/spatial_method.py @@ -61,7 +61,7 @@ def spatial_variable(self, symbol): edges). Parameters - ----------- + ---------- symbol : :class:`pybamm.SpatialVariable` The spatial variable to be discretised. @@ -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` diff --git a/pybamm/util.py b/pybamm/util.py index 7cfc5c8532..e6b7c3e7aa 100644 --- a/pybamm/util.py +++ b/pybamm/util.py @@ -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""" diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py index 0ed936ec5b..d8b9810b1e 100644 --- a/tests/unit/test_util.py +++ b/tests/unit/test_util.py @@ -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):