Skip to content

Commit

Permalink
Merge branch 'develop' into 307-add-cuckoo-optimiser
Browse files Browse the repository at this point in the history
  • Loading branch information
BradyPlanden committed Jun 6, 2024
2 parents d0f56f3 + fd171d0 commit ff0ec36
Show file tree
Hide file tree
Showing 82 changed files with 1,449 additions and 1,096 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@
"financial"
]
},
{
"login": "IntelLiGent",
"name": "Horizon Europe IntelLiGent Consortium",
"avatar_url": "assets/logo-farger.pdf",
"profile": "https://heuintelligent.eu/",
"contributions": [
"financial"
]
},
{
"login": "muhammedsogut",
"name": "Muhammed Nedim Sogut",
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/periodic_benchmarks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
# - Publish website
name: Benchmarks
on:
# Everyday at 12 pm UTC
# Every Monday and Thursday at 12 pm UTC
schedule:
- cron: "0 12 * * *"
- cron: "0 12 * * 1,4"
# Make it possible to trigger the
# workflow manually
workflow_dispatch:
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/scheduled_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ on:
branches:
- main

# runs every day at 09:00 and 15:00 UTC
# runs every day at 09:00 UTC
schedule:
- cron: '0 9 * * *'
- cron: '0 15 * * *'

# Check noxfile.py for associated environment variables
env:
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.4.4"
rev: "v0.4.7"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- [#315](https://github.com/pybop-team/PyBOP/pull/315) - Updates __init__ structure to remove circular import issues and minimises dependancy imports across codebase for faster PyBOP module import. Adds type-hints to BaseModel and refactors rebuild parameter variables.
- [#236](https://github.com/pybop-team/PyBOP/issues/236) - Restructures the optimiser classes, adds a new optimisation API through direct construction and keyword arguments, and fixes the setting of `max_iterations`, and `_minimising`. Introduces `pybop.BaseOptimiser`, `pybop.BasePintsOptimiser`, and `pybop.BaseSciPyOptimiser` classes.
- [#321](https://github.com/pybop-team/PyBOP/pull/321) - Updates Prior classes with BaseClass, adds a `problem.sample_initial_conditions` method to improve stability of SciPy.Minimize optimiser.
- [#249](https://github.com/pybop-team/PyBOP/pull/249) - Add WeppnerHuggins model and GITT example.
Expand All @@ -13,14 +14,16 @@
- [#273](https://github.com/pybop-team/PyBOP/pull/273) - Adds notebooks to nox examples session and updates CI workflows for change.
- [#250](https://github.com/pybop-team/PyBOP/pull/250) - Adds DFN, MPM, MSMR models and moves multiple construction variables to BaseEChem. Adds exception catch on simulate & simulateS1.
- [#241](https://github.com/pybop-team/PyBOP/pull/241) - Adds experimental circuit model fitting notebook with LG M50 data.
- [#268](https://github.com/pybop-team/PyBOP/pull/268) - Fixes the GitHub Release artifact uploads, allowing verification of
codesigned binaries and source distributions via `sigstore-python`.
- [#268](https://github.com/pybop-team/PyBOP/pull/268) - Fixes the GitHub Release artifact uploads, allowing verification of codesigned binaries and source distributions via `sigstore-python`.
- [#79](https://github.com/pybop-team/PyBOP/issues/79) - Adds BPX as a dependency and imports BPX support from PyBaMM.
- [#267](https://github.com/pybop-team/PyBOP/pull/267) - Add classifiers to pyproject.toml, update project.urls.
- [#195](https://github.com/pybop-team/PyBOP/issues/195) - Adds the Nelder-Mead optimiser from PINTS as another option.

## Bug Fixes

- [#347](https://github.com/pybop-team/PyBOP/issues/347) - Resets options between MSMR tests to cope with a bug in PyBaMM v23.9 which is fixed in PyBaMM v24.1.
- [#337](https://github.com/pybop-team/PyBOP/issues/337) - Restores benchmarks, relaxes CI schedule for benchmarks and scheduled tests.
- [#231](https://github.com/pybop-team/PyBOP/issues/231) - Allows passing of keyword arguments to PyBaMM models and disables build on initialisation.
- [#321](https://github.com/pybop-team/PyBOP/pull/321) - Improves `integration/test_spm_parameterisation.py` stability, adds flakly pytest plugin, and `test_thevenin_parameterisation.py` integration test.
- [#330](https://github.com/pybop-team/PyBOP/issues/330) - Fixes implementation of default plotting options.
- [#317](https://github.com/pybop-team/PyBOP/pull/317) - Installs seed packages into `nox` sessions, ensuring that scheduled tests can pass.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://faraday.ac.uk"><img src="assets/faraday-logo.jpg?s=100" width="100px;" alt="Faraday Institution"/><br /><sub><b>Faraday Institution</b></sub></a><br /><a href="#financial-FaradayInstitution" title="Financial">💵</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.ukri.org/"><img src="assets/UKRI.png?s=100" width="100px;" alt="UK Research and Innovation"/><br /><sub><b>UK Research and Innovation</b></sub></a><br /><a href="#financial-UKRI" title="Financial">💵</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://heuintelligent.eu/"><img src="assets/logo-farger.svg" width="100px;" alt="EU IntelLiGent Project"/><br /><sub><b>IntelLiGent Consortium</b></sub></a><br /><a href="#financial-UKRI" title="Financial">💵</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://www.linkedin.com/in/muhammedsogut/"><img src="https://avatars.githubusercontent.com/u/34511375?v=4?s=100" width="100px;" alt="Muhammed Nedim Sogut"/><br /><sub><b>Muhammed Nedim Sogut</b></sub></a><br /><a href="https://github.com/pybop-team/PyBOP/commits?author=muhammedsogut" title="Code">💻</a></td>
</tr>
</tbody>
Expand Down
30 changes: 20 additions & 10 deletions benchmarks/benchmark_parameterisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,26 @@ def setup(self, model, parameter_set, optimiser):
# Create cost function
cost = pybop.SumSquaredError(problem=problem)

# Create optimization instance
self.optim = pybop.Optimisation(cost, optimiser=optimiser)
# Create optimization instance and set options for consistent benchmarking
if optimiser in [pybop.GradientDescent]:
self.optim.optimiser.set_learning_rate(
0.008
) # Compromise between stability & performance
self.optim = pybop.Optimisation(
cost,
optimiser=optimiser,
max_iterations=250,
max_unchanged_iterations=25,
threshold=1e-5,
min_iterations=2,
learning_rate=0.008, # Compromise between stability & performance
)
else:
self.optim = pybop.Optimisation(
cost,
optimiser=optimiser,
max_iterations=250,
max_unchanged_iterations=25,
threshold=1e-5,
min_iterations=2,
)

def time_parameterisation(self, model, parameter_set, optimiser):
"""
Expand All @@ -99,10 +113,6 @@ def time_parameterisation(self, model, parameter_set, optimiser):
parameter_set (str): The name of the parameter set being used (unused).
optimiser (pybop.Optimiser): The optimizer class being used (unused).
"""
# Set optimizer options for consistent benchmarking
self.optim.set_max_unchanged_iterations(iterations=25, threshold=1e-5)
self.optim.set_max_iterations(250)
self.optim.set_min_iterations(2)
self.optim.run()

def time_optimiser_ask(self, model, parameter_set, optimiser):
Expand All @@ -115,4 +125,4 @@ def time_optimiser_ask(self, model, parameter_set, optimiser):
optimiser (pybop.Optimiser): The optimizer class being used.
"""
if optimiser not in [pybop.SciPyMinimize, pybop.SciPyDifferentialEvolution]:
self.optim.optimiser.ask()
self.optim.pints_optimiser.ask()
29 changes: 19 additions & 10 deletions benchmarks/benchmark_track_parameterisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,26 @@ def setup(self, model, parameter_set, optimiser):
# Create cost function
cost = pybop.SumSquaredError(problem=problem)

# Create optimization instance
self.optim = pybop.Optimisation(cost, optimiser=optimiser)
# Create optimization instance and set options for consistent benchmarking
if optimiser in [pybop.GradientDescent]:
self.optim.optimiser.set_learning_rate(
0.008
) # Compromise between stability & performance
self.optim = pybop.Optimisation(
cost,
optimiser=optimiser,
max_iterations=250,
max_unchanged_iterations=25,
threshold=1e-5,
min_iterations=2,
learning_rate=0.008, # Compromise between stability & performance
)
else:
self.optim = pybop.Optimisation(
cost,
optimiser=optimiser,
max_iterations=250,
max_unchanged_iterations=25,
threshold=1e-5,
min_iterations=2,
)

# Track output results
self.x = self.results_tracking(model, parameter_set, optimiser)
Expand All @@ -110,10 +124,5 @@ def results_tracking(self, model, parameter_set, optimiser):
parameter_set (str): The name of the parameter set being used (unused).
optimiser (pybop.Optimiser): The optimizer class being used (unused).
"""

# Set optimizer options for consistent benchmarking
self.optim.set_max_unchanged_iterations(iterations=25, threshold=1e-5)
self.optim.set_max_iterations(250)
self.optim.set_min_iterations(2)
x, _ = self.optim.run()
return x
Original file line number Diff line number Diff line change
Expand Up @@ -1467,7 +1467,7 @@
"id": "bf63b4f9-de38-4e70-9472-1de4973a0954",
"metadata": {},
"source": [
"In this example, we are going to try to fit all five parameters at once. To do this, we define a `pybop.parameter` for each fitting parameter as,"
"In this example, we are going to try to fit all five parameters at once. To do this, we define a `pybop.Parameter` for each fitting parameter and compile them in pybop.Parameters,"
]
},
{
Expand All @@ -1484,7 +1484,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"R0 [Ohm]\",\n",
" prior=pybop.Gaussian(0.005, 0.0001),\n",
Expand All @@ -1510,7 +1510,7 @@
" prior=pybop.Gaussian(3000, 2500),\n",
" bounds=[0.5, 1e4],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions examples/notebooks/equivalent_circuit_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@
"id": "bf63b4f9-de38-4e70-9472-1de4973a0954",
"metadata": {},
"source": [
"In this example, we are going to try to fit all five parameters at once. This isn't recommend for real-life application as identifiablity is challenging to guarantee with this large a parameter space. To do this, we define the `pybop.parameters` as,"
"In this example, we are going to try to fit all five parameters at once. This isn't recommend for real-life application as identifiablity is challenging to guarantee with this large a parameter space. To do this, we define the `pybop.Parameters` as,"
]
},
{
Expand All @@ -256,7 +256,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"R0 [Ohm]\",\n",
" prior=pybop.Gaussian(0.0002, 0.0001),\n",
Expand All @@ -278,11 +278,11 @@
" bounds=[2500, 5e4],\n",
" ),\n",
" pybop.Parameter(\n",
" \"C1 [F]\",\n",
" \"C2 [F]\",\n",
" prior=pybop.Gaussian(10000, 2500),\n",
" bounds=[2500, 5e4],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/multi_model_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3729,7 +3729,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"Positive electrode thickness [m]\",\n",
" prior=pybop.Gaussian(7.56e-05, 0.05e-05),\n",
Expand All @@ -3742,7 +3742,7 @@
" bounds=[65e-06, 90e-06],\n",
" true_value=parameter_set[\"Negative electrode thickness [m]\"],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/multi_optimiser_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"Negative electrode active material volume fraction\",\n",
" prior=pybop.Gaussian(0.6, 0.02),\n",
Expand All @@ -270,7 +270,7 @@
" prior=pybop.Gaussian(0.48, 0.02),\n",
" bounds=[0.4, 0.7],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/optimiser_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"Negative electrode active material volume fraction\",\n",
" prior=pybop.Uniform(0.45, 0.7),\n",
Expand All @@ -262,7 +262,7 @@
" bounds=[0.4, 0.8],\n",
" true_value=0.51,\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
12 changes: 5 additions & 7 deletions examples/notebooks/optimiser_interface.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,11 @@
")\n",
"\n",
"# Define the parameters\n",
"parameters = [\n",
" pybop.Parameter(\n",
" \"R0 [Ohm]\",\n",
" prior=pybop.Gaussian(0.0002, 0.0001),\n",
" bounds=[1e-4, 1e-2],\n",
" )\n",
"]\n",
"parameters = pybop.Parameter(\n",
" \"R0 [Ohm]\",\n",
" prior=pybop.Gaussian(0.0002, 0.0001),\n",
" bounds=[1e-4, 1e-2],\n",
")\n",
"\n",
"# Generate synthetic data\n",
"t_eval = np.arange(0, 900, 2)\n",
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/pouch_cell_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"Negative electrode active material volume fraction\",\n",
" prior=pybop.Gaussian(0.7, 0.05),\n",
Expand All @@ -334,7 +334,7 @@
" prior=pybop.Gaussian(0.58, 0.05),\n",
" bounds=[0.5, 0.8],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions examples/notebooks/spm_electrode_design.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
},
"outputs": [],
"source": [
"parameters = [\n",
"parameters = pybop.Parameters(\n",
" pybop.Parameter(\n",
" \"Positive electrode thickness [m]\",\n",
" prior=pybop.Gaussian(7.56e-05, 0.05e-05),\n",
Expand All @@ -154,7 +154,7 @@
" prior=pybop.Gaussian(5.22e-06, 0.05e-06),\n",
" bounds=[2e-06, 9e-06],\n",
" ),\n",
"]"
")"
]
},
{
Expand Down
12 changes: 3 additions & 9 deletions examples/scripts/BPX_spm.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
model = pybop.lithium_ion.SPM(parameter_set=parameter_set)

# Fitting parameters
parameters = [
parameters = pybop.Parameters(
pybop.Parameter(
"Negative particle radius [m]",
prior=pybop.Gaussian(6e-06, 0.1e-6),
Expand All @@ -23,7 +23,7 @@
bounds=[1e-7, 9e-7],
true_value=parameter_set["Positive particle radius [m]"],
),
]
)

# Generate data
sigma = 0.001
Expand All @@ -47,13 +47,7 @@

# Run the optimisation
x, final_cost = optim.run()
print(
"True parameters:",
[
parameters[0].true_value,
parameters[1].true_value,
],
)
print("True parameters:", parameters.true_value())
print("Estimated parameters:", x)

# Plot the timeseries output
Expand Down
4 changes: 2 additions & 2 deletions examples/scripts/ecm_CMAES.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
)

# Fitting parameters
parameters = [
parameters = pybop.Parameters(
pybop.Parameter(
"R0 [Ohm]",
prior=pybop.Gaussian(0.0002, 0.0001),
Expand All @@ -56,7 +56,7 @@
prior=pybop.Gaussian(0.0001, 0.0001),
bounds=[1e-5, 1e-2],
),
]
)

sigma = 0.001
t_eval = np.arange(0, 900, 3)
Expand Down
Loading

0 comments on commit ff0ec36

Please sign in to comment.