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-10/

Custom Configuration Validator

Create a configuration system with custom validation rules for a machine learning training pipeline. The system should validate configuration values automatically and provide helpful error messages when invalid values are detected.

Requirements

Implement a custom configuration class that extends YACS's configuration functionality to add validation logic. The validator should enforce the following rules:

  1. Learning rate validation: The learning rate must be between 0.0 (exclusive) and 1.0 (inclusive)
  2. Batch size validation: The batch size must be a positive integer (greater than 0)
  3. Optimizer validation: The optimizer must be one of the allowed values: "adam", "sgd", or "rmsprop"

Your implementation should:

  • Create a configuration class that automatically validates values when they are set
  • Raise appropriate exceptions (ValueError) with descriptive messages when validation fails
  • Support all standard configuration operations (merging from lists, files, etc.)
  • Maintain the validation behavior throughout the configuration's lifetime

Test Cases

  • Setting learning rate to 0.5 succeeds @test
  • Setting learning rate to 0.0 raises ValueError with message containing "must be greater than 0" @test
  • Setting learning rate to 1.5 raises ValueError with message containing "must be less than or equal to 1.0" @test
  • Setting batch size to 32 succeeds @test
  • Setting batch size to 0 raises ValueError with message containing "must be positive" @test
  • Setting batch size to -5 raises ValueError with message containing "must be positive" @test
  • Setting optimizer to "adam" succeeds @test
  • Setting optimizer to "invalid_opt" raises ValueError with message containing "must be one of" @test

Implementation

@generates

API

class ValidatedConfig:
    """
    A configuration class that extends YACS CfgNode with custom validation.

    Validates:
    - LEARNING_RATE: Must be in range (0.0, 1.0]
    - BATCH_SIZE: Must be a positive integer
    - OPTIMIZER: Must be one of ["adam", "sgd", "rmsprop"]
    """
    pass

def get_default_config():
    """
    Returns a new ValidatedConfig instance with default training parameters.

    Default values:
    - LEARNING_RATE: 0.001
    - BATCH_SIZE: 32
    - OPTIMIZER: "adam"

    Returns:
        ValidatedConfig: A configuration instance with defaults
    """
    pass

Dependencies { .dependencies }

yacs { .dependency }

Provides the base configuration system with CfgNode class.

@satisfied-by