From 0630d0dfae94c2921720cba0d2ee5824f24489bc Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Sun, 5 May 2024 04:30:04 +0100 Subject: [PATCH 01/15] fixes to pybop.experiment, pybop.base_model for pybamm@develop ahead of pybamm v24.5 --- examples/scripts/parameters/example_BPX.json | 7 ++----- pybop/_experiment.py | 2 -- pybop/models/base_model.py | 16 ++++++++++++---- pyproject.toml | 8 +++++--- tests/unit/test_experiment.py | 6 +++--- 5 files changed, 22 insertions(+), 17 deletions(-) diff --git a/examples/scripts/parameters/example_BPX.json b/examples/scripts/parameters/example_BPX.json index 43bbcf90..1e1efaad 100644 --- a/examples/scripts/parameters/example_BPX.json +++ b/examples/scripts/parameters/example_BPX.json @@ -1,7 +1,7 @@ { "Header": { - "BPX": 0.1, - "Title": "Parameterisation example of an LFP|graphite 2 Ah cylindrical 18650 cell.", + "BPX": 0.4, + "Title": "Parameterisation example of an LFP|graphite 2 Ah cylindrical 18650 cell. File downloaded on 19/3/24 from https://github.com/FaradayInstitution/BPX/blob/main/examples/lfp_18650_cell_BPX.json", "Description": "LFP|graphite 2 Ah cylindrical 18650 cell. Parameterisation by About:Energy Limited (aboutenergy.io), December 2022, based on cell cycling data, and electrode data gathered after cell teardown. Electrolyte properties from Nyman et al. 2008 (doi:10.1016/j.electacta.2008.04.023). Negative electrode entropic coefficient data are from O'Regan et al. 2022 (doi:10.1016/j.electacta.2022.140700). Positive electrode entropic coefficient data are from Gerver and Meyers 2011 (doi:10.1149/1.3591799). Other thermal properties are estimated.", "Model": "DFN" }, @@ -70,9 +70,6 @@ "Thickness [m]": 2e-05, "Porosity": 0.47, "Transport efficiency": 0.3222 - }, - "User-defined": { - "Source:": "An example BPX json file downloaded on 19/3/24 from https://github.com/FaradayInstitution/BPX/blob/main/examples/lfp_18650_cell_BPX.json" } } } diff --git a/pybop/_experiment.py b/pybop/_experiment.py index 1c495384..a651dffc 100644 --- a/pybop/_experiment.py +++ b/pybop/_experiment.py @@ -49,6 +49,4 @@ def __init__( period, temperature, termination, - drive_cycles, - cccv_handling, ) diff --git a/pybop/models/base_model.py b/pybop/models/base_model.py index e9ba3d6c..9c2ae880 100644 --- a/pybop/models/base_model.py +++ b/pybop/models/base_model.py @@ -119,9 +119,13 @@ def build( self.set_params() self._mesh = pybamm.Mesh(self.geometry, self.submesh_types, self.var_pts) - self._disc = pybamm.Discretisation(self.mesh, self.spatial_methods) + self._disc = pybamm.Discretisation( + mesh=self.mesh, + spatial_methods=self.spatial_methods, + check_model=check_model, + ) self._built_model = self._disc.process_model( - self._model_with_set_params, inplace=False, check_model=check_model + self._model_with_set_params, inplace=False ) # Clear solver and setup model @@ -230,9 +234,13 @@ def rebuild( self.set_params(rebuild=True) self._mesh = pybamm.Mesh(self.geometry, self.submesh_types, self.var_pts) - self._disc = pybamm.Discretisation(self.mesh, self.spatial_methods) + self._disc = pybamm.Discretisation( + mesh=self.mesh, + spatial_methods=self.spatial_methods, + check_model=check_model, + ) self._built_model = self._disc.process_model( - self._model_with_set_params, inplace=False, check_model=check_model + self._model_with_set_params, inplace=False ) # Clear solver and setup model diff --git a/pyproject.toml b/pyproject.toml index 99067e24..7e4f89ed 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pybop" -version = "24.6" +version = "24.3" authors = [ {name = "The PyBOP Team"}, ] @@ -26,8 +26,10 @@ classifiers = [ ] requires-python = ">=3.9, <3.13" dependencies = [ - "pybamm>=23.9", - "numpy>=1.16, <2.0", + # "pybamm>=23.9", + # "pybamm @ git+https://github.com/pybamm-team/PyBaMM@develop", + "pybamm @ git+https://github.com/BradyPlanden/PyBaMM@fix-electrode-diffusion-rename", + "numpy>=1.16", "scipy>=1.3", "pints>=0.5", "bpx>=0.4", diff --git a/tests/unit/test_experiment.py b/tests/unit/test_experiment.py index 6d18ef50..71355ff8 100644 --- a/tests/unit/test_experiment.py +++ b/tests/unit/test_experiment.py @@ -18,9 +18,9 @@ def test_experiment(self): pybop_experiment = pybop.Experiment(protocol) pybamm_experiment = pybamm.Experiment(protocol) - assert [ - step.to_dict() for step in pybop_experiment.operating_conditions_steps - ] == [step.to_dict() for step in pybamm_experiment.operating_conditions_steps] + assert [step.to_dict() for step in pybop_experiment.steps] == [ + step.to_dict() for step in pybamm_experiment.steps + ] assert pybop_experiment.cycle_lengths == pybamm_experiment.cycle_lengths From 775c3c03cb84d57a123cfb040ffd6986dfd393c5 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Mon, 6 May 2024 00:15:05 +0100 Subject: [PATCH 02/15] increment number of states in spm_UKF example --- examples/scripts/spm_UKF.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/scripts/spm_UKF.py b/examples/scripts/spm_UKF.py index e528c715..c69883b2 100644 --- a/examples/scripts/spm_UKF.py +++ b/examples/scripts/spm_UKF.py @@ -22,7 +22,7 @@ # Make a prediction with measurement noise sigma = 0.001 -t_eval = np.arange(0, 300, 2) +t_eval = np.arange(0, 900, 0.5) values = model.predict(t_eval=t_eval) corrupt_values = values["Voltage [V]"].data + np.random.normal(0, sigma, len(t_eval)) @@ -42,8 +42,8 @@ signal = ["Voltage [V]"] n_states = model.n_states n_signals = len(signal) -covariance = np.diag([0] * 19 + [sigma**2] + [0] * 19 + [sigma**2]) -process_noise = np.diag([0] * 19 + [1e-6] + [0] * 19 + [1e-6]) +covariance = np.diag([0] * 20 + [sigma**2] + [0] * 20 + [sigma**2]) +process_noise = np.diag([0] * 20 + [1e-6] + [0] * 20 + [1e-6]) measurement_noise = np.diag([sigma**2]) observer = pybop.UnscentedKalmanFilterObserver( parameters, From f03643f339dd519de65b71191dcfaed62112004b Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Wed, 22 May 2024 16:55:41 +0100 Subject: [PATCH 03/15] fix: update non-converged DFN test --- pyproject.toml | 3 +-- tests/unit/test_models.py | 9 ++++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7e4f89ed..af331cae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,8 +27,7 @@ classifiers = [ requires-python = ">=3.9, <3.13" dependencies = [ # "pybamm>=23.9", - # "pybamm @ git+https://github.com/pybamm-team/PyBaMM@develop", - "pybamm @ git+https://github.com/BradyPlanden/PyBaMM@fix-electrode-diffusion-rename", + "pybamm @ git+https://github.com/pybamm-team/PyBaMM@develop", "numpy>=1.16", "scipy>=1.3", "pints>=0.5", diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index b50a14bf..4d26a15d 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -358,10 +358,13 @@ def test_non_converged_solution(self): "Voltage [V]": np.zeros(100), } ) - problem = pybop.FittingProblem(model, parameters=parameters, dataset=dataset) - res = problem.evaluate([-0.2, -0.2]) - _, res_grad = problem.evaluateS1([-0.2, -0.2]) + + # Simulate the DFN with active material values of 0 + # This should not converge, and as such, the + # solution from model.simulate should be inf + res = problem.evaluate([0, 0]) + _, res_grad = problem.evaluateS1([0, 0]) for key in problem.signal: assert np.isinf(res.get(key, [])).any() From 9b4fd07bb5afe389e8217ac315940a68084e8de7 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Thu, 27 Jun 2024 18:47:28 +0100 Subject: [PATCH 04/15] update target pybamm source to forked develop w/ diffusivity fix --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index af331cae..156d1086 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -27,7 +27,7 @@ classifiers = [ requires-python = ">=3.9, <3.13" dependencies = [ # "pybamm>=23.9", - "pybamm @ git+https://github.com/pybamm-team/PyBaMM@develop", + "pybamm @ git+https://github.com/bradyplanden/PyBaMM@v24.5rc0-diffusivity-test", "numpy>=1.16", "scipy>=1.3", "pints>=0.5", From f7e5b7ddf77f87248e1ceed998450ee1148b9854 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Fri, 28 Jun 2024 09:58:45 +0100 Subject: [PATCH 05/15] tests: updts to test_non_converged_solution. Changes to pybamm v24.5 have resulted in solver.solve() to return values for incorrect inputs values when not requesting sensitivities. This removes the test that assert output == np.inf in this case. --- tests/unit/test_models.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 4d26a15d..3ed098c3 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -360,12 +360,11 @@ def test_non_converged_solution(self): ) problem = pybop.FittingProblem(model, parameters=parameters, dataset=dataset) - # Simulate the DFN with active material values of 0 - # This should not converge, and as such, the - # solution from model.simulate should be inf - res = problem.evaluate([0, 0]) - _, res_grad = problem.evaluateS1([0, 0]) + # Simulate the DFN with active material values of 0. + # The solution from model.simulateS1 should be inf + # and the gradient should be inf. + output_S1, res_grad = problem.evaluateS1([0, 0]) for key in problem.signal: - assert np.isinf(res.get(key, [])).any() + assert np.isinf(output_S1.get(key, [])).any() assert np.isinf(res_grad).any() From 4b77f0597341a5092d204a26df32aff8aafc59fb Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Fri, 28 Jun 2024 10:50:06 +0100 Subject: [PATCH 06/15] test: updt asserts to capture differing outputs --- tests/unit/test_models.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 3ed098c3..70935845 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -361,10 +361,11 @@ def test_non_converged_solution(self): problem = pybop.FittingProblem(model, parameters=parameters, dataset=dataset) # Simulate the DFN with active material values of 0. - # The solution from model.simulateS1 should be inf - # and the gradient should be inf. + # The solutions will not change as the solver will not converge. + output = problem.evaluate([0, 0]) output_S1, res_grad = problem.evaluateS1([0, 0]) for key in problem.signal: + assert np.allclose(output.get(key, [])[0], output.get(key, [])) assert np.isinf(output_S1.get(key, [])).any() assert np.isinf(res_grad).any() From c88a2ed9c278d6161495c903be8ac8b1a72dd7ba Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Fri, 28 Jun 2024 11:08:25 +0100 Subject: [PATCH 07/15] test: revert to allclose as output vector varies for each OS --- tests/unit/test_models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 70935845..7db67278 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -367,5 +367,5 @@ def test_non_converged_solution(self): for key in problem.signal: assert np.allclose(output.get(key, [])[0], output.get(key, [])) - assert np.isinf(output_S1.get(key, [])).any() + assert np.allclose(output_S1.get(key, [])[0], output_S1.get(key, [])) assert np.isinf(res_grad).any() From 5484a6c8c29ac72e577db061c7ed28b7c297dd38 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Fri, 28 Jun 2024 18:26:54 +0100 Subject: [PATCH 08/15] tests: remove gradient == np.inf assert --- tests/unit/test_models.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 7db67278..b2e29842 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -363,9 +363,8 @@ def test_non_converged_solution(self): # Simulate the DFN with active material values of 0. # The solutions will not change as the solver will not converge. output = problem.evaluate([0, 0]) - output_S1, res_grad = problem.evaluateS1([0, 0]) + output_S1, _ = problem.evaluateS1([0, 0]) for key in problem.signal: assert np.allclose(output.get(key, [])[0], output.get(key, [])) assert np.allclose(output_S1.get(key, [])[0], output_S1.get(key, [])) - assert np.isinf(res_grad).any() From 4c71ed99c201c511d50d12381d18b0091be07732 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Sun, 30 Jun 2024 13:34:09 +0100 Subject: [PATCH 09/15] tests: Add missing asserts --- tests/unit/test_cost.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/unit/test_cost.py b/tests/unit/test_cost.py index 80e44bea..0fc7c546 100644 --- a/tests/unit/test_cost.py +++ b/tests/unit/test_cost.py @@ -179,7 +179,8 @@ def test_costs(self, cost): cost([1.1]) # Test option setting - cost.set_fail_gradient(1) + cost.set_fail_gradient(10) + assert cost._de == 10 if isinstance(cost, pybop.SumSquaredError): e, de = cost.evaluateS1([0.5]) @@ -263,4 +264,4 @@ def test_design_costs( # Compute after updating nominal capacity cost = cost_class(problem, update_capacity=True) - cost([0.4]) + assert np.isfinite(cost([0.4])) From d95275f099aa34864b1173ce552b040065d9e48a Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Mon, 22 Jul 2024 12:01:12 +0100 Subject: [PATCH 10/15] build: increment pybamm to 24.5rc2, ci: increment tests alongside. --- .gitignore | 3 ++ CHANGELOG.md | 8 ++++++ examples/scripts/gitt.py | 4 +-- pybop/models/lithium_ion/weppner_huggins.py | 4 +-- pyproject.toml | 28 +++++++++++++------ scripts/ci/build_matrix.sh | 11 +++++--- .../test_model_experiment_changes.py | 2 +- tests/unit/test_models.py | 2 +- 8 files changed, 44 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 3c3bb708..2bafcca6 100644 --- a/.gitignore +++ b/.gitignore @@ -314,3 +314,6 @@ $RECYCLE.BIN/ # Airspeed Velocity *.asv/ results/ + +# Pycharm +*.idea/ diff --git a/CHANGELOG.md b/CHANGELOG.md index b2cb56fe..c5da6a56 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ ## Features +## Bug Fixes + +## Breaking Changes + +# [v24.6.1](https://github.com/pybop-team/PyBOP/tree/v24.6.1) - 2024-07-XX + +## Features +- [#313](https://github.com/pybop-team/PyBOP/pull/313/) - Fixes for PyBaMM v24.5, drops support for PyBaMM v23.9, v24.1 ## Bug Fixes diff --git a/examples/scripts/gitt.py b/examples/scripts/gitt.py index 6d3b4a94..4b8c1561 100644 --- a/examples/scripts/gitt.py +++ b/examples/scripts/gitt.py @@ -36,10 +36,10 @@ model = pybop.lithium_ion.WeppnerHuggins(parameter_set=parameter_set) parameters = pybop.Parameter( - "Positive electrode diffusivity [m2.s-1]", + "Positive particle diffusivity [m2.s-1]", prior=pybop.Gaussian(5e-14, 1e-13), bounds=[1e-16, 1e-11], - true_value=parameter_set["Positive electrode diffusivity [m2.s-1]"], + true_value=parameter_set["Positive particle diffusivity [m2.s-1]"], ) problem = pybop.FittingProblem( diff --git a/pybop/models/lithium_ion/weppner_huggins.py b/pybop/models/lithium_ion/weppner_huggins.py index 5d8d626a..b8707cca 100644 --- a/pybop/models/lithium_ion/weppner_huggins.py +++ b/pybop/models/lithium_ion/weppner_huggins.py @@ -36,7 +36,7 @@ def __init__(self, name="Weppner & Huggins model", **model_kwargs): # Model kwargs (build, options) are not implemented, keeping here for consistent interface if model_kwargs is not dict(build=True): unused_kwargs_warning = "The input model_kwargs are not currently used by the Weppner & Huggins model." - warnings.warn(unused_kwargs_warning, UserWarning) + warnings.warn(unused_kwargs_warning, UserWarning, stacklevel=2) super().__init__({}, name) @@ -65,7 +65,7 @@ def __init__(self, name="Weppner & Huggins model", **model_kwargs): # Parameters ###################### - d_s = Parameter("Positive electrode diffusivity [m2.s-1]") + d_s = Parameter("Positive particle diffusivity [m2.s-1]") c_s_max = Parameter("Maximum concentration in positive electrode [mol.m-3]") diff --git a/pyproject.toml b/pyproject.toml index 156d1086..3dcd94c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "pybop" -version = "24.3" +version = "24.6" authors = [ {name = "The PyBOP Team"}, ] @@ -26,9 +26,8 @@ classifiers = [ ] requires-python = ">=3.9, <3.13" dependencies = [ - # "pybamm>=23.9", - "pybamm @ git+https://github.com/bradyplanden/PyBaMM@v24.5rc0-diffusivity-test", - "numpy>=1.16", + "pybamm>=24.5rc2", + "numpy>=1.16, <2.0", "scipy>=1.3", "pints>=0.5", "bpx>=0.4", @@ -74,7 +73,7 @@ Homepage = "https://github.com/pybop-team/PyBOP" Documentation = "https://pybop-docs.readthedocs.io" Repository = "https://github.com/pybop-team/PyBOP" Releases = "https://github.com/pybop-team/PyBOP/releases" -Changelog = "https://github.com/pybop-team/PyBOP/CHANGELOG.md" +Changelog = "https://github.com/pybop-team/PyBOP/blob/develop/CHANGELOG.md" [tool.pytest.ini_options] addopts = "--showlocals -v -n auto" @@ -82,10 +81,23 @@ addopts = "--showlocals -v -n auto" [tool.ruff] extend-include = ["*.ipynb"] extend-exclude = ["__init__.py"] +fix = true [tool.ruff.lint] -extend-select = ["I"] +select = [ + "A", # flake8-builtins: Check for Python builtins being used as variables or parameters + "B", # flake8-bugbear: Find likely bugs and design problems + "E", # pycodestyle errors + "W", # pycodestyle warnings + "F", # pyflakes: Detect various errors by parsing the source file + "I", # isort: Check and enforce import ordering + "ISC", # flake8-implicit-str-concat: Check for implicit string concatenation + "TID", # flake8-tidy-imports: Validate import hygiene + "UP", # pyupgrade: Automatically upgrade syntax for newer versions of Python +] + ignore = ["E501","E741"] +per-file-ignores = {"**.ipynb" = ["E402", "E703"]} -[tool.ruff.lint.per-file-ignores] -"**.ipynb" = ["E402", "E703"] +[tool.ruff.lint.flake8-tidy-imports] +ban-relative-imports = "all" diff --git a/scripts/ci/build_matrix.sh b/scripts/ci/build_matrix.sh index 9dfe3224..88d5b9b3 100755 --- a/scripts/ci/build_matrix.sh +++ b/scripts/ci/build_matrix.sh @@ -11,8 +11,11 @@ python_version=("3.9" "3.10" "3.11" "3.12") os=("ubuntu-latest" "windows-latest" "macos-13" "macos-14") -# This command fetches the last two PyBaMM versions excluding release candidates from PyPI -pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 2 | paste -sd " " -)) +# This command fetches the last PyBaMM version excluding release candidates from PyPI +#pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 1 | paste -sd " " -)) + +# This command fetches the last PyBaMM versions including release candidates from PyPI +pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | tail -n 1 | paste -sd " " -)) # open dict json='{ @@ -40,7 +43,7 @@ json+=' ] }' -# Filter out incompatible combinations -json=$(echo "$json" | jq -c 'del(.include[] | select(.pybamm_version == "23.9" and .python_version == "3.12"))') +# Example for filtering out incompatible combinations +#json=$(echo "$json" | jq -c 'del(.include[] | select(.pybamm_version == "23.9" and .python_version == "3.12"))') echo "$json" | jq -c . diff --git a/tests/integration/test_model_experiment_changes.py b/tests/integration/test_model_experiment_changes.py index 64d27132..7bcc33dd 100644 --- a/tests/integration/test_model_experiment_changes.py +++ b/tests/integration/test_model_experiment_changes.py @@ -22,7 +22,7 @@ class TestModelAndExperimentChanges: ), pybop.Parameters( pybop.Parameter( # non-geometric parameter - "Positive electrode diffusivity [m2.s-1]", + "Positive particle diffusivity [m2.s-1]", prior=pybop.Gaussian(3.43e-15, 1e-15), bounds=[1e-15, 5e-15], true_value=4e-15, diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index b2e29842..b12b3639 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -361,7 +361,7 @@ def test_non_converged_solution(self): problem = pybop.FittingProblem(model, parameters=parameters, dataset=dataset) # Simulate the DFN with active material values of 0. - # The solutions will not change as the solver will not converge. + # The solution elements will not change as the solver will not converge. output = problem.evaluate([0, 0]) output_S1, _ = problem.evaluateS1([0, 0]) From 49154041447451455c747b96bd236ff3a76f9f95 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Sat, 20 Jul 2024 15:13:38 +0100 Subject: [PATCH 11/15] tests: increase coverage, fix flaky observer tests --- tests/unit/test_observer_unscented_kalman.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/unit/test_observer_unscented_kalman.py b/tests/unit/test_observer_unscented_kalman.py index ce60abbc..a6217cbb 100644 --- a/tests/unit/test_observer_unscented_kalman.py +++ b/tests/unit/test_observer_unscented_kalman.py @@ -93,6 +93,15 @@ def test_cholupdate(self): SquareRootUKF.cholupdate(R1_, u.copy(), 1.0) np.testing.assert_array_almost_equal(R1, R1_) + # Test hypot + f = 10.0 + j = 20.0 + out_1 = f * np.sqrt(1 + 1.0 * f**2 / j**2) + np.testing.assert_allclose(SquareRootUKF.hypot(f, j, 1.0), out_1) + + j = 10.0 + np.testing.assert_allclose(SquareRootUKF.hypot(f, j, 1.0), float(0)) + @pytest.mark.unit def test_unscented_kalman_filter(self, dataset, observer): t_eval = dataset["Time [s]"] @@ -116,6 +125,11 @@ def test_unscented_kalman_filter(self, dataset, observer): decimal=4, ) + # Test get covariance + cov = observer.get_current_measure() + assert cov.shape == (1, 1) + assert float(0) <= cov[0] + @pytest.mark.unit def test_observe_no_measurement(self, observer): with pytest.raises(ValueError): From baa9467fb904be9631623edb015f604b7be25746 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 22 Jul 2024 11:06:32 +0000 Subject: [PATCH 12/15] style: pre-commit fixes --- pybop/costs/fitting_costs.py | 2 +- pybop/models/base_model.py | 2 +- pybop/observers/unscented_kalman.py | 4 ++-- pybop/parameters/parameter_set.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/pybop/costs/fitting_costs.py b/pybop/costs/fitting_costs.py index 6315c4b6..e474fd11 100644 --- a/pybop/costs/fitting_costs.py +++ b/pybop/costs/fitting_costs.py @@ -161,7 +161,7 @@ def _evaluate(self, inputs: Inputs, grad=None): e = np.asarray( [ - np.sum(((prediction[signal] - self._target[signal]) ** 2)) + np.sum((prediction[signal] - self._target[signal]) ** 2) for signal in self.signal ] ) diff --git a/pybop/models/base_model.py b/pybop/models/base_model.py index 9c2ae880..eba7ed88 100644 --- a/pybop/models/base_model.py +++ b/pybop/models/base_model.py @@ -11,7 +11,7 @@ @dataclass -class TimeSeriesState(object): +class TimeSeriesState: """ The current state of a time series model that is a pybamm model. """ diff --git a/pybop/observers/unscented_kalman.py b/pybop/observers/unscented_kalman.py index afbc2a01..c7eb18b0 100644 --- a/pybop/observers/unscented_kalman.py +++ b/pybop/observers/unscented_kalman.py @@ -152,7 +152,7 @@ def get_current_covariance(self) -> Covariance: @dataclass -class SigmaPoint(object): +class SigmaPoint: """ A sigma point is a point in the state space that is used to estimate the mean and covariance of a random variable. """ @@ -162,7 +162,7 @@ class SigmaPoint(object): w_c: float -class SquareRootUKF(object): +class SquareRootUKF: """ van der Menve, R., & Wan, E. A. (2001). THE SQUARE-ROOT UNSCENTED KALMAN FILTER FOR STATE AND PARAMETER-ESTIMATION. https://doi.org/10.1109/ICASSP.2001.940586 diff --git a/pybop/parameters/parameter_set.py b/pybop/parameters/parameter_set.py index 43f3e999..821faf68 100644 --- a/pybop/parameters/parameter_set.py +++ b/pybop/parameters/parameter_set.py @@ -67,7 +67,7 @@ def import_parameters(self, json_path=None): # Read JSON file if not self.params and self.json_path: - with open(self.json_path, "r") as file: + with open(self.json_path) as file: self.params = json.load(file) else: raise ValueError( From 963f563b1a882fcd977844484cfc9209047e4c28 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Mon, 22 Jul 2024 12:14:34 +0100 Subject: [PATCH 13/15] Reverts linting changes for patch v24.6.1 --- pyproject.toml | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3dcd94c1..77e11735 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ ] requires-python = ">=3.9, <3.13" dependencies = [ - "pybamm>=24.5rc2", + "pybamm>=24.5rc2", "numpy>=1.16, <2.0", "scipy>=1.3", "pints>=0.5", @@ -84,20 +84,8 @@ extend-exclude = ["__init__.py"] fix = true [tool.ruff.lint] -select = [ - "A", # flake8-builtins: Check for Python builtins being used as variables or parameters - "B", # flake8-bugbear: Find likely bugs and design problems - "E", # pycodestyle errors - "W", # pycodestyle warnings - "F", # pyflakes: Detect various errors by parsing the source file - "I", # isort: Check and enforce import ordering - "ISC", # flake8-implicit-str-concat: Check for implicit string concatenation - "TID", # flake8-tidy-imports: Validate import hygiene - "UP", # pyupgrade: Automatically upgrade syntax for newer versions of Python -] - +extend-select = ["I"] ignore = ["E501","E741"] -per-file-ignores = {"**.ipynb" = ["E402", "E703"]} -[tool.ruff.lint.flake8-tidy-imports] -ban-relative-imports = "all" +[tool.ruff.lint.per-file-ignores] +"**.ipynb" = ["E402", "E703"] From 8c9823cd836ad9b3aac6aaa5a66adea5001e4367 Mon Sep 17 00:00:00 2001 From: Brady Planden Date: Wed, 31 Jul 2024 09:11:12 +0100 Subject: [PATCH 14/15] release: increment versions --- CITATION.cff | 2 +- docs/_static/switcher.json | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CITATION.cff b/CITATION.cff index b5c83816..6583447f 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -11,5 +11,5 @@ authors: family-names: Courtier - given-names: David family-names: Howey -version: "24.6" # Update this when you release a new version +version: "24.6.1" # Update this when you release a new version repository-code: 'https://www.github.com/pybop-team/pybop' diff --git a/docs/_static/switcher.json b/docs/_static/switcher.json index 2847bc26..8985f8ee 100644 --- a/docs/_static/switcher.json +++ b/docs/_static/switcher.json @@ -6,7 +6,7 @@ { "name": "v24.6 (stable)", "version": "v24.6", - "url": "https://pybop-docs.readthedocs.io/en/v24.6/", + "url": "https://pybop-docs.readthedocs.io/en/v24.6.1/", "preferred": true }, { diff --git a/pyproject.toml b/pyproject.toml index 77e11735..a4334c1e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ ] requires-python = ">=3.9, <3.13" dependencies = [ - "pybamm>=24.5rc2", + "pybamm>=24.5", "numpy>=1.16, <2.0", "scipy>=1.3", "pints>=0.5", From a3182076f1bed0834cf7111bd1403d456eaea97f Mon Sep 17 00:00:00 2001 From: Brady Planden <55357039+BradyPlanden@users.noreply.github.com> Date: Wed, 31 Jul 2024 12:00:23 +0100 Subject: [PATCH 15/15] Apply suggestions from code review --- CHANGELOG.md | 2 +- scripts/ci/build_matrix.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5da6a56..616a26ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ ## Breaking Changes -# [v24.6.1](https://github.com/pybop-team/PyBOP/tree/v24.6.1) - 2024-07-XX +# [v24.6.1](https://github.com/pybop-team/PyBOP/tree/v24.6.1) - 2024-07-31 ## Features - [#313](https://github.com/pybop-team/PyBOP/pull/313/) - Fixes for PyBaMM v24.5, drops support for PyBaMM v23.9, v24.1 diff --git a/scripts/ci/build_matrix.sh b/scripts/ci/build_matrix.sh index 88d5b9b3..491bb59d 100755 --- a/scripts/ci/build_matrix.sh +++ b/scripts/ci/build_matrix.sh @@ -12,10 +12,10 @@ python_version=("3.9" "3.10" "3.11" "3.12") os=("ubuntu-latest" "windows-latest" "macos-13" "macos-14") # This command fetches the last PyBaMM version excluding release candidates from PyPI -#pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 1 | paste -sd " " -)) +pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | grep -v rc | tail -n 1 | paste -sd " " -)) # This command fetches the last PyBaMM versions including release candidates from PyPI -pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | tail -n 1 | paste -sd " " -)) +#pybamm_version=($(curl -s https://pypi.org/pypi/pybamm/json | jq -r '.releases | keys[]' | tail -n 1 | paste -sd " " -)) # open dict json='{