Skip to content

Commit

Permalink
Merge branch 'develop', updt __init__.py order, add Parameters type h…
Browse files Browse the repository at this point in the history
…ints
  • Loading branch information
BradyPlanden committed Jun 6, 2024
2 parents 2b3ee76 + 02cbb14 commit 1020428
Show file tree
Hide file tree
Showing 68 changed files with 906 additions and 678 deletions.
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.5"
rev: "v0.4.7"
hooks:
- id: ruff
args: [--fix, --show-fixes]
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

## Bug Fixes

- [#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.
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 @@ -232,7 +232,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.025),\n",
Expand All @@ -243,7 +243,7 @@
" prior=pybop.Gaussian(0.6, 0.025),\n",
" bounds=[0.5, 0.8],\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 1020428

Please sign in to comment.