Skip to content

Commit

Permalink
ProfileOptions: add some basic integrity checking
Browse files Browse the repository at this point in the history
  • Loading branch information
dweindl committed Oct 30, 2023
1 parent 7210de8 commit 9983284
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions pypesto/profile/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,24 @@ def create_instance(
return maybe_options
options = ProfileOptions(**maybe_options)
return options

def validate(self):
"""Check if options are valid.
Raise ``ValueError`` if not.
"""
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

0 comments on commit 9983284

Please sign in to comment.