diff --git a/tests/integration/test_optimisation_options.py b/tests/integration/test_optimisation_options.py index 796090c4..f88720ea 100644 --- a/tests/integration/test_optimisation_options.py +++ b/tests/integration/test_optimisation_options.py @@ -56,7 +56,7 @@ def noise(self, sigma, values): def spm_costs(self, model, parameters, cost_class): # Form dataset init_soc = 0.5 - solution = self.getdata(model, self.ground_truth, init_soc) + solution = self.get_data(model, parameters, self.ground_truth, init_soc) dataset = pybop.Dataset( { "Time [s]": solution["Time [s]"].data, @@ -99,15 +99,10 @@ def test_optimisation_f_guessed(self, f_guessed, spm_costs): # Assertions assert initial_cost > final_cost - np.testing.assert_allclose(x, self.ground_truth, atol=2.5e-2) + np.testing.assert_allclose(x, self.ground_truth, atol=1e-2) - def getdata(self, model, x, init_soc): - model.parameter_set.update( - { - "Negative electrode active material volume fraction": x[0], - "Positive electrode active material volume fraction": x[1], - } - ) + def get_data(self, model, parameters, x, init_soc): + model.parameters = parameters experiment = pybop.Experiment( [ ( @@ -117,5 +112,5 @@ def getdata(self, model, x, init_soc): ] * 2 ) - sim = model.predict(init_soc=init_soc, experiment=experiment) + sim = model.predict(init_soc=init_soc, experiment=experiment, inputs=x) return sim diff --git a/tests/integration/test_spm_parameterisations.py b/tests/integration/test_spm_parameterisations.py index 89ecc32f..40b4f40e 100644 --- a/tests/integration/test_spm_parameterisations.py +++ b/tests/integration/test_spm_parameterisations.py @@ -1,6 +1,5 @@ import numpy as np import pytest -from pybamm import __version__ as pybamm_version import pybop @@ -59,7 +58,7 @@ def noise(self, sigma, values): @pytest.fixture def spm_costs(self, model, parameters, cost_class, init_soc): # Form dataset - solution = self.getdata(model, self.ground_truth, init_soc) + solution = self.get_data(model, parameters, self.ground_truth, init_soc) dataset = pybop.Dataset( { "Time [s]": solution["Time [s]"].data, @@ -119,16 +118,13 @@ def test_spm_optimisers(self, optimiser, spm_costs): # Assertions if not np.allclose(x0, self.ground_truth, atol=1e-5): assert initial_cost > final_cost - if pybamm_version <= "23.9": - np.testing.assert_allclose(x, self.ground_truth, atol=2.5e-2) - else: - np.testing.assert_allclose(x, self.ground_truth, atol=1.75e-2) + np.testing.assert_allclose(x, self.ground_truth, atol=1e-2) @pytest.fixture def spm_two_signal_cost(self, parameters, model, cost_class): # Form dataset init_soc = 0.5 - solution = self.getdata(model, self.ground_truth, init_soc) + solution = self.get_data(model, parameters, self.ground_truth, init_soc) dataset = pybop.Dataset( { "Time [s]": solution["Time [s]"].data, @@ -188,7 +184,7 @@ def test_multiple_signals(self, multi_optimiser, spm_two_signal_cost): # Assertions if not np.allclose(x0, self.ground_truth, atol=1e-5): assert initial_cost > final_cost - np.testing.assert_allclose(x, self.ground_truth, atol=2.5e-2) + np.testing.assert_allclose(x, self.ground_truth, atol=1e-2) @pytest.mark.parametrize("init_soc", [0.4, 0.6]) @pytest.mark.integration @@ -199,7 +195,7 @@ def test_model_misparameterisation(self, parameters, model, init_soc): second_model = pybop.lithium_ion.SPMe(parameter_set=second_parameter_set) # Form dataset - solution = self.getdata(second_model, self.ground_truth, init_soc) + solution = self.get_data(second_model, parameters, self.ground_truth, init_soc) dataset = pybop.Dataset( { "Time [s]": solution["Time [s]"].data, @@ -226,13 +222,8 @@ def test_model_misparameterisation(self, parameters, model, init_soc): np.testing.assert_allclose(final_cost, 0, atol=1e-2) np.testing.assert_allclose(x, self.ground_truth, atol=2e-2) - def getdata(self, model, x, init_soc): - model.parameter_set.update( - { - "Negative electrode active material volume fraction": x[0], - "Positive electrode active material volume fraction": x[1], - } - ) + def get_data(self, model, parameters, x, init_soc): + model.parameters = parameters experiment = pybop.Experiment( [ ( @@ -242,5 +233,5 @@ def getdata(self, model, x, init_soc): ] * 2 ) - sim = model.predict(init_soc=init_soc, experiment=experiment) + sim = model.predict(init_soc=init_soc, experiment=experiment, inputs=x) return sim diff --git a/tests/integration/test_thevenin_parameterisation.py b/tests/integration/test_thevenin_parameterisation.py index ed0ff154..cc2a52c6 100644 --- a/tests/integration/test_thevenin_parameterisation.py +++ b/tests/integration/test_thevenin_parameterisation.py @@ -49,7 +49,7 @@ def cost_class(self, request): @pytest.fixture def cost(self, model, parameters, cost_class): # Form dataset - solution = self.getdata(model, self.ground_truth) + solution = self.get_data(model, parameters, self.ground_truth) dataset = pybop.Dataset( { "Time [s]": solution["Time [s]"].data, @@ -88,13 +88,8 @@ def test_optimisers_on_simple_model(self, optimiser, cost): assert initial_cost > final_cost np.testing.assert_allclose(x, self.ground_truth, atol=1e-2) - def getdata(self, model, x): - model.parameter_set.update( - { - "R0 [Ohm]": x[0], - "R1 [Ohm]": x[1], - } - ) + def get_data(self, model, parameters, x): + model.parameters = parameters experiment = pybop.Experiment( [ ( @@ -103,5 +98,5 @@ def getdata(self, model, x): ), ] ) - sim = model.predict(experiment=experiment) + sim = model.predict(experiment=experiment, inputs=x) return sim