Skip to content

Commit

Permalink
Merge branch 'develop' into fix_1165_asym_prof
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Oct 30, 2023
2 parents 046b08f + 8d3986d commit 3f5ea02
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pypesto/profile/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(
self.magic_factor_obj_value = magic_factor_obj_value
self.whole_path = whole_path

self.validate()

def __getattr__(self, key):
"""Allow usage of keys like attributes."""
try:
Expand All @@ -91,3 +93,24 @@ def create_instance(
return maybe_options
options = ProfileOptions(**maybe_options)
return options

def validate(self):
"""Check if options are valid.
Raises ``ValueError`` if current settings aren't valid.
"""
if self.min_step_size <= 0:
raise ValueError("min_step_size must be > 0.")
if self.max_step_size <= 0:
raise ValueError("max_step_size must be > 0.")
if self.min_step_size > self.max_step_size:
raise ValueError("min_step_size must be <= max_step_size.")
if self.default_step_size <= 0:
raise ValueError("default_step_size must be > 0.")
if self.default_step_size > self.max_step_size:
raise ValueError("default_step_size must be <= max_step_size.")
if self.default_step_size < self.min_step_size:
raise ValueError("default_step_size must be >= min_step_size.")

if self.magic_factor_obj_value < 0 or self.magic_factor_obj_value >= 1:
raise ValueError("magic_factor_obj_value must be >= 0 and < 1.")
1 change: 1 addition & 0 deletions pypesto/profile/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def parameter_profile(
if profile_options is None:
profile_options = ProfileOptions()
profile_options = ProfileOptions.create_instance(profile_options)
profile_options.validate()

# create a function handle that will be called later to get the next point
if isinstance(next_guess_method, str):
Expand Down
22 changes: 22 additions & 0 deletions test/profile/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,28 @@ def test_approximate_ci():
assert np.isclose(ub, 9)


def test_options_valid():
"""Test ProfileOptions validity checks."""
# default settings are valid
profile.ProfileOptions()

# try to set invalid values
with pytest.raises(ValueError):
profile.ProfileOptions(default_step_size=-1)
with pytest.raises(ValueError):
profile.ProfileOptions(default_step_size=1, min_step_size=2)
with pytest.raises(ValueError):
profile.ProfileOptions(
default_step_size=2,
min_step_size=1,
)
with pytest.raises(ValueError):
profile.ProfileOptions(
min_step_size=2,
max_step_size=1,
)


@pytest.mark.parametrize(
"lb,ub",
[(6 * np.ones(5), 10 * np.ones(5)), (-4 * np.ones(5), 1 * np.ones(5))],
Expand Down

0 comments on commit 3f5ea02

Please sign in to comment.