예제 #1
0
    def run_wrapper(
        self,
        run_info: RunInfo,
    ) -> Tuple[RunInfo, RunValue]:
        """
        wrapper function for ExecuteTARun.run_wrapper() to cap the target algorithm
        runtime if it would run over the total allowed runtime.

        Parameters
        ----------
        run_info : RunInfo
            Object that contains enough information to execute a configuration run in
            isolation.
        Returns
        -------
        RunInfo:
            an object containing the configuration launched
        RunValue:
            Contains information about the status/performance of config
        """
        if self.budget_type is None:
            if run_info.budget != 0:
                raise ValueError(
                    'If budget_type is None, budget must be.0, but is %f' %
                    run_info.budget)
        else:
            if run_info.budget == 0:
                run_info = run_info._replace(budget=100)
            elif run_info.budget <= 0 or run_info.budget > 100:
                raise ValueError(
                    'Illegal value for budget, must be >0 and <=100, but is %f'
                    % run_info.budget)
            if self.budget_type not in ('subsample', 'iterations', 'mixed'):
                raise ValueError(
                    "Illegal value for budget type, must be one of "
                    "('subsample', 'iterations', 'mixed'), but is : %s" %
                    self.budget_type)

        remaining_time = self.stats.get_remaing_time_budget()

        if remaining_time - 5 < run_info.cutoff:
            run_info = run_info._replace(cutoff=int(remaining_time - 5))

        if run_info.cutoff < 1.0:
            return run_info, RunValue(
                status=StatusType.STOP,
                cost=self.worst_possible_result,
                time=0.0,
                additional_info={},
                starttime=time.time(),
                endtime=time.time(),
            )
        elif (run_info.cutoff != int(np.ceil(run_info.cutoff))
              and not isinstance(run_info.cutoff, int)):
            run_info = run_info._replace(cutoff=int(np.ceil(run_info.cutoff)))

        return super().run_wrapper(run_info=run_info)
예제 #2
0
파일: tae.py 프로젝트: automl/Auto-PyTorch
    def run_wrapper(
        self,
        run_info: RunInfo,
    ) -> Tuple[RunInfo, RunValue]:
        """
        wrapper function for ExecuteTARun.run_wrapper() to cap the target algorithm
        runtime if it would run over the total allowed runtime.

        Args:
            run_info (RunInfo): Object that contains enough information
                to execute a configuration run in isolation.
        Returns:
            RunInfo:
                an object containing the configuration launched
            RunValue:
                Contains information about the status/performance of config
        """
        if self.budget_type is None:
            if run_info.budget != 0:
                raise ValueError(
                    'If budget_type is None, budget must be.0, but is %f' %
                    run_info.budget)
        else:
            if run_info.budget == 0:
                # SMAC can return budget zero for intensifiers that don't have a concept
                # of budget, for example a simple bayesian optimization intensifier.
                # Budget determines how our pipeline trains, which can be via runtime or epochs
                epochs_budget = self.pipeline_config.get('epochs', np.inf)
                runtime_budget = self.pipeline_config.get('runtime', np.inf)
                run_info = run_info._replace(
                    budget=min(epochs_budget, runtime_budget))
            elif run_info.budget <= 0:
                raise ValueError(
                    'Illegal value for budget, must be greater than zero but is %f'
                    % run_info.budget)
            if self.budget_type not in ('epochs', 'runtime'):
                raise ValueError(
                    "Illegal value for budget type, must be one of "
                    "('epochs', 'runtime'), but is : %s" % self.budget_type)

        remaining_time = self.stats.get_remaing_time_budget()

        if remaining_time - 5 < run_info.cutoff:
            run_info = run_info._replace(cutoff=int(remaining_time - 5))

        if run_info.cutoff < 1.0:
            return run_info, RunValue(
                status=StatusType.STOP,
                cost=self.worst_possible_result,
                time=0.0,
                additional_info={},
                starttime=time.time(),
                endtime=time.time(),
            )
        elif (run_info.cutoff != int(np.ceil(run_info.cutoff))
              and not isinstance(run_info.cutoff, int)):
            run_info = run_info._replace(cutoff=int(np.ceil(run_info.cutoff)))

        self.logger.info("Starting to evaluate configuration %s" %
                         run_info.config.config_id)
        run_info, run_value = super().run_wrapper(run_info=run_info)
        return run_info, run_value