Package: chika
chikachikais a simple and easy config tool for hierarchical configurations.RequirementsPython>=3.9 (typing.get_*requires Python3.8 or higher)Installationpip install -U chikaorpip install -U git+https://github.com/moskomule/chikaUsageWrite typed configurations usingchika.config, which depends ondataclass.# main.pyimportenumimportchika@chika.configclassModelConfig:name:str=chika.choices('resnet','densenet')depth:int=10@chika.configclassDataConfig:# values that needs to be specifiedname:str=chika.required(help="name of dataset")classOptims(str,enum.Enum):# currently, only StrEnum is supportedsgd="sgd"adam="adam"@chika.configclassOptimConfig:name:Optims=Optims.sgdsteps:list[int]=chika.sequence(100,150)@chika.configclassBaseConfig:model:ModelConfigdata:DataConfigoptim:OptimConfigseed:int=chika.with_help(1,help="random seed")use_amp:bool=Falsegpu:int=chika.choices(*range(torch.cuda.device_count()),help="id of gpu")Then, wrap the main function withchika.main(BaseConfig).@chika.main(BaseConfig)defmain(cfg:BaseConfig):set_seed(cfg.seed)model=ModelRegistry(cfg.model)...Now,main.pycan be executed as...python main.py --use_amp
# cfg.use_amp == True

python main.py --model config/densenet.yaml
# cfg.model.name == densenet
# cfg.model.depth == 12

python main.py --model config/densenet.yaml --model.depth 24
# cfg.model.name == densenet
# cfg.model.depth == 24

python main.py --optim.decay_steps 120 150
# config.optim.decay_steps == [120, 150]

python main.py -h
#usage: test.py [-h] [--model MODEL] [--model.name {resnet,densenet}] [--model.depth MODEL.DEPTH] [--data DATA] --data.name DATA.NAME [--optim OPTIM] [--optim.steps OPTIM.STEPS [OPTIM.STEPS ...]]
#               [--seed SEED] [--use_amp] [--gpu {1,2,3}]
#
#optional arguments:
#  -h, --help            show this help message and exit
#  --model MODEL         load {yaml,yml,json} file for model if necessary
#  --model.name {resnet,densenet}
#                        (default: 'resnet')
#  --model.depth MODEL.DEPTH
#                        (default: 10)
#  --data DATA           load {yaml,yml,json} file for data if necessary
#  --data.name DATA.NAME
#                        name of dataset (required) (default: None)
#  --optim OPTIM         load {yaml,yml,json} file for optim if necessary
#  --optim.steps OPTIM.STEPS [OPTIM.STEPS ...]
#                        (default: [100, 150])
#  --seed SEED           random seed (default: 1)
#  --use_amp             (default: False)
#  --gpu {1,2,3}         id of gpu (default: 1)Child configs can be updated via YAML or JSON files.# config/densenet.yamlmodel:name:densenetdepth:12Forchika.Config, the following functions are prepared:defwith_help(default,help):...# add help messagedefchoices(*values,help):...# add candidates that should be selecteddefsequence(*values,size,help):...# add a list. size can be specifieddefrequired(*,help):...# add a required valuedefbounded(default,_from,_to,*help):...# add boundariesWorking Directorychange_job_dir=Truecreates a unique directory for each run.@chika.main(BaseConfig,change_job_dir=True)defmain(cfg):print(Path(".").resolve())# /home/user/outputs/0901-122412-558f5aprint(Path(".")/"weights.pt")# /home/user/outputs/0901-122412-558f5a/weights.ptprint(chika.original_path)# /home/userprint(chika.resolve_original_path("weights.pt"))# /home/user/weights.ptOther APIsfromchikaimportChikaConfigcfg=ChikaConfig.from_dict(...)cfg.to_dict()# {"model": {"name": "resnet", "zero_init": True, ...}, ...}Known issues and ToDosConfigs cannot be nested twice or more than twice.Config(Config(...))is valid,
butConfig(Config(Config(...)))is invalid.