Пример #1
0
def initialize_controls(experiment: Experiment,
                        configuration: Configuration = None,
                        secrets: Secrets = None):
    """
    Initialize all declared controls in the experiment.

    On Python controls, this means calling the `configure_control` function
    of the exposed module.

    Controls are initialized once only when they are declared many
    times in the experiment with the same name.
    """
    logger.debug("Initializing controls")
    controls = get_controls(experiment)

    seen = []
    for control in controls:
        name = control.get("name")
        if not name or name in seen:
            continue
        seen.append(name)
        logger.debug("Initializing control '{}'".format(name))

        provider = control.get("provider")
        if provider and provider["type"] == "python":
            try:
                initialize_control(control, experiment, configuration, secrets)
            except Exception:
                logger.debug(
                    "Control initialization '{}' failed. "
                    "It will not be registered.".format(
                        control['name']),
                    exc_info=True)
Пример #2
0
def initialize_global_controls(experiment: Experiment,
                               configuration: Configuration, secrets: Secrets,
                               settings: Settings):
    """
    Load and initialize controls declared in the settings.

    Notice, if a control fails during its initialization, it is deregistered
    and will not be applied throughout the experiment.
    """
    controls = get_global_controls()[:]
    for control in get_global_controls():
        name = control['name']
        logger.debug("Initializing global control '{}'".format(name))

        provider = control.get("provider")
        if provider and provider["type"] == "python":
            try:
                initialize_control(control,
                                   experiment=experiment,
                                   configuration=configuration,
                                   secrets=secrets,
                                   settings=settings)
            except Exception:
                logger.debug("Control initialization '{}' failed. "
                             "It will not be registered.".format(
                                 control['name']),
                             exc_info=True)
                controls.remove(control)
    set_global_controls(controls)
Пример #3
0
def initialize_global_controls(experiment: Experiment,
                               configuration: Configuration, secrets: Secrets,
                               settings: Settings):
    """
    Load and initialize controls declared in the settings.

    Notice, if a control fails during its initialization, it is not registered
    at all and will not be applied throughout the experiment.
    """
    controls = []
    for name, control in settings.get("controls", {}).items():
        control['name'] = name
        logger.debug("Initializing global control '{}'".format(name))

        provider = control.get("provider")
        if provider and provider["type"] == "python":
            try:
                initialize_control(
                    control, experiment=experiment,
                    configuration=configuration, secrets=secrets,
                    settings=settings)
            except Exception:
                logger.debug(
                    "Control initialization '{}' failed. "
                    "It will not be registered.".format(
                        control['name']),
                    exc_info=True)
                # we don't use a control that failed its initialization
                continue

        controls.append(control)
    set_global_controls(controls)
Пример #4
0
def initialize_global_controls(settings: Settings):
    """
    Load and initialize controls declared in the settings
    """
    controls = []
    for name, control in settings.get("controls", {}).items():
        control['name'] = name
        logger.debug("Initializing global control '{}'".format(name))

        provider = control.get("provider")
        if provider and provider["type"] == "python":
            initialize_control(control,
                               configuration=None,
                               secrets=None,
                               settings=settings)
        controls.append(control)
    global_controls.set(controls)