Skip to content

Commit

Permalink
fix naming of parameters in test
Browse files Browse the repository at this point in the history
  • Loading branch information
danrgll committed Dec 6, 2023
1 parent 5bcf6cf commit 15d4cc8
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 52 deletions.
17 changes: 9 additions & 8 deletions tests/test_yaml_search_space/correct_config.yaml
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
search_space:
learning_rate:
param_float1:
lower: 0.00001
upper: 0.1
log: TRUE
is_fidelity: off

num_epochs:
param_int1:
lower: -3
upper: 30
log: false
is_fidelity: on
batch_size:
param_int2:
type: int
lower: 1E2
upper: 3e4
log: on
log: ON
is_fidelity: FALSE

sec_learning_rate:
param_float2:
lower: 3.3e-5
upper: 1.5E-1

optimizer:
param_cat:
choices: [2, "sgd", 10e-3]

dropout_rate:
param_const1:
value: 0.5

constant_value:
param_const2:
value: 1e3
is_fidelity: TRUE
17 changes: 11 additions & 6 deletions tests/test_yaml_search_space/correct_config_including_types.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
search_space:
learning_rate:
param_float1:
type: float
lower: 0.00001
upper: 1e-1
log: true

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

batch_size:
param_int2:
type: "int"
lower: 1e2
upper: 3E4
log: true
is_fidelity: false

sec_learning_rate:
param_float2:
type: "float"
lower: 3.3e-5
upper: 1.5E-1

optimizer:
param_cat:
type: cat
choices: [2, "sgd", 10E-3]

dropout_rate:
param_const1:
type: const
value: 0.5

param_const2:
type: const
value: 1e3
is_fidelity: true
79 changes: 41 additions & 38 deletions tests/test_yaml_search_space/test_search_space.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@
import pytest

from neps import CategoricalParameter, ConstantParameter, FloatParameter, IntegerParameter
from neps.search_spaces.search_space import (
SearchSpaceFromYamlFileError,
pipeline_space_from_yaml,
)

from neps import CategoricalParameter, ConstantParameter, FloatParameter, IntegerParameter


@pytest.mark.neps_api
def test_correct_yaml_files():
def test_correct_yaml_file(path):
"""Test the function with a correctly formatted YAML file."""
pipeline_space = pipeline_space_from_yaml(path)
assert isinstance(pipeline_space, dict)
assert isinstance(pipeline_space["learning_rate"], FloatParameter)
assert pipeline_space["learning_rate"].lower == 0.00001
assert pipeline_space["learning_rate"].upper == 0.1
assert pipeline_space["learning_rate"].log is True
assert pipeline_space["optimizer"].is_fidelity is False
assert pipeline_space["learning_rate"].default is None
assert pipeline_space["learning_rate"].default_confidence_score == 0.5
assert isinstance(pipeline_space["num_epochs"], IntegerParameter)
assert pipeline_space["num_epochs"].lower == -3
assert pipeline_space["num_epochs"].upper == 30
assert pipeline_space["num_epochs"].log is False
assert pipeline_space["num_epochs"].is_fidelity is True
assert pipeline_space["num_epochs"].default is None
assert pipeline_space["num_epochs"].default_confidence_score == 0.5
assert isinstance(pipeline_space["batch_size"], IntegerParameter)
assert pipeline_space["batch_size"].lower == 100
assert pipeline_space["batch_size"].upper == 30000
assert pipeline_space["batch_size"].log is True
assert pipeline_space["batch_size"].is_fidelity is False
assert pipeline_space["batch_size"].default is None
assert pipeline_space["batch_size"].default_confidence_score == 0.5
assert isinstance(pipeline_space["sec_learning_rate"], FloatParameter)
assert pipeline_space["sec_learning_rate"].lower == 3.3e-5
assert pipeline_space["sec_learning_rate"].upper == 0.15
assert pipeline_space["sec_learning_rate"].log is False
assert pipeline_space["sec_learning_rate"].is_fidelity is False
assert pipeline_space["sec_learning_rate"].default is None
assert pipeline_space["sec_learning_rate"].default_confidence_score == 0.5
assert isinstance(pipeline_space["optimizer"], CategoricalParameter)
assert pipeline_space["optimizer"].choices == [2, "sgd", 10e-3]
assert pipeline_space["optimizer"].is_fidelity is False
assert pipeline_space["optimizer"].default is None
assert pipeline_space["optimizer"].default_confidence_score == 2
assert isinstance(pipeline_space["dropout_rate"], ConstantParameter)
assert pipeline_space["dropout_rate"].value == 0.5
assert pipeline_space["dropout_rate"].is_fidelity is False
assert isinstance(pipeline_space["param_float1"], FloatParameter)
assert pipeline_space["param_float1"].lower == 0.00001
assert pipeline_space["param_float1"].upper == 0.1
assert pipeline_space["param_float1"].log is True
assert pipeline_space["param_float1"].is_fidelity is False
assert pipeline_space["param_float1"].default is None
assert pipeline_space["param_float1"].default_confidence_score == 0.5
assert isinstance(pipeline_space["param_int1"], IntegerParameter)
assert pipeline_space["param_int1"].lower == -3
assert pipeline_space["param_int1"].upper == 30
assert pipeline_space["param_int1"].log is False
assert pipeline_space["param_int1"].is_fidelity is True
assert pipeline_space["param_int1"].default is None
assert pipeline_space["param_int1"].default_confidence_score == 0.5
assert isinstance(pipeline_space["param_int2"], IntegerParameter)
assert pipeline_space["param_int2"].lower == 100
assert pipeline_space["param_int2"].upper == 30000
assert pipeline_space["param_int2"].log is True
assert pipeline_space["param_int2"].is_fidelity is False
assert pipeline_space["param_int2"].default is None
assert pipeline_space["param_int2"].default_confidence_score == 0.5
assert isinstance(pipeline_space["param_float2"], FloatParameter)
assert pipeline_space["param_float2"].lower == 3.3e-5
assert pipeline_space["param_float2"].upper == 0.15
assert pipeline_space["param_float2"].log is False
assert pipeline_space["param_float2"].is_fidelity is False
assert pipeline_space["param_float2"].default is None
assert pipeline_space["param_float2"].default_confidence_score == 0.5
assert isinstance(pipeline_space["param_cat"], CategoricalParameter)
assert pipeline_space["param_cat"].choices == [2, "sgd", 10e-3]
assert pipeline_space["param_cat"].is_fidelity is False
assert pipeline_space["param_cat"].default is None
assert pipeline_space["param_cat"].default_confidence_score == 2
assert isinstance(pipeline_space["param_const1"], ConstantParameter)
assert pipeline_space["param_const1"].value == 0.5
assert pipeline_space["param_const1"].is_fidelity is False
assert isinstance(pipeline_space["param_const2"], ConstantParameter)
assert pipeline_space["param_const2"].value == 1e3
assert pipeline_space["param_const2"].is_fidelity is True

test_correct_yaml_file("tests/test_yaml_search_space/correct_config.yaml")
test_correct_yaml_file(
Expand Down

0 comments on commit 15d4cc8

Please sign in to comment.