Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure optimisers to enable passing of kwargs #255

Merged
merged 95 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
8aef4f9
Enable passing of kwargs to SciPy
NicolaCourtier Mar 23, 2024
5e1843d
Update checks on bounds
NicolaCourtier Mar 23, 2024
6513e9c
style: pre-commit fixes
pre-commit-ci[bot] Mar 23, 2024
ffc3a4e
Change assert False to not
NicolaCourtier Mar 23, 2024
c56d9e6
Add update_options and error for Pints
NicolaCourtier Mar 23, 2024
0a53eb3
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Mar 27, 2024
22ab3b1
Rename opt to optim
NicolaCourtier Mar 27, 2024
0169420
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 9, 2024
4a1f0e0
Remove stray comments
NicolaCourtier Apr 11, 2024
833ecfe
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 12, 2024
129b999
Add BaseSciPyOptimiser and BasePintsOptimiser
NicolaCourtier Apr 14, 2024
762c714
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 14, 2024
d43b101
style: pre-commit fixes
pre-commit-ci[bot] Apr 14, 2024
710d49e
Align optimiser option setting
NicolaCourtier Apr 16, 2024
00d2815
Update notebooks with kwargs
NicolaCourtier Apr 16, 2024
3d7d9b8
Update scripts with kwargs
NicolaCourtier Apr 16, 2024
7e098e7
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 22, 2024
d91e727
Complete merge
NicolaCourtier Apr 22, 2024
9125b6a
style: pre-commit fixes
pre-commit-ci[bot] Apr 22, 2024
ea8e9a0
Update notebooks
NicolaCourtier Apr 22, 2024
b48e6d7
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 22, 2024
a8e60aa
Align optimisers with Optimisation as base class
NicolaCourtier Apr 22, 2024
a496ae2
Update stopping criteria in spm_NelderMead.py
NicolaCourtier Apr 22, 2024
ddf2afa
Update stopping criteria in spm_adam.py
NicolaCourtier Apr 22, 2024
d4dd9d2
Update sigma0 in spm_descent.py
NicolaCourtier Apr 22, 2024
88267cc
Update description
NicolaCourtier Apr 22, 2024
967754b
Update GradientDescent
NicolaCourtier Apr 22, 2024
73e78de
Change update to set and check pint_method
NicolaCourtier Apr 22, 2024
fe1a029
Merge branch '236-scipy-kwargs' of https://github.com/pybop-team/PyBO…
NicolaCourtier Apr 22, 2024
8e2cfdf
Update test_optimisation_options
NicolaCourtier Apr 22, 2024
078955a
Update notebooks
NicolaCourtier Apr 23, 2024
524f344
Update set learning rate
NicolaCourtier Apr 23, 2024
65e59d6
Pop threshold
NicolaCourtier Apr 23, 2024
9b3fea2
Fix bug in model.simulate
NicolaCourtier Apr 23, 2024
c6cc8cf
Update notebooks
NicolaCourtier Apr 23, 2024
4cb30f3
Update test_models.py
NicolaCourtier Apr 23, 2024
b2ada21
Store SciPy result
NicolaCourtier Apr 23, 2024
89b8020
Update x0 input and add tests
NicolaCourtier Apr 23, 2024
8e3d756
Update bounds to avoid x0 outside
NicolaCourtier Apr 23, 2024
85e1fe5
Re-initialise pints_method on certain options
NicolaCourtier Apr 23, 2024
9b3fca3
Update x0_new test
NicolaCourtier Apr 23, 2024
62fcb60
Update test_optimisation.py
NicolaCourtier Apr 23, 2024
91b86de
Update test_optimisation.py
NicolaCourtier Apr 23, 2024
b5fb981
Create initialise_method for PINTS optimisers
NicolaCourtier Apr 23, 2024
08e752f
Align optimisation result
NicolaCourtier Apr 23, 2024
e48e91b
Update checks on bounds
NicolaCourtier Apr 23, 2024
d65e0f5
Make DefaultOptimiser a subclass
NicolaCourtier Apr 23, 2024
be879e2
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier Apr 26, 2024
936b159
Reset
NicolaCourtier Apr 27, 2024
5800c75
Reset semicolons
NicolaCourtier Apr 27, 2024
0fdd511
Apply suggestions
NicolaCourtier Apr 27, 2024
04b3d03
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier May 9, 2024
dc1eb62
Add standalone optimiser
NicolaCourtier May 9, 2024
f192426
Simplify optimiser set-up and align _minimising
NicolaCourtier May 9, 2024
4ae9418
Update option setting in notebooks
NicolaCourtier May 9, 2024
06758e2
Take abs of cost0
NicolaCourtier May 9, 2024
44b5b2e
Update comment
NicolaCourtier May 9, 2024
71b4b88
style: pre-commit fixes
pre-commit-ci[bot] May 9, 2024
811ab21
Implement suggestions from Brady
NicolaCourtier May 9, 2024
7391626
style: pre-commit fixes
pre-commit-ci[bot] May 9, 2024
40954c1
Remove unnecessary lines
NicolaCourtier May 9, 2024
6c2de22
Rename base_optimiser.py to base_pints_optimiser.py
NicolaCourtier May 9, 2024
5d40930
Update filename in nit
NicolaCourtier May 9, 2024
6c0c7f1
Revert "Update filename in nit"
NicolaCourtier May 9, 2024
17ae9ec
Revert "Rename base_optimiser.py to base_pints_optimiser.py"
NicolaCourtier May 9, 2024
3d18ad3
Update tests and base option setting
NicolaCourtier May 9, 2024
b831ad4
Update test_invalid_cost
NicolaCourtier May 9, 2024
769db0d
Increase coverage
NicolaCourtier May 9, 2024
402f8c9
Increase coverage
NicolaCourtier May 9, 2024
192231e
Sort out notebook changes
NicolaCourtier May 10, 2024
7d0b654
Merge branch 'develop' into 236-scipy-kwargs
NicolaCourtier May 17, 2024
b59833f
Fix merge
NicolaCourtier May 17, 2024
4be3103
Reset scale parameter
NicolaCourtier May 17, 2024
1419111
Move settings into arguments
NicolaCourtier May 17, 2024
4237ad5
Update comments
NicolaCourtier May 17, 2024
4991a37
Update optimiser call
NicolaCourtier May 17, 2024
ec027a5
Move check on jac
NicolaCourtier May 17, 2024
40c91ee
Add assertions
NicolaCourtier May 17, 2024
b663396
Add maxiter to test
NicolaCourtier May 17, 2024
e2ae1dd
Add assertion
NicolaCourtier May 17, 2024
aa73bff
Update to lambda functions
NicolaCourtier May 17, 2024
9fa1155
Update comment
NicolaCourtier May 17, 2024
dd6446b
Update to list comprehension
NicolaCourtier May 17, 2024
dc04f47
Formatting
NicolaCourtier May 17, 2024
da2b742
Revert "Update to lambda functions"
NicolaCourtier May 17, 2024
1627754
Move minimising out of costs
NicolaCourtier May 17, 2024
2c61500
Improve conditioning of StandaloneCost
NicolaCourtier May 17, 2024
658181e
Reset StandaloneCost
NicolaCourtier May 20, 2024
afaf69e
Update description
NicolaCourtier May 20, 2024
dec74d7
Updates to #236 to avoid breaking change to `pybop.Optimisation` (#309)
BradyPlanden May 22, 2024
f1fc913
Rename method back to optimiser
NicolaCourtier May 22, 2024
2f3690b
Update comments
NicolaCourtier May 22, 2024
55abec8
Change optimiser to pints_optimiser
NicolaCourtier May 22, 2024
8f73469
Rename base_optimiser to pints_base_optimiser
NicolaCourtier May 22, 2024
6b37c3f
Rename _optimisation to base_optimiser
NicolaCourtier May 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- [#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.
- [#304](https://github.com/pybop-team/PyBOP/pull/304) - Decreases the testing suite completion time.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,7 @@
}
],
"source": [
"optim = pybop.Optimisation(cost, optimiser=pybop.PSO)\n",
"optim.set_max_unchanged_iterations(iterations=55, threshold=1e-6)\n",
"optim = pybop.PSO(cost, max_unchanged_iterations=55, threshold=1e-6)\n",
"x, final_cost = optim.run()\n",
"print(\"Initial parameters:\", cost.x0)\n",
"print(\"Estimated parameters:\", x)"
Expand Down
3 changes: 1 addition & 2 deletions examples/notebooks/equivalent_circuit_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,7 @@
}
],
"source": [
"optim = pybop.Optimisation(cost, optimiser=pybop.CMAES)\n",
"optim.set_max_iterations(300)\n",
"optim = pybop.CMAES(cost, max_iterations=300)\n",
"x, final_cost = optim.run()\n",
"print(\"Initial parameters:\", cost.x0)\n",
"print(\"Estimated parameters:\", x)"
Expand Down
6 changes: 3 additions & 3 deletions examples/notebooks/multi_model_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3813,9 +3813,9 @@
" print(f\"Running {model.name}\")\n",
" problem = pybop.FittingProblem(model, parameters, dataset, init_soc=init_soc)\n",
" cost = pybop.SumSquaredError(problem)\n",
" optim = pybop.Optimisation(cost, optimiser=pybop.XNES, verbose=True)\n",
" optim.set_max_iterations(60)\n",
" optim.set_max_unchanged_iterations(15)\n",
" optim = pybop.XNES(\n",
" cost, verbose=True, max_iterations=60, max_unchanged_iterations=15\n",
" )\n",
" x, final_cost = optim.run()\n",
" optims.append(optim)\n",
" xs.append(x)"
Expand Down
29 changes: 7 additions & 22 deletions examples/notebooks/multi_optimiser_identification.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,7 @@
"cost = pybop.SumSquaredError(problem)\n",
"for optimiser in gradient_optimisers:\n",
" print(f\"Running {optimiser.__name__}\")\n",
" optim = pybop.Optimisation(cost, optimiser=optimiser)\n",
" optim.set_max_unchanged_iterations(20)\n",
" optim.set_max_iterations(60)\n",
" optim = optimiser(cost, max_unchanged_iterations=20, max_iterations=60)\n",
" x, _ = optim.run()\n",
" optims.append(optim)\n",
" xs.append(x)"
Expand All @@ -387,9 +385,7 @@
"source": [
"for optimiser in non_gradient_optimisers:\n",
" print(f\"Running {optimiser.__name__}\")\n",
" optim = pybop.Optimisation(cost, optimiser=optimiser)\n",
" optim.set_max_unchanged_iterations(20)\n",
" optim.set_max_iterations(60)\n",
" optim = optimiser(cost, max_unchanged_iterations=20, max_iterations=60)\n",
" x, _ = optim.run()\n",
" optims.append(optim)\n",
" xs.append(x)"
Expand All @@ -413,9 +409,7 @@
"source": [
"for optimiser in scipy_optimisers:\n",
" print(f\"Running {optimiser.__name__}\")\n",
" optim = pybop.Optimisation(cost, optimiser=optimiser)\n",
" optim.set_max_unchanged_iterations(20)\n",
" optim.set_max_iterations(60)\n",
" optim = optimiser(cost, max_iterations=60)\n",
" x, _ = optim.run()\n",
" optims.append(optim)\n",
" xs.append(x)"
Expand Down Expand Up @@ -462,14 +456,7 @@
],
"source": [
"for optim in optims:\n",
" if isinstance(\n",
" optim.optimiser, (pybop.SciPyMinimize, pybop.SciPyDifferentialEvolution)\n",
" ):\n",
" print(f\"| Optimiser: {optim.optimiser.name()} | Results: {optim.result.x} |\")\n",
" else:\n",
" print(\n",
" f\"| Optimiser: {optim.optimiser.name()} | Results: {optim.optimiser.x_best()} |\"\n",
" )"
" print(f\"| Optimiser: {optim.name()} | Results: {optim.result.x} |\")"
]
},
{
Expand Down Expand Up @@ -612,9 +599,7 @@
],
"source": [
"for optim, x in zip(optims, xs):\n",
" pybop.quick_plot(\n",
" optim.cost.problem, parameter_values=x, title=optim.optimiser.name()\n",
" )"
" pybop.quick_plot(optim.cost.problem, parameter_values=x, title=optim.name())"
]
},
{
Expand Down Expand Up @@ -822,7 +807,7 @@
],
"source": [
"for optim in optims:\n",
" pybop.plot_convergence(optim, title=optim.optimiser.name())\n",
" pybop.plot_convergence(optim, title=optim.name())\n",
" pybop.plot_parameters(optim)"
]
},
Expand Down Expand Up @@ -942,7 +927,7 @@
"# Plot the cost landscape with optimisation path and updated bounds\n",
"bounds = np.array([[0.5, 0.8], [0.55, 0.8]])\n",
"for optim in optims:\n",
" pybop.plot2d(optim, bounds=bounds, steps=10, title=optim.optimiser.name())"
" pybop.plot2d(optim, bounds=bounds, steps=10, title=optim.name())"
]
},
{
Expand Down
10 changes: 4 additions & 6 deletions examples/notebooks/optimiser_calibration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@
"source": [
"problem = pybop.FittingProblem(model, parameters, dataset)\n",
"cost = pybop.SumSquaredError(problem)\n",
"optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent, sigma0=0.2)\n",
"optim.set_max_iterations(100)"
"optim = pybop.GradientDescent(cost, sigma0=0.2, max_iterations=100)"
]
},
{
Expand Down Expand Up @@ -456,8 +455,7 @@
" print(sigma)\n",
" problem = pybop.FittingProblem(model, parameters, dataset)\n",
" cost = pybop.SumSquaredError(problem)\n",
" optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent, sigma0=sigma)\n",
" optim.set_max_iterations(100)\n",
" optim = pybop.GradientDescent(cost, sigma0=sigma, max_iterations=100)\n",
" x, final_cost = optim.run()\n",
" optims.append(optim)\n",
" xs.append(x)"
Expand Down Expand Up @@ -490,7 +488,7 @@
"source": [
"for optim, sigma in zip(optims, sigmas):\n",
" print(\n",
" f\"| Sigma: {sigma} | Num Iterations: {optim._iterations} | Best Cost: {optim.optimiser.f_best()} | Results: {optim.optimiser.x_best()} |\"\n",
" f\"| Sigma: {sigma} | Num Iterations: {optim._iterations} | Best Cost: {optim.pints_optimiser.f_best()} | Results: {optim.pints_optimiser.x_best()} |\"\n",
" )"
]
},
Expand Down Expand Up @@ -723,7 +721,7 @@
}
],
"source": [
"optim = pybop.Optimisation(cost, optimiser=pybop.GradientDescent, sigma0=0.0115)\n",
"optim = pybop.GradientDescent(cost, sigma0=0.0115)\n",
"x, final_cost = optim.run()\n",
"pybop.quick_plot(problem, parameter_values=x, title=\"Optimised Comparison\");"
]
Expand Down
Loading
Loading