or run

tessl search
Log in

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/yacs@0.1.x
tile.json

tessl/pypi-yacs

tessl install tessl/pypi-yacs@0.1.0

A 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%

task.mdevals/scenario-3/

Configuration CLI Override Parser

Overview

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).

Requirements

Your implementation should:

  1. 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))
  2. Accept command-line overrides in the format: key1 value1 key2 value2 ...

    • Keys should use dot notation for nested values (e.g., "TRAIN.LEARNING_RATE")
    • String values should be automatically converted to appropriate Python types
  3. Apply the command-line overrides to update the default configuration

  4. Output the final configuration in a readable format

Constraints

  • Values from the command line arrive as strings and must be safely parsed
  • The parser should handle tuples, lists, integers, floats, booleans, None, and strings
  • Type conversion should be safe (no arbitrary code execution)
  • Invalid values should fall back to treating the input as a string

Dependencies { .dependencies }

yacs { .dependency }

Provides configuration management with safe value parsing.

Test Cases

Test 1: Basic type conversions @test

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 4
  • TRAIN.LEARNING_RATE should be float 0.01
  • TRAIN.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)

Test 2: Boolean and None handling @test

Input command-line arguments:

DATA.AUGMENTATION True SYSTEM.USE_CUDA False

Expected behavior:

  • DATA.AUGMENTATION should be boolean True
  • SYSTEM.USE_CUDA should be boolean False

Test 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 False

Test 3: String values that can't be parsed @test

Input command-line arguments:

MODEL.TYPE vgg19_bn

Expected 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)

Implementation Notes

Create a file named config_parser.py with a parse_config() function that:

  1. Creates the default configuration
  2. Applies the command-line overrides
  3. Returns the final configuration

The solution should demonstrate proper use of the configuration management library to handle safe parsing of string values into appropriate Python types.