tessl install tessl/pypi-yacs@0.1.0A lightweight library for defining and managing system configurations for scientific experimentation.
Agent Success
Agent success rate when using this tile
97%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.05x
Baseline
Agent success rate without this tile
92%
Build a command-line configuration parser for a scientific experiment runner. The parser should accept configuration overrides from the command line and safely parse string values into their appropriate Python types (integers, floats, booleans, tuples, lists, and None).
Your implementation should:
Create a default configuration with the following structure:
MODEL.TYPE: string (default: "resnet50")MODEL.DEPTH: integer (default: 101)TRAIN.LEARNING_RATE: float (default: 0.001)TRAIN.BATCH_SIZE: integer (default: 32)TRAIN.EPOCHS: integer (default: 100)TRAIN.SCALES: tuple of integers (default: (8, 16, 32))SYSTEM.NUM_GPUS: integer (default: 8)SYSTEM.USE_CUDA: boolean (default: True)DATA.AUGMENTATION: boolean (default: False)DATA.MEAN: tuple of floats (default: (0.485, 0.456, 0.406))Accept command-line overrides in the format: key1 value1 key2 value2 ...
Apply the command-line overrides to update the default configuration
Output the final configuration in a readable format
Provides configuration management with safe value parsing.
Input command-line arguments:
SYSTEM.NUM_GPUS 4 TRAIN.LEARNING_RATE 0.01 TRAIN.SCALES "(1, 2, 4, 8)"Expected behavior:
SYSTEM.NUM_GPUS should be integer 4TRAIN.LEARNING_RATE should be float 0.01TRAIN.SCALES should be tuple (1, 2, 4, 8)Test file: test_config.py { .test-file }
def test_basic_type_conversions():
from config_parser import parse_config
args = ["SYSTEM.NUM_GPUS", "4", "TRAIN.LEARNING_RATE", "0.01", "TRAIN.SCALES", "(1, 2, 4, 8)"]
cfg = parse_config(args)
assert cfg['SYSTEM']['NUM_GPUS'] == 4
assert isinstance(cfg['SYSTEM']['NUM_GPUS'], int)
assert cfg['TRAIN']['LEARNING_RATE'] == 0.01
assert isinstance(cfg['TRAIN']['LEARNING_RATE'], float)
assert cfg['TRAIN']['SCALES'] == (1, 2, 4, 8)
assert isinstance(cfg['TRAIN']['SCALES'], tuple)Input command-line arguments:
DATA.AUGMENTATION True SYSTEM.USE_CUDA FalseExpected behavior:
DATA.AUGMENTATION should be boolean TrueSYSTEM.USE_CUDA should be boolean FalseTest file: test_config.py { .test-file }
def test_boolean_handling():
from config_parser import parse_config
args = ["DATA.AUGMENTATION", "True", "SYSTEM.USE_CUDA", "False"]
cfg = parse_config(args)
assert cfg['DATA']['AUGMENTATION'] is True
assert cfg['SYSTEM']['USE_CUDA'] is FalseInput command-line arguments:
MODEL.TYPE vgg19_bnExpected behavior:
MODEL.TYPE should remain string "vgg19_bn"Test file: test_config.py { .test-file }
def test_string_fallback():
from config_parser import parse_config
args = ["MODEL.TYPE", "vgg19_bn"]
cfg = parse_config(args)
assert cfg['MODEL']['TYPE'] == "vgg19_bn"
assert isinstance(cfg['MODEL']['TYPE'], str)Create a file named config_parser.py with a parse_config() function that:
The solution should demonstrate proper use of the configuration management library to handle safe parsing of string values into appropriate Python types.