def dfs_check_child(cfg: Cfg2Tune): for v in cfg.values(): if isinstance(v, Cfg2Tune): assert len(object.__getattribute__(v, "_params2tune")) == 0 dfs_check_child(v)
#!/usr/bin/env python # -*- coding: utf-8 -*- """ @Author : Xiaobo Yang @Contact : [email protected] @Time : 2021/5/6 22:09 @File : cfg.py.py @Software: PyCharm @Desc : """ from alchemy_cat.py_tools import Cfg2Tune, Param2Tune cfg = config = Cfg2Tune() cfg.rslt_dir = 'run_time_mutual_depend_config' # * Param on same Cfg2Tune cfg.foo0.foo1.a = Param2Tune([0, 1, 2]) def b_subject_to(_): if cfg.foo0.foo1.a.cur_val == 0: return True return cfg.c.cur_val cfg.foo0.foo1.b = Param2Tune([.1, .2], b_subject_to) # * Param on root Cfg2Tune cfg.c = Param2Tune([False, True], subject_to=lambda x: x ==
def subject_to_static_config(): return Cfg2Tune.load_cfg2tune( osp.join('configs', 'subject_to_static_config', 'cfg.py'))
def wrong_sequence_config(): return Cfg2Tune.load_cfg2tune( osp.join('configs', 'wrong_sequence_config', 'cfg.py'))
def run_time_mutual_depend_config(): return Cfg2Tune.load_cfg2tune( osp.join('configs', 'run_time_mutual_depend_config', 'cfg.py'))
def no_param_config(): return Cfg2Tune.load_cfg2tune( osp.join('configs', 'no_param_config', 'cfg.py'))
def no_legal_val_config(): return Cfg2Tune.load_cfg2tune( osp.join('configs', 'no_legal_val_config', 'cfg.py'))
def easy_config(): return Cfg2Tune.load_cfg2tune(osp.join('configs', 'easy_config', 'cfg.py'))
def test_same_name_config(): with pytest.raises(RuntimeError, match="for param2tune repeated."): Cfg2Tune.load_cfg2tune( osp.join('configs', 'same_name_config', 'cfg.py'))