src.core.config_validator

Configuration validation and parameter mapping for MMM models.

This module provides functionality to validate model configurations, map user-friendly parameter names to internal names, and provide helpful error messages for configuration issues.

Module Contents

class src.core.config_validator.ParameterMapper

Maps user-friendly parameter names to internal mathematical notation.

This class allows users to use intuitive parameter names in their configurations while maintaining mathematical correctness internally.

classmethod normalize_parameter_name(name: str) str

Convert a user-friendly parameter name to its internal representation.

Parameters:

name – The parameter name to normalize

Returns:

The internal parameter name

classmethod normalize_config(config: Dict[str, Any]) Dict[str, Any]

Normalize all parameter names in a configuration dictionary.

Parameters:

config – Configuration dictionary with potentially aliased parameter names

Returns:

Configuration dictionary with normalized parameter names

Raises:

ValueError – If multiple aliases map to the same internal parameter

classmethod get_parameter_info(param_name: str) Dict[str, str] | None

Get detailed information about a parameter.

Parameters:

param_name – The parameter name (can be an alias)

Returns:

Dictionary with parameter information or None if not found

classmethod get_all_aliases(param_name: str) List[str]

Get all aliases for a given parameter.

Parameters:

param_name – The parameter name (can be an alias)

Returns:

List of all aliases for this parameter

class src.core.config_validator.ConfigValidator(expected_parameters: Set[str] | None = None)

Validates MMM model configurations with helpful error messages.

validate_custom_priors(custom_priors: Dict[str, Any], raise_on_unexpected: bool = True, warn_on_missing: bool = True) Dict[str, Any]

Validate and normalize custom priors configuration.

Parameters:
  • custom_priors – Dictionary of custom prior configurations

  • raise_on_unexpected – Whether to raise an error for unexpected parameters

  • warn_on_missing – Whether to warn about missing expected parameters

Returns:

Normalized configuration dictionary

Raises:

ValueError – If validation fails and raise_on_unexpected is True

validate_prior_distribution(param_name: str, prior_config: Dict[str, Any]) None

Validate that a prior distribution is properly configured.

Parameters:
  • param_name – The parameter name

  • prior_config – The prior configuration dictionary

Raises:

ValueError – If the prior configuration is invalid

src.core.config_validator.create_config_documentation() str

Generate documentation for all configuration parameters.

Returns:

Formatted documentation string

class src.core.config_validator.FieldValidator(field_type=None, default=None, optional=False)

Base class for field validation.

validate(field_name: str, value: Any, config: Dict[str, Any]) tuple[bool, str | None]

Validate a field value.

Parameters:
  • field_name – Name of the field being validated

  • value – Value to validate

  • config – Full configuration dictionary (for dependency validation)

Returns:

Tuple of (is_valid, error_message)

class src.core.config_validator.RequiredField(field_type=None)

Bases: FieldValidator

Validates that required fields are present.

class src.core.config_validator.TypeValidator(field_type, default=None, optional=False)

Bases: FieldValidator

Validates field types with optional defaults.

class src.core.config_validator.RangeValidator(field_type, min_value=None, max_value=None, default=None, optional=False)

Bases: FieldValidator

Validates numeric ranges.

validate(field_name: str, value: Any, config: Dict[str, Any]) tuple[bool, str | None]

Validate numeric range.

class src.core.config_validator.EnumValidator(allowed_values: List[str], default=None, optional=False)

Bases: FieldValidator

Validates enum values.

validate(field_name: str, value: Any, config: Dict[str, Any]) tuple[bool, str | None]

Validate enum value.

class src.core.config_validator.StructuredValidator(schema_class, optional=False)

Bases: FieldValidator

Validates nested structures.

validate(field_name: str, value: Any, config: Dict[str, Any]) tuple[bool, str | None]

Validate structured field.

class src.core.config_validator.MediaChannelSchema

Schema for validating media channel configuration.

classmethod validate(channel: Dict[str, Any]) tuple[bool, List[str]]

Validate a media channel configuration.

Parameters:

channel – Media channel configuration dictionary

Returns:

Tuple of (is_valid, list_of_errors)

class src.core.config_validator.ProphetSchema

Schema for validating Prophet configuration.

classmethod validate(prophet_config: Dict[str, Any]) tuple[bool, List[str]]

Validate Prophet configuration.

Parameters:

prophet_config – Prophet configuration dictionary

Returns:

Tuple of (is_valid, list_of_errors)

class src.core.config_validator.ConfigSchema

Complete configuration schema with validation.

classmethod validate(config: Dict[str, Any]) tuple[bool, List[str]]

Validate entire configuration against schema.

Parameters:

config – Configuration dictionary to validate

Returns:

Tuple of (is_valid, list_of_errors)

classmethod validate_and_apply_defaults(config: Dict[str, Any]) Dict[str, Any]

Validate configuration and apply default values where needed.

Parameters:

config – Configuration dictionary to validate

Returns:

Configuration with defaults applied

Raises:

ValueError – If validation fails

src.core.config_validator.validate_and_normalize_config(config: Dict[str, Any], raise_on_error: bool = True) Dict[str, Any]

Validate and normalize a model configuration.

Parameters:
  • config – The configuration dictionary to validate

  • raise_on_error – Whether to raise errors or just warn

Returns:

Normalized configuration dictionary

Raises:

ValueError – If validation fails and raise_on_error is True

src.core.config_validator.validate_full_config(config: Dict[str, Any], apply_defaults: bool = True) Dict[str, Any]

Validate complete configuration including all fields beyond custom_priors.

This function validates the entire configuration file structure, including required fields, types, ranges, and inter-field dependencies.

Parameters:
  • config – The configuration dictionary to validate

  • apply_defaults – Whether to apply default values for optional fields

Returns:

Validated configuration dictionary (with defaults if apply_defaults=True)

Raises:

ValueError – If validation fails

Example

>>> config = load_config('config.yml')[1]
>>> validated_config = validate_full_config(config)