Skip to content

Commit

Permalink
Fixed priorband_template.py example (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
DaStoll authored Nov 14, 2024
2 parents 65e5194 + 4abb9de commit 43617c7
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion neps/optimizers/multi_fidelity/successive_halving.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def __init__(
self.sample_default_first = sample_default_first
self.sample_default_at_target = sample_default_at_target

assert self.pipeline_space.fidelity is not None
assert self.pipeline_space.fidelity is not None, "Fidelity parameter not set."
self.min_budget = self.pipeline_space.fidelity.lower
self.max_budget = self.pipeline_space.fidelity.upper
self.eta = eta
Expand Down
6 changes: 6 additions & 0 deletions neps/search_spaces/hyperparameters/numerical.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ def __init__(
f"{default_confidence}"
)

if is_fidelity and (lower <= 0 or upper <= 0):
raise ValueError(
f"{_cls_name} parameter: fidelity parameter bounds error (log scale "
f"can't have bounds <= 0). Actual values: lower={lower}, upper={upper}"
)

# Validate 'log' and 'is_fidelity' types to prevent configuration errors
# from the YAML input
for param, value in {"log": log, "is_fidelity": is_fidelity}.items():
Expand Down
2 changes: 1 addition & 1 deletion neps_examples/template/priorband_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pipeline_space() -> dict:
default=1e-3, # a non-None value here acts as the mode of the prior distribution
),
wd=neps.Float(
lower=0,
lower=1e-5,
upper=1e-1,
log=True,
default=1e-3,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_yaml_search_space/correct_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ param_float1:
is_fidelity: off

param_int1:
lower: -3
lower: 3
upper: 30
log: false
is_fidelity: on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ param_float1:

param_int1:
type: integer
lower: -3
lower: 3
upper: 30
is_fidelity: True

Expand Down
22 changes: 22 additions & 0 deletions tests/test_yaml_search_space/incorrect_fidelity_bounds_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
param_float1:
lower: 0.00001
upper: 0.1
log: TRUE
is_fidelity: off

param_int1:
lower: -3 # negative fidelity range
upper: 30
log: false
is_fidelity: on

param_int2:
type: int
lower: 1E2
upper: 3e4
log: ON
is_fidelity: FALSE

param_float2:
lower: 3.3e-5
upper: 1.5E-1
10 changes: 9 additions & 1 deletion tests/test_yaml_search_space/test_search_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def test_correct_yaml_file(path):
assert isinstance(pipeline_space, dict)
float1 = Float(0.00001, 0.1, log=True, is_fidelity=False)
assert float1.__eq__(pipeline_space["param_float1"]) is True
int1 = Integer(-3, 30, log=False, is_fidelity=True)
int1 = Integer(3, 30, log=False, is_fidelity=True)
assert int1.__eq__(pipeline_space["param_int1"]) is True
int2 = Integer(100, 30000, log=True, is_fidelity=False)
assert int2.__eq__(pipeline_space["param_int2"]) is True
Expand Down Expand Up @@ -143,3 +143,11 @@ def test_categorical_default_value_not_in_choices():
with pytest.raises(SearchSpaceFromYamlFileError) as excinfo:
pipeline_space_from_yaml(BASE_PATH + "default_value_not_in_choices_config.yaml")
assert excinfo.value.exception_type == "ValueError"

@pytest.mark.neps_api
def test_incorrect_fidelity_parameter_bounds():
"""Test if a ValueError is raised when the bounds of a fidelity parameter are
not correctly specified."""
with pytest.raises(SearchSpaceFromYamlFileError) as excinfo:
pipeline_space_from_yaml(BASE_PATH + "incorrect_fidelity_bounds_config.yaml")
assert excinfo.value.exception_type == "ValueError"

0 comments on commit 43617c7

Please sign in to comment.