chika 
chika is a simple and easy config tool for hierarchical configurations.
Requirements
- Python>=3.9 (
typing.get_*requires Python3.8 or higher)
Installation
pip install -U chika
or
pip install -U git+https://github.com/moskomule/chika
Usage
Write typed configurations using chika.config, which depends on dataclass.
# main.py
import enum
import chika
@chika.config
class ModelConfig:
name: str = chika.choices('resnet', 'densenet')
depth: int = 10
@chika.config
class DataConfig:
# values that needs to be specified
name: str = chika.required(help="name of dataset")
class Optims(str, enum.Enum):
# currently, only StrEnum is supported
sgd = "sgd"
adam = "adam"
@chika.config
class OptimConfig:
name: Optims = Optims.sgd
steps: list[int] = chika.sequence(100, 150)
@chika.config
class BaseConfig:
model: ModelConfig
data: DataConfig
optim: OptimConfig
seed: int = chika.with_help(1, help="random seed")
use_amp: bool = False
gpu: int = chika.choices(*range(torch.cuda.device_count()), help="id of gpu")
Then, wrap the main function with chika.main(BaseConfig).
@chika.main(BaseConfig)
def main(cfg: BaseConfig):
set_seed(cfg.seed)
model = ModelRegistry(cfg.model)
...
Now, main.py can 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.yaml
model:
name: densenet
depth: 12
For chika.Config, the following functions are prepared:
def with_help(default, help): ...
# add help message
def choices(*values, help): ...
# add candidates that should be selected
def sequence(*values, size, help): ...
# add a list. size can be specified
def required(*, help): ...
# add a required value
def bounded(default, _from, _to, *help): ...
# add boundaries
Working Directory
change_job_dir=True creates a unique directory for each run.
@chika.main(BaseConfig, change_job_dir=True)
def main(cfg):
print(Path(".").resolve())
# /home/user/outputs/0901-122412-558f5a
print(Path(".") / "weights.pt")
# /home/user/outputs/0901-122412-558f5a/weights.pt
print(chika.original_path)
# /home/user
print(chika.resolve_original_path("weights.pt"))
# /home/user/weights.pt
Other APIs
from chika import ChikaConfig
cfg = ChikaConfig.from_dict(...)
cfg.to_dict()
# {"model": {"name": "resnet", "zero_init": True, ...}, ...}
Known issues and ToDos
- Configs cannot be nested twice or more than twice.
Config(Config(...))is valid, butConfig(Config(Config(...)))is invalid.
Metadata
Release files for chika 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chika-0.1.0.tar.gz | 10.4 kB | Without provenance | Details for chika-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chika-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for chika-0.1.0-py3-none-any.whl |
Total release size: 20.1 kB
Release files / chika-0.1.0.tar.gz
| Download URL | chika-0.1.0.tar.gz |
|---|---|
| Size | 10.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e07224f465ad1991bed0a85379fa430a9a62970bb36a1b2582ef9a7a0ad40e9
|
|
BLAKE2b-256 checksum How to use checksums |
0ddb4dba47e1e8c08363163f9d443e338b08a4a6238588164be7fa3a6a9247d6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Release files / chika-0.1.0-py3-none-any.whl
| Download URL | chika-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2cc0b13e7f6a4555539c5828b4ac061e4dc9f56ac5bad506819dbcc9335cfd7a
|
|
BLAKE2b-256 checksum How to use checksums |
c077361b2a1186c800b9f42b382a200669e283a8bf8a7f1aef08278968ea5305
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for chika 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.