Skip to content

Commit

Permalink
Add random seed, updt branch target, increment python for publish job…
Browse files Browse the repository at this point in the history
… in workflow
  • Loading branch information
BradyPlanden committed Mar 16, 2024
1 parent aa9a395 commit 8e6f609
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/periodic_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# - Publish website
name: Benchmarks
on:
push:
# Everyday at 12 pm UTC
schedule:
- cron: "0 12 * * *"
Expand Down Expand Up @@ -62,10 +61,10 @@ jobs:
runs-on: ubuntu-latest
if: github.repository == 'pybop-team/PyBOP'
steps:
- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: 3.11
python-version: 3.12

- name: Install asv
run: pip install asv
Expand Down
2 changes: 1 addition & 1 deletion asv.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"python -m build --wheel -o {build_cache_dir} {build_dir}"
],
"default_benchmark_timeout": 180,
"branches": ["179-add-airspeed-velocity-for-automated-benchmarking"],
"branches": ["develop"],
"environment_type": "virtualenv",
"matrix": {
"req":{
Expand Down
8 changes: 7 additions & 1 deletion benchmarks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ With `asv` installed and your benchmarks set up, you can now run benchmarks usin
To run all benchmarks in your python env:

```bash
asv run --python=same
asv run
```

This will test the current state of your codebase by default. You can specify a range of commits to run benchmarks against by appending a commit range to the command, like so:
Expand All @@ -57,6 +57,12 @@ This will test the current state of your codebase by default. You can specify a
asv run <commit-hash-1>..<commit-hash-2>
```

For quick benchmarking, pass the `--quick` argument to `asv run`. This runs each benchmark once and returns the singular value.

```bash
asv run --quick
```

### Running Specific Benchmarks

To run a specific benchmark, use:
Expand Down
4 changes: 4 additions & 0 deletions benchmarks/benchmark_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pybop
import numpy as np
from .benchmark_utils import set_random_seed


class BenchmarkModel:
Expand All @@ -17,6 +18,9 @@ def setup(self, model, parameter_set):
model (pybop.Model): The model class to be benchmarked.
parameter_set (str): The name of the parameter set to be used.
"""
# Set random seed
set_random_seed()

# Create model instance
self.model = model(parameter_set=pybop.ParameterSet.pybamm(parameter_set))

Expand Down
6 changes: 5 additions & 1 deletion benchmarks/benchmark_optim_construction.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pybop
import numpy as np
from .benchmark_utils import set_random_seed


class BenchmarkOptimisationConstruction:
Expand All @@ -19,6 +20,9 @@ def setup(self, model, parameter_set, optimiser):
parameter_set (str): The name of the parameter set to be used.
optimiser (pybop.Optimiser): The optimizer class to be used.
"""
# Set random seed
set_random_seed()

# Create model instance
model_instance = model(parameter_set=pybop.ParameterSet.pybamm(parameter_set))

Expand Down Expand Up @@ -74,7 +78,7 @@ def time_optimisation_construction(self, model, parameter_set, optimiser):
"""
self.optim = pybop.Optimisation(self.cost, optimiser=optimiser)

def time_cost(self, model, parameter_set, optimiser):
def time_cost_evaluate(self, model, parameter_set, optimiser):
"""
Benchmark the cost function evaluation.
Expand Down
5 changes: 5 additions & 0 deletions benchmarks/benchmark_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import numpy as np


def set_random_seed(seed_value=8):
np.random.seed(seed_value)
6 changes: 5 additions & 1 deletion benchmarks/parameterisation_benchmark.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import pybop
import numpy as np
from .benchmark_utils import set_random_seed


class ParameterisationBenchmark:
class BenchmarkParameterisation:
param_names = ["model", "parameter_set", "optimiser"]
params = [
[pybop.lithium_ion.SPM, pybop.lithium_ion.SPMe],
Expand All @@ -29,6 +30,9 @@ def setup(self, model, parameter_set, optimiser):
parameter_set (str): The name of the parameter set to be used.
optimiser (pybop.Optimiser): The optimizer class to be used.
"""
# Set random seed
set_random_seed()

# Create model instance
model_instance = model(parameter_set=pybop.ParameterSet.pybamm(parameter_set))

Expand Down

0 comments on commit 8e6f609

Please sign in to comment.