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

Fixes #320 #321

Merged
merged 15 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features

- [#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.
- [#301](https://github.com/pybop-team/PyBOP/pull/301) - Updates default echem solver to "fast with events" mode.
Expand All @@ -19,6 +20,7 @@ codesigned binaries and source distributions via `sigstore-python`.

## Bug Fixes

- [#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.
- [#308](https://github.com/pybop-team/PyBOP/pull/308) - Enables testing on both macOS Intel and macOS ARM (Silicon) runners and fixes the scheduled tests.
Expand Down
2 changes: 1 addition & 1 deletion pybop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
#
from .parameters.parameter import Parameter
from .parameters.parameter_set import ParameterSet
from .parameters.priors import Gaussian, Uniform, Exponential
from .parameters.priors import BasePrior, Gaussian, Uniform, Exponential


#
Expand Down
17 changes: 14 additions & 3 deletions pybop/optimisers/scipy_optimisers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
super().__init__()
self.method = method
self.bounds = bounds
self.num_resamples = 40
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is intentionally left without an set/get as #255 enables kwargs to this class, which will be added once that is merged.

self.tol = tol
self.options = {}
self._max_iterations = maxiter
Expand Down Expand Up @@ -56,11 +57,21 @@
def callback(x):
self.log.append([x])

# Scale the cost function and eliminate nan values
# Check x0 and resample if required
self.cost0 = cost_function(x0)
self.inf_count = 0
if np.isinf(self.cost0):
raise Exception("The initial parameter values return an infinite cost.")
for i in range(1, self.num_resamples):
x0 = cost_function.problem.sample_initial_conditions(seed=i)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be updated in #322 to work with costs without a problem.

self.cost0 = cost_function(x0)
if not np.isinf(self.cost0):
break

Check warning on line 67 in pybop/optimisers/scipy_optimisers.py

View check run for this annotation

Codecov / codecov/patch

pybop/optimisers/scipy_optimisers.py#L67

Added line #L67 was not covered by tests
if np.isinf(self.cost0):
raise ValueError(
"The initial parameter values return an infinite cost."
)

# Scale the cost function and eliminate nan values
self.inf_count = 0

def cost_wrapper(x):
cost = cost_function(x) / self.cost0
Expand Down
4 changes: 2 additions & 2 deletions pybop/parameters/parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def __init__(
self.set_bounds(bounds)
self.margin = 1e-4

def rvs(self, n_samples):
def rvs(self, n_samples, random_state=None):
"""
Draw random samples from the parameter's prior distribution.

Expand All @@ -59,7 +59,7 @@ def rvs(self, n_samples):
array-like
An array of samples drawn from the prior distribution within the parameter's bounds.
"""
samples = self.prior.rvs(n_samples)
samples = self.prior.rvs(n_samples, random_state=random_state)

# Constrain samples to be within bounds
if self.bounds is not None:
Expand Down
Loading
Loading