Coverage for mlos_core/mlos_core/tests/spaces/adapters/identity_adapter_test.py: 100%
20 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
1#
2# Copyright (c) Microsoft Corporation.
3# Licensed under the MIT License.
4#
5"""Tests for Identity space adapter."""
7# pylint: disable=missing-function-docstring
9import ConfigSpace as CS
10import pandas as pd
12from mlos_core.spaces.adapters import IdentityAdapter
15def test_identity_adapter() -> None:
16 """Tests identity adapter."""
17 input_space = CS.ConfigurationSpace(seed=1234)
18 input_space.add(CS.UniformIntegerHyperparameter(name="int_1", lower=0, upper=100))
19 input_space.add(CS.UniformFloatHyperparameter(name="float_1", lower=0, upper=100))
20 input_space.add(CS.CategoricalHyperparameter(name="str_1", choices=["on", "off"]))
22 adapter = IdentityAdapter(orig_parameter_space=input_space)
24 num_configs = 10
25 for (
26 sampled_config
27 ) in input_space.sample_configuration( # pylint: disable=not-an-iterable # (false positive)
28 size=num_configs
29 ):
30 sampled_config_sr = pd.Series(dict(sampled_config))
31 target_config_sr = adapter.inverse_transform(sampled_config_sr)
32 assert target_config_sr.equals(sampled_config_sr)
33 target_config = CS.Configuration(
34 adapter.target_parameter_space, values=target_config_sr.to_dict()
35 )
36 assert target_config == sampled_config
37 orig_config_df = adapter.transform(target_config_sr)
38 assert orig_config_df.equals(sampled_config_sr)
39 orig_config = CS.Configuration(
40 adapter.orig_parameter_space, values=orig_config_df.to_dict()
41 )
42 assert orig_config == sampled_config