From be8a55fcdf07b5f87a4000c98daa311620519fe5 Mon Sep 17 00:00:00 2001 From: NicolaCourtier <45851982+NicolaCourtier@users.noreply.github.com> Date: Wed, 4 Dec 2024 22:01:32 +0000 Subject: [PATCH 1/3] Add naming utility --- pybop/_utils.py | 10 ++++++++++ pybop/costs/base_cost.py | 5 +++++ pyproject.toml | 1 + tests/unit/test_cost.py | 15 ++++++++------- 4 files changed, 24 insertions(+), 7 deletions(-) diff --git a/pybop/_utils.py b/pybop/_utils.py index 426b0d27..7566dca1 100644 --- a/pybop/_utils.py +++ b/pybop/_utils.py @@ -2,6 +2,7 @@ import numpy as np import pybamm +import regex as re def is_numeric(x): @@ -11,6 +12,15 @@ def is_numeric(x): return isinstance(x, (int, float, np.number)) +def add_spaces(string): + """ + Return the class name as a string with spaces before each new capitalised word. + """ + re_outer = re.compile(r"([^A-Z ])([A-Z])") + re_inner = re.compile(r"(?=1.16, <2.0", "scipy>=1.3", "pints>=0.5", + "regex", ] [project.optional-dependencies] diff --git a/tests/unit/test_cost.py b/tests/unit/test_cost.py index e9ad01dc..134a7d36 100644 --- a/tests/unit/test_cost.py +++ b/tests/unit/test_cost.py @@ -235,19 +235,20 @@ def design_problem(self, parameters, experiment, signal): ) @pytest.mark.parametrize( - "cost_class", + "cost_class, expected_name", [ - pybop.DesignCost, - pybop.GravimetricEnergyDensity, - pybop.VolumetricEnergyDensity, - pybop.GravimetricPowerDensity, - pybop.VolumetricPowerDensity, + (pybop.DesignCost, "Design Cost"), + (pybop.GravimetricEnergyDensity, "Gravimetric Energy Density"), + (pybop.VolumetricEnergyDensity, "Volumetric Energy Density"), + (pybop.GravimetricPowerDensity, "Gravimetric Power Density"), + (pybop.VolumetricPowerDensity, "Volumetric Power Density"), ], ) @pytest.mark.unit - def test_design_costs(self, cost_class, design_problem): + def test_design_costs(self, cost_class, expected_name, design_problem): # Construct Cost cost = cost_class(design_problem) + assert cost.name == expected_name if cost_class in [pybop.DesignCost]: with pytest.raises(NotImplementedError): From 4457e8e498088ba3015eeffe66e4cdf1745f1a1e Mon Sep 17 00:00:00 2001 From: NicolaCourtier <45851982+NicolaCourtier@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:32:27 +0000 Subject: [PATCH 2/3] Remove regex dependency Co-authored-by: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> --- pybop/_utils.py | 2 +- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pybop/_utils.py b/pybop/_utils.py index 7566dca1..fb0f1f59 100644 --- a/pybop/_utils.py +++ b/pybop/_utils.py @@ -2,7 +2,7 @@ import numpy as np import pybamm -import regex as re +import re def is_numeric(x): diff --git a/pyproject.toml b/pyproject.toml index 54a1bfc7..5e1c7444 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -30,7 +30,6 @@ dependencies = [ "numpy>=1.16, <2.0", "scipy>=1.3", "pints>=0.5", - "regex", ] [project.optional-dependencies] From c3811e3eb41ee56045af15a4fe437ce3a2d72545 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 6 Dec 2024 10:34:20 +0000 Subject: [PATCH 3/3] style: pre-commit fixes --- pybop/_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybop/_utils.py b/pybop/_utils.py index fb0f1f59..c09991b3 100644 --- a/pybop/_utils.py +++ b/pybop/_utils.py @@ -1,8 +1,8 @@ +import re from typing import Optional import numpy as np import pybamm -import re def is_numeric(x):