diff --git a/.github/workflows/test_on_push.yaml b/.github/workflows/test_on_pull_request.yaml similarity index 84% rename from .github/workflows/test_on_push.yaml rename to .github/workflows/test_on_pull_request.yaml index e2b6d19d9..2f74bbe32 100644 --- a/.github/workflows/test_on_push.yaml +++ b/.github/workflows/test_on_pull_request.yaml @@ -105,6 +105,37 @@ jobs: run: | nox -s examples + # Quick benchmarks on macos-14 + benchmarks: + needs: style + runs-on: macos-14 + strategy: + fail-fast: false + name: Benchmarks + + steps: + - name: Check out PyBOP repository + uses: actions/checkout@v4 + with: + fetch-depth: 2 + + - name: Set up Python 3.12 + id: setup-python + uses: actions/setup-python@v4 + with: + python-version: 3.12 + + - name: Install dependencies + shell: bash + run: | + python -m pip install --upgrade pip asv[virtualenv] + + - name: Run quick benchmarks + shell: bash + run: | + asv machine --machine "GitHubRunner" + asv run --machine "GitHubRunner" --quick --show-stderr + # Runs only on macos-14 with Python 3.12 check_coverage: needs: style diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ffd08853..aa292e013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ ## Bug Fixes +- [#454](https://github.com/pybop-team/PyBOP/issue/454) - Fixes benchmarking suite. - [#421](https://github.com/pybop-team/PyBOP/issues/421) - Adds a default value for the initial SOC for design problems. ## Breaking Changes diff --git a/asv.conf.json b/asv.conf.json index fdd830cea..e6b508e06 100644 --- a/asv.conf.json +++ b/asv.conf.json @@ -8,7 +8,7 @@ "python -m build --wheel -o {build_cache_dir} {build_dir}" ], "default_benchmark_timeout": 180, - "branches": ["develop"], + "branches": ["HEAD"], "environment_type": "virtualenv", "matrix": { "req":{ diff --git a/benchmarks/benchmark_model.py b/benchmarks/benchmark_model.py index 7a1720feb..2941cba88 100644 --- a/benchmarks/benchmark_model.py +++ b/benchmarks/benchmark_model.py @@ -26,19 +26,20 @@ def setup(self, model, parameter_set): self.model = model(parameter_set=pybop.ParameterSet.pybamm(parameter_set)) # Define fitting parameters - parameters = [ + parameters = pybop.Parameters( pybop.Parameter( "Current function [A]", prior=pybop.Gaussian(0.4, 0.02), bounds=[0.2, 0.7], initial_value=0.4, ) - ] + ) # Generate synthetic data sigma = 0.001 self.t_eval = np.arange(0, 900, 2) - values = self.model.predict(t_eval=self.t_eval) + self.init_state = {"Initial SoC": 0.5} + values = self.model.predict(t_eval=self.t_eval, initial_state=self.init_state) corrupt_values = values["Voltage [V]"].data + np.random.normal( 0, sigma, len(self.t_eval) ) @@ -58,7 +59,7 @@ def setup(self, model, parameter_set): # Create fitting problem self.problem = pybop.FittingProblem( - model=self.model, dataset=dataset, parameters=parameters, init_soc=0.5 + model=self.model, dataset=dataset, parameters=parameters ) def time_model_predict(self, model, parameter_set): @@ -69,7 +70,9 @@ def time_model_predict(self, model, parameter_set): model (pybop.Model): The model class being benchmarked. parameter_set (str): The name of the parameter set being used. """ - self.model.predict(inputs=self.inputs, t_eval=self.t_eval) + self.model.predict( + inputs=self.inputs, t_eval=self.t_eval, initial_state=self.init_state + ) def time_model_simulate(self, model, parameter_set): """ diff --git a/benchmarks/benchmark_optim_construction.py b/benchmarks/benchmark_optim_construction.py index 75bb28b3c..0849b4f38 100644 --- a/benchmarks/benchmark_optim_construction.py +++ b/benchmarks/benchmark_optim_construction.py @@ -28,7 +28,7 @@ def setup(self, model, parameter_set, optimiser): model_instance = model(parameter_set=pybop.ParameterSet.pybamm(parameter_set)) # Define fitting parameters - parameters = [ + parameters = pybop.Parameters( pybop.Parameter( "Negative electrode active material volume fraction", prior=pybop.Gaussian(0.6, 0.02), @@ -41,7 +41,7 @@ def setup(self, model, parameter_set, optimiser): bounds=[0.375, 0.625], initial_value=0.51, ), - ] + ) # Generate synthetic data sigma = 0.001 @@ -75,7 +75,7 @@ def time_optimisation_construction(self, model, parameter_set, optimiser): Args: model (pybop.Model): The model class being benchmarked. parameter_set (str): The name of the parameter set being used. - optimiser (pybop.Optimiser): The optimizer class being used. + optimiser (pybop.Optimiser): The optimiser class being used. """ self.optim = pybop.Optimisation(self.cost, optimiser=optimiser) @@ -86,6 +86,6 @@ def time_cost_evaluate(self, model, parameter_set, optimiser): Args: model (pybop.Model): The model class being benchmarked. parameter_set (str): The name of the parameter set being used. - optimiser (pybop.Optimiser): The optimizer class being used. + optimiser (pybop.Optimiser): The optimiser class being used. """ self.cost([0.63, 0.51]) diff --git a/benchmarks/benchmark_parameterisation.py b/benchmarks/benchmark_parameterisation.py index 681502387..9615f7876 100644 --- a/benchmarks/benchmark_parameterisation.py +++ b/benchmarks/benchmark_parameterisation.py @@ -29,7 +29,7 @@ def setup(self, model, parameter_set, optimiser): Args: model (pybop.Model): The model class to be benchmarked. parameter_set (str): The name of the parameter set to be used. - optimiser (pybop.Optimiser): The optimizer class to be used. + optimiser (pybop.Optimiser): The optimiser class to be used. """ # Set random seed set_random_seed() @@ -45,7 +45,7 @@ def setup(self, model, parameter_set, optimiser): model_instance = model(parameter_set=params) # Define fitting parameters - parameters = [ + parameters = pybop.Parameters( pybop.Parameter( "Negative electrode active material volume fraction", prior=pybop.Gaussian(0.55, 0.03), @@ -56,7 +56,7 @@ def setup(self, model, parameter_set, optimiser): prior=pybop.Gaussian(0.55, 0.03), bounds=[0.375, 0.7], ), - ] + ) # Generate synthetic data sigma = 0.003 @@ -110,7 +110,7 @@ def time_parameterisation(self, model, parameter_set, optimiser): Args: model (pybop.Model): The model class being benchmarked (unused). parameter_set (str): The name of the parameter set being used (unused). - optimiser (pybop.Optimiser): The optimizer class being used (unused). + optimiser (pybop.Optimiser): The optimiser class being used (unused). """ self.optim.run() diff --git a/benchmarks/benchmark_track_parameterisation.py b/benchmarks/benchmark_track_parameterisation.py index a420dd3b9..134adaf3d 100644 --- a/benchmarks/benchmark_track_parameterisation.py +++ b/benchmarks/benchmark_track_parameterisation.py @@ -45,7 +45,7 @@ def setup(self, model, parameter_set, optimiser): model_instance = model(parameter_set=params) # Define fitting parameters - parameters = [ + parameters = pybop.Parameters( pybop.Parameter( "Negative electrode active material volume fraction", prior=pybop.Gaussian(0.55, 0.03), @@ -56,7 +56,7 @@ def setup(self, model, parameter_set, optimiser): prior=pybop.Gaussian(0.55, 0.03), bounds=[0.375, 0.7], ), - ] + ) # Generate synthetic data sigma = 0.003 diff --git a/tests/unit/test_models.py b/tests/unit/test_models.py index 9fe434cfc..f1722366e 100644 --- a/tests/unit/test_models.py +++ b/tests/unit/test_models.py @@ -82,6 +82,12 @@ def test_predict_without_pybamm(self, model): ): model.predict(None, None) + # Test new_copy() without pybamm_model + if not isinstance(model, pybop.lithium_ion.MSMR): + new_model = model.new_copy() + assert new_model.pybamm_model is not None + assert new_model.parameter_set is not None + @pytest.mark.unit def test_predict_with_inputs(self, model): # Define inputs