Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkBlyth committed Aug 22, 2024
2 parents d1e84b9 + 86aa8fd commit ec0e12f
Show file tree
Hide file tree
Showing 89 changed files with 3,541 additions and 1,554 deletions.
1 change: 1 addition & 0 deletions .github/workflows/lychee_links.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
--exclude "https://a.tile.openstreetmap.org/*"
--exclude "https://openstreetmap.org/*|https://www.openstreetmap.org/*"
--exclude "https://cdn.plot.ly/*"
--exclude "http://www.w3.org/*|https://www.w3.org/*"
--exclude "https://doi.org/*"
--exclude-path ./CHANGELOG.md
--exclude-path asv.conf.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.5.6"
rev: "v0.6.1"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
## Features

- [#353](https://github.com/pybop-team/PyBOP/issues/353) - Allow user-defined check_params functions to enforce nonlinear constraints and enable SciPy constrained optimisation methods
- [#405](https://github.com/pybop-team/PyBOP/pull/405) - Adds frequency-domain based EIS prediction methods via `model.simulateEIS` and updates to `problem.evaluate` with examples and tests.
- [#460](https://github.com/pybop-team/PyBOP/pull/460) - Notebook example files added for ECM and folder structure updated.
- [#450](https://github.com/pybop-team/PyBOP/pull/450) - Adds support for IDAKLU with output variables, and corresponding examples, tests.
- [#364](https://github.com/pybop-team/PyBOP/pull/364) - Adds the MultiFittingProblem class and the multi_fitting example script.
- [#444](https://github.com/pybop-team/PyBOP/issues/444) - Merge `BaseModel` `build()` and `rebuild()` functionality.
- [#435](https://github.com/pybop-team/PyBOP/pull/435) - Adds SLF001 linting for private members.
- [#418](https://github.com/pybop-team/PyBOP/issues/418) - Wraps the `get_parameter_info` method from PyBaMM to get a dictionary of parameter names and types.
- [#413](https://github.com/pybop-team/PyBOP/pull/413) - Adds `DesignCost` functionality to `WeightedCost` class with additional tests.
- [#357](https://github.com/pybop-team/PyBOP/pull/357) - Adds `Transformation()` class with `LogTransformation()`, `IdentityTransformation()`, and `ScaledTransformation()`, `ComposedTransformation()` implementations with corresponding examples and tests.
Expand All @@ -13,10 +19,14 @@

## 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

- [#436](https://github.com/pybop-team/PyBOP/pull/436) - **API Change:** The functionality from `BaseCost.evaluate/S1` & `BaseCost._evaluate/S1` is represented in `BaseCost.__call__` & `BaseCost.compute`. `BaseCost.compute` directly acts on the predictions, while `BaseCost.__call__` calls `BaseProblem.evaluate/S1` before `BaseCost.compute`. `compute` has optional args for gradient cost calculations.
- [#424](https://github.com/pybop-team/PyBOP/issues/424) - Replaces the `init_soc` input to `FittingProblem` with the option to pass an initial OCV value, updates `BaseModel` and fixes `multi_model_identification.ipynb` and `spm_electrode_design.ipynb`.

# [v24.6.1](https://github.com/pybop-team/PyBOP/tree/v24.6.1) - 2024-07-31

## Features
Expand All @@ -25,6 +35,7 @@

## Bug Fixes


## Breaking Changes

# [v24.6](https://github.com/pybop-team/PyBOP/tree/v24.6) - 2024-07-08
Expand Down
12 changes: 8 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pip install -e .[all,dev]

Before you commit any code, please perform the following checks using [Nox](https://nox.thea.codes/en/stable/index.html):

- [All tests pass](#testing): `$ nox -s unit`
- [All tests pass](#testing): `$ nox -s quick`

### Installing and using pre-commit

Expand Down Expand Up @@ -83,16 +83,20 @@ PyBOP follows the [PEP8 recommendations](https://www.python.org/dev/peps/pep-000

### Ruff

We use [ruff](https://github.com/charliermarsh/ruff) to check our PEP8 adherence. To try this on your system, navigate to the PyBOP directory in a console and type
We use [ruff](https://github.com/charliermarsh/ruff) to lint and ensure adherence to Python PEP standards. To manually trigger `ruff`, navigate to the PyBOP directory in a console and type

```bash
python -m pip install pre-commit
pre-commit run ruff
```

ruff is configured inside the file `pre-commit-config.yaml`, allowing us to ignore some errors. If you think this should be added or removed, please submit an [issue](https://guides.github.com/features/issues/).
ruff is configured inside the file `pyproject.toml`, allowing us to ignore some errors. If you think a rule should be added or removed, please submit an [issue](https://guides.github.com/features/issues/).

When you commit your changes they will be checked against ruff automatically (see [Pre-commit checks](#pre-commit-checks)).
When you commit your changes they will be checked against ruff automatically (see [Pre-commit checks](#pre-commit-checks)). If you are having issues getting your commit to pass the linting, it
is possible to skip linting for single lines (this should only be done as a **last resort**) by adding a line comment of `#noqa: $ruff_rule` where the `$ruff_rule` is replaced with the rule in question.
It is also possible to skip linting altogether by committing your changes by using the
`--no-verify` command-line flag.
These rules can be found in the ruff configuration in `pyproject.toml` or in the failed pre-commit output. Please note the lint skipping in the pull request for reviewers.

### Naming

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": ["develop"],
"branches": ["HEAD"],
"environment_type": "virtualenv",
"matrix": {
"req":{
Expand Down
17 changes: 10 additions & 7 deletions benchmarks/benchmark_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand All @@ -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):
Expand All @@ -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):
"""
Expand All @@ -79,7 +82,7 @@ def time_model_simulate(self, model, parameter_set):
model (pybop.Model): The model class being benchmarked.
parameter_set (str): The name of the parameter set being used.
"""
self.problem._model.simulate(inputs=self.inputs, t_eval=self.t_eval)
self.problem.model.simulate(inputs=self.inputs, t_eval=self.t_eval)

def time_model_simulateS1(self, model, parameter_set):
"""
Expand All @@ -89,4 +92,4 @@ def time_model_simulateS1(self, model, parameter_set):
model (pybop.Model): The model class being benchmarked.
parameter_set (str): The name of the parameter set being used.
"""
self.problem._model.simulateS1(inputs=self.inputs, t_eval=self.t_eval)
self.problem.model.simulateS1(inputs=self.inputs, t_eval=self.t_eval)
8 changes: 4 additions & 4 deletions benchmarks/benchmark_optim_construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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])
8 changes: 4 additions & 4 deletions benchmarks/benchmark_parameterisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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),
Expand All @@ -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
Expand Down Expand Up @@ -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()

Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmark_track_parameterisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,7 @@
"outputs": [],
"source": [
"problem.set_target(dataset_two_pulse)\n",
"model.parameter_set[\"Initial SoC\"] = 0.8 - 0.0075\n",
"model.rebuild(dataset_two_pulse)"
"model.build(dataset=dataset_two_pulse, initial_state={\"Initial SoC\": 0.8 - 0.0075})"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/equivalent_circuit_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"\n",
"### Setting up the Environment\n",
"\n",
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP from its development branch and upgrade some dependencies:"
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP and upgrade dependencies:"
]
},
{
Expand Down
40 changes: 20 additions & 20 deletions examples/notebooks/multi_model_identification.ipynb

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions examples/notebooks/multi_optimiser_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"\n",
"### Setting up the Environment\n",
"\n",
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP from its development branch and upgrade some dependencies:"
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP and upgrade dependencies:"
]
},
{
Expand Down Expand Up @@ -115,8 +115,8 @@
"outputs": [],
"source": [
"t_eval = np.arange(0, 2000, 10)\n",
"init_soc = 1.0\n",
"values = synth_model.predict(t_eval=t_eval, init_soc=init_soc)"
"initial_state = {\"Initial SoC\": 1.0}\n",
"values = synth_model.predict(t_eval=t_eval, initial_state=initial_state)"
]
},
{
Expand Down Expand Up @@ -448,7 +448,8 @@
"source": [
"optims = []\n",
"xs = []\n",
"problem = pybop.FittingProblem(model, parameters, dataset, init_soc=init_soc)\n",
"model.set_initial_state(initial_state)\n",
"problem = pybop.FittingProblem(model, parameters, dataset)\n",
"cost = pybop.SumSquaredError(problem)\n",
"for optimiser in gradient_optimisers:\n",
" print(f\"Running {optimiser.__name__}\")\n",
Expand Down
12 changes: 6 additions & 6 deletions examples/notebooks/optimiser_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"\n",
"### Setting up the Environment\n",
"\n",
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP from its development branch and upgrade some dependencies:"
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP and upgrade dependencies:"
]
},
{
Expand Down Expand Up @@ -100,7 +100,7 @@
" }\n",
")\n",
"model = pybop.lithium_ion.SPM(parameter_set=parameter_set)\n",
"init_soc = 0.4\n",
"initial_state = {\"Initial SoC\": 0.4}\n",
"experiment = pybop.Experiment(\n",
" [\n",
" (\n",
Expand All @@ -110,7 +110,7 @@
" ]\n",
" * 2\n",
")\n",
"values = model.predict(init_soc=init_soc, experiment=experiment)"
"values = model.predict(initial_state=initial_state, experiment=experiment)"
]
},
{
Expand Down Expand Up @@ -240,7 +240,7 @@
}
],
"source": [
"problem = pybop.FittingProblem(model, parameters, dataset, init_soc=init_soc)\n",
"problem = pybop.FittingProblem(model, parameters, dataset)\n",
"cost = pybop.SumSquaredError(problem)\n",
"optim = pybop.GradientDescent(cost, sigma0=0.2, max_iterations=100)"
]
Expand Down Expand Up @@ -451,7 +451,7 @@
"optims = []\n",
"for sigma in sigmas:\n",
" print(sigma)\n",
" problem = pybop.FittingProblem(model, parameters, dataset, init_soc=init_soc)\n",
" problem = pybop.FittingProblem(model, parameters, dataset)\n",
" cost = pybop.SumSquaredError(problem)\n",
" optim = pybop.GradientDescent(cost, sigma0=sigma, max_iterations=100)\n",
" x, final_cost = optim.run()\n",
Expand Down Expand Up @@ -482,7 +482,7 @@
"source": [
"for optim, sigma in zip(optims, sigmas):\n",
" print(\n",
" f\"| Sigma: {sigma} | Num Iterations: {optim._iterations} | Best Cost: {optim.pints_optimiser.f_best()} | Results: {optim.pints_optimiser.x_best()} |\"\n",
" f\"| Sigma: {sigma} | Num Iterations: {optim.result.n_iterations} | Best Cost: {optim.pints_optimiser.f_best()} | Results: {optim.pints_optimiser.x_best()} |\"\n",
" )"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/notebooks/pouch_cell_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"\n",
"### Setting up the Environment\n",
"\n",
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP from its development branch and upgrade some dependencies:"
"Before we begin, we need to ensure that we have all the necessary tools. We will install PyBOP and upgrade dependencies:"
]
},
{
Expand Down
Loading

0 comments on commit ec0e12f

Please sign in to comment.