From 53167090d6eb7990fe8ff0c2f0ca1a28b372899c Mon Sep 17 00:00:00 2001 From: avelichk Date: Tue, 17 Aug 2021 12:11:20 +0100 Subject: [PATCH 1/2] Update Katib UI with Optuna Algorithm Settings --- .../constants/algorithms-settings.const.ts | 27 ++++++++++++++----- pkg/suggestion/v1beta1/optuna/service.py | 4 +-- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/pkg/new-ui/v1beta1/frontend/src/app/constants/algorithms-settings.const.ts b/pkg/new-ui/v1beta1/frontend/src/app/constants/algorithms-settings.const.ts index e5853bcd194..0ca7f3c0b90 100644 --- a/pkg/new-ui/v1beta1/frontend/src/app/constants/algorithms-settings.const.ts +++ b/pkg/new-ui/v1beta1/frontend/src/app/constants/algorithms-settings.const.ts @@ -17,7 +17,7 @@ export const RandomSearchSettings: AlgorithmSetting[] = [ { name: 'random_state', value: null, - type: AlgorithmSettingType.STRING, + type: AlgorithmSettingType.INTEGER, }, ]; @@ -60,7 +60,6 @@ export const TPESettings: AlgorithmSetting[] = [ value: null, type: AlgorithmSettingType.STRING, }, - { name: 'prior_weight', value: null, @@ -69,22 +68,38 @@ export const TPESettings: AlgorithmSetting[] = [ { name: 'n_EI_candidates', value: null, - type: AlgorithmSettingType.STRING, + type: AlgorithmSettingType.INTEGER, }, { name: 'random_state', value: null, - type: AlgorithmSettingType.STRING, + type: AlgorithmSettingType.INTEGER, }, ]; -export const MultivariateTPESettings: AlgorithmSetting[] = []; +export const MultivariateTPESettings: AlgorithmSetting[] = [ + { + name: 'n_startup_trials', + value: null, + type: AlgorithmSettingType.INTEGER, + }, + { + name: 'n_ei_candidates', + value: null, + type: AlgorithmSettingType.INTEGER, + }, + { + name: 'random_state', + value: null, + type: AlgorithmSettingType.INTEGER, + }, +]; export const CMAESSettings: AlgorithmSetting[] = [ { name: 'random_state', value: null, - type: AlgorithmSettingType.STRING, + type: AlgorithmSettingType.INTEGER, }, { name: 'sigma', diff --git a/pkg/suggestion/v1beta1/optuna/service.py b/pkg/suggestion/v1beta1/optuna/service.py index a4d0319ace2..c7bbff613b2 100644 --- a/pkg/suggestion/v1beta1/optuna/service.py +++ b/pkg/suggestion/v1beta1/optuna/service.py @@ -69,9 +69,9 @@ def _create_sampler(self, algorithm_spec): if name == "tpe" or name == "multivariate-tpe": kwargs = {} for k, v in settings.items(): - if k == "startup_trials": + if k == "n_startup_trials": kwargs["n_startup_trials"] = int(v) - elif k == "ei_candidates": + elif k == "n_ei_candidates": kwargs["n_ei_candidates"] = int(v) elif k == "random_state": kwargs["seed"] = int(v) From 6f36d2961656a4f87152e7a384e1332a49d66708 Mon Sep 17 00:00:00 2001 From: avelichk Date: Tue, 17 Aug 2021 12:30:22 +0100 Subject: [PATCH 2/2] Fix Optuna tests --- pkg/suggestion/v1beta1/goptuna/converter.go | 4 ++-- test/suggestion/v1beta1/test_optuna_service.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pkg/suggestion/v1beta1/goptuna/converter.go b/pkg/suggestion/v1beta1/goptuna/converter.go index 7ebab1b002b..0a925851b81 100644 --- a/pkg/suggestion/v1beta1/goptuna/converter.go +++ b/pkg/suggestion/v1beta1/goptuna/converter.go @@ -75,13 +75,13 @@ func toGoptunaSampler(algorithm *api_v1_beta1.AlgorithmSpec) (goptuna.Sampler, g return nil, nil, err } opts = append(opts, tpe.SamplerOptionSeed(int64(seed))) - } else if s.Name == "startup_trials" { + } else if s.Name == "n_startup_trials" { n, err := strconv.Atoi(s.Value) if err != nil { return nil, nil, err } opts = append(opts, tpe.SamplerOptionNumberOfStartupTrials(n)) - } else if s.Name == "ei_candidates" { + } else if s.Name == "n_ei_candidates" { n, err := strconv.Atoi(s.Value) if err != nil { return nil, nil, err diff --git a/test/suggestion/v1beta1/test_optuna_service.py b/test/suggestion/v1beta1/test_optuna_service.py index 17f061c5cf5..a2aa48dd53e 100644 --- a/test/suggestion/v1beta1/test_optuna_service.py +++ b/test/suggestion/v1beta1/test_optuna_service.py @@ -33,10 +33,10 @@ def setup_method(self): servicers, grpc_testing.strict_real_time()) @pytest.mark.parametrize( - ["algorithm_name", "algorithm_settings"], + ["algorithm_name", "algorithm_settings"], [ - ["tpe", {"startup_trials": "20", "ei_candidates": "10", "random_state": "71"}], - ["multivariate-tpe", {"startup_trials": "20", "ei_candidates": "10", "random_state": "71"}], + ["tpe", {"n_startup_trials": "20", "n_ei_candidates": "10", "random_state": "71"}], + ["multivariate-tpe", {"n_startup_trials": "20", "n_ei_candidates": "10", "random_state": "71"}], ["cmaes", {"restart_strategy": "ipop", "sigma": "2", "random_state": "71"}], ["random", {"random_state": "71"}], ], @@ -47,7 +47,7 @@ def test_get_suggestion(self, algorithm_name, algorithm_settings): spec=api_pb2.ExperimentSpec( algorithm=api_pb2.AlgorithmSpec( algorithm_name=algorithm_name, - algorithm_settings = [ + algorithm_settings=[ api_pb2.AlgorithmSetting( name=name, value=value