From 4abb9de41079a71e6064f9e655e8449d93c60936 Mon Sep 17 00:00:00 2001 From: Gopalji Gaur Date: Thu, 7 Nov 2024 15:02:40 +0100 Subject: [PATCH] Fixed pytest with new fidelity parameter checks --- .../correct_config.yaml | 2 +- .../correct_config_including_types.yaml | 2 +- .../incorrect_fidelity_bounds_config.yaml | 22 +++++++++++++++++++ .../test_search_space.py | 10 ++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 tests/test_yaml_search_space/incorrect_fidelity_bounds_config.yaml diff --git a/tests/test_yaml_search_space/correct_config.yaml b/tests/test_yaml_search_space/correct_config.yaml index 1264127a..b8c34866 100644 --- a/tests/test_yaml_search_space/correct_config.yaml +++ b/tests/test_yaml_search_space/correct_config.yaml @@ -5,7 +5,7 @@ param_float1: is_fidelity: off param_int1: - lower: -3 + lower: 3 upper: 30 log: false is_fidelity: on diff --git a/tests/test_yaml_search_space/correct_config_including_types.yaml b/tests/test_yaml_search_space/correct_config_including_types.yaml index 95a38074..4ae8cb9c 100644 --- a/tests/test_yaml_search_space/correct_config_including_types.yaml +++ b/tests/test_yaml_search_space/correct_config_including_types.yaml @@ -6,7 +6,7 @@ param_float1: param_int1: type: integer - lower: -3 + lower: 3 upper: 30 is_fidelity: True diff --git a/tests/test_yaml_search_space/incorrect_fidelity_bounds_config.yaml b/tests/test_yaml_search_space/incorrect_fidelity_bounds_config.yaml new file mode 100644 index 00000000..552c775d --- /dev/null +++ b/tests/test_yaml_search_space/incorrect_fidelity_bounds_config.yaml @@ -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 diff --git a/tests/test_yaml_search_space/test_search_space.py b/tests/test_yaml_search_space/test_search_space.py index bfc1c84c..6d0b8c5c 100644 --- a/tests/test_yaml_search_space/test_search_space.py +++ b/tests/test_yaml_search_space/test_search_space.py @@ -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 @@ -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"