Example #1
0
def build_config(user_config: Dict[str, Any]) -> Optional[Dict[str, Any]]:
    """Check user config and apply default value to optional configs.

    Args:
        user_config: The user config to be referred.

    Returns:
        A nested dict of configs, or None if there has any errors.
    """

    log = get_default_logger('Config')

    # Check user config and make up optional values
    error = 0
    for key, attr in CONFIG_SETTING.items():
        if key in user_config:
            if 'options' in attr:
                # Specified config, check if it is legal
                if user_config[key] not in attr['options']:
                    log.error('"%s" is not a valid option for %s',
                              user_config[key], key)
                    error += 1
        else:
            # Missing config, check if it is optional (set to default if so)
            if attr['require']:
                log.error('Missing "%s" in the config which is required', key)
                error += 1
            else:
                log.debug('Use default value for %s: %s', key,
                          str(attr['default']))
                user_config[key] = attr['default']

    for key in user_config.keys():
        if key not in CONFIG_SETTING:
            log.error('Unrecognized config key: %s', key)
            error += 1

    if error > 0:
        return None

    # Build config
    config: Dict[str, Any] = {}
    for key, attr in user_config.items():
        curr = config
        levels = key.split('.')
        for level in levels[:-1]:
            if level not in curr:
                curr[level] = {}
            curr = curr[level]
        curr[levels[-1]] = attr

    return config
Example #2
0
"""
The unit test module for design point manipulation in search algorithm.
"""
import pytest

from autodse import logger
from autodse.explorer.algorithm import SearchAlgorithm
from autodse.explorer.algorithmfactory import AlgorithmFactory
from autodse.explorer.exhaustive import ExhaustiveAlgorithm
from autodse.parameter import MerlinParameter, get_default_point

LOG = logger.get_default_logger('UNIT-TEST', 'DEBUG')


@pytest.fixture
def fixture_space():
    #pylint:disable=missing-docstring

    space = {}
    param = MerlinParameter()
    param.name = 'A'
    param.option_expr = '[x for x in range(10) if x==0 or B!="flatten" and C!="flatten"]'
    param.deps = ['B', 'C']
    param.default = 0
    space['A'] = param

    param = MerlinParameter()
    param.name = 'B'
    param.option_expr = '[x for x in ["off", "", "flatten"] if x=="off" or C!="flatten"]'
    param.deps = ['C']
    param.child = ['A']