Skip to content

Commit

Permalink
Merge pull request #381 from pybop-team/380-bug-self_boundaries-not-c…
Browse files Browse the repository at this point in the history
…reated-for-pyboppso

Restore boundaries to pybop.PSO
  • Loading branch information
BradyPlanden authored Jul 3, 2024
2 parents 401c27f + 76b59f1 commit 1fa9d36
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

## Bug Fixes

- [#380](https://github.com/pybop-team/PyBOP/pull/380) - Restore self._boundaries construction for `pybop.PSO`
- [#372](https://github.com/pybop-team/PyBOP/pull/372) - Converts `np.array` to `np.asarray` for Numpy v2.0 support.
- [#165](https://github.com/pybop-team/PyBOP/issues/165) - Stores the attempted and best parameter values and the best cost for each iteration in the log attribute of the optimiser and updates the associated plots.
- [#354](https://github.com/pybop-team/PyBOP/issues/354) - Fixes the calculation of the gradient in the `RootMeanSquaredError` cost.
Expand Down
24 changes: 11 additions & 13 deletions pybop/optimisers/base_pints_optimiser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,20 @@ def _sanitise_inputs(self):

# Convert bounds to PINTS boundaries
if self.bounds is not None:
if issubclass(
self.pints_optimiser,
(PintsGradientDescent, PintsAdam, PintsNelderMead),
):
ignored_optimisers = (PintsGradientDescent, PintsAdam, PintsNelderMead)
if issubclass(self.pints_optimiser, ignored_optimisers):
print(f"NOTE: Boundaries ignored by {self.pints_optimiser}")
self.bounds = None
elif issubclass(self.pints_optimiser, PintsPSO):
if not all(
np.isfinite(value)
for sublist in self.bounds.values()
for value in sublist
):
raise ValueError(
"Either all bounds or no bounds must be set for Pints PSO."
)
else:
if issubclass(self.pints_optimiser, PintsPSO):
if not all(
np.isfinite(value)
for sublist in self.bounds.values()
for value in sublist
):
raise ValueError(
f"Either all bounds or no bounds must be set for {self.pints_optimiser.__name__}."
)
self._boundaries = PintsRectangularBoundaries(
self.bounds["lower"], self.bounds["upper"]
)
Expand Down

0 comments on commit 1fa9d36

Please sign in to comment.