Exemple #1
0
    def __init__(
        self,
        objective_func,
        restart_needed=False,
        need_lc=False,
        method_name='default_method_name',
        log_directory='logs',
        data_directory='data',
        time_limit_per_trial=600,
        runtime_limit=None,
        max_queue_len=300,
        ip='',
        port=13579,
        authkey=b'abc',
    ):
        self.log_directory = log_directory
        if not os.path.exists(self.log_directory):
            os.makedirs(self.log_directory)
        self.data_directory = data_directory
        if not os.path.exists(self.data_directory):
            os.makedirs(self.data_directory)

        self.logger = self._get_logger(method_name)

        self.objective_func = objective_func
        self.trial_statistics = list()
        self.recorder = list()

        self.global_start_time = time.time()
        self.runtime_limit = None
        self._history = {
            "time_elapsed": list(),
            "performance": list(),
            "best_trial_id": list(),
            "configuration": list()
        }
        self.global_incumbent = 1e10
        self.global_incumbent_configuration = None
        self.global_trial_counter = 0
        self.restart_needed = restart_needed
        self.record_lc = need_lc
        self.method_name = method_name
        # evaluation metrics
        self.stage_id = 1
        self.stage_history = {'stage_id': list(), 'performance': list()}
        self.grid_search_perf = list()

        if self.method_name is None:
            raise ValueError('Method name must be specified! NOT NONE.')

        self.time_limit_per_trial = time_limit_per_trial
        self.runtime_limit = runtime_limit
        assert self.runtime_limit is not None

        max_queue_len = max(300, max_queue_len)
        self.master_messager = MasterMessager(ip, port, authkey, max_queue_len,
                                              max_queue_len)
Exemple #2
0
    def __init__(
        self,
        objective_function,
        config_space,
        eval_type='holdout',
        parallel_strategy='async',
        batch_size=4,
        batch_strategy='median_imputation',
        num_constraints=0,
        num_objs=1,
        sample_strategy: str = 'bo',
        runtime_limit=600,
        time_limit_per_trial=180,
        surrogate_type=None,
        acq_type=None,
        acq_optimizer_type='local_random',
        initial_runs=3,
        init_strategy='random_explore_first',
        initial_configurations=None,
        ref_point=None,
        history_bo_data: List[OrderedDict] = None,
        logging_dir='logs',
        task_id='default',
        random_state=1,
        ip="",
        port=13579,
        authkey=b'abc',
    ):

        self.task_info = {
            'num_constraints': num_constraints,
            'num_objs': num_objs
        }
        self.FAILED_PERF = [MAXINT] * num_objs
        super().__init__(objective_function,
                         config_space,
                         task_id=task_id,
                         output_dir=logging_dir,
                         random_state=random_state,
                         initial_runs=initial_runs,
                         max_runs=int(1e10),
                         runtime_limit=runtime_limit,
                         sample_strategy=sample_strategy,
                         time_limit_per_trial=time_limit_per_trial,
                         history_bo_data=history_bo_data)
        if parallel_strategy == 'sync':
            self.config_advisor = SyncBatchAdvisor(
                config_space,
                self.task_info,
                batch_size=batch_size,
                batch_strategy=batch_strategy,
                initial_trials=initial_runs,
                initial_configurations=initial_configurations,
                init_strategy=init_strategy,
                history_bo_data=history_bo_data,
                optimization_strategy=sample_strategy,
                surrogate_type=surrogate_type,
                acq_type=acq_type,
                acq_optimizer_type=acq_optimizer_type,
                ref_point=ref_point,
                task_id=task_id,
                output_dir=logging_dir,
                random_state=random_state)
        elif parallel_strategy == 'async':
            self.config_advisor = AsyncBatchAdvisor(
                config_space,
                self.task_info,
                batch_size=batch_size,
                batch_strategy=batch_strategy,
                initial_trials=initial_runs,
                initial_configurations=initial_configurations,
                init_strategy=init_strategy,
                history_bo_data=history_bo_data,
                optimization_strategy=sample_strategy,
                surrogate_type=surrogate_type,
                acq_type=acq_type,
                acq_optimizer_type=acq_optimizer_type,
                ref_point=ref_point,
                task_id=task_id,
                output_dir=logging_dir,
                random_state=random_state)
        else:
            raise ValueError('Invalid parallel strategy - %s.' %
                             parallel_strategy)

        self.eval_type = eval_type
        self.parallel_strategy = parallel_strategy
        self.batch_size = batch_size
        max_queue_len = max(100, 3 * batch_size)
        self.master_messager = MasterMessager(ip, port, authkey, max_queue_len,
                                              max_queue_len)
        self.start_time = time.time()

        self.configs = list()
        self.perfs = list()
        self.incumbent_perf = float("-INF")
        self.incumbent_config = self.config_space.get_default_configuration()
        self.eval_dict = dict()
        self.workers = dict()
    def __init__(
        self,
        objective_function,
        config_space,
        parallel_strategy='async',
        batch_size=4,
        batch_strategy='default',
        num_constraints=0,
        num_objs=1,
        sample_strategy: str = 'bo',
        max_runs=200,
        time_limit_per_trial=180,
        surrogate_type='auto',
        acq_type='auto',
        acq_optimizer_type='auto',
        initial_runs=3,
        init_strategy='random_explore_first',
        initial_configurations=None,
        ref_point=None,
        history_bo_data: List[OrderedDict] = None,
        logging_dir='logs',
        task_id='default_task_id',
        random_state=None,
        advisor_kwargs: dict = None,
        ip="",
        port=13579,
        authkey=b'abc',
    ):

        if task_id is None:
            raise ValueError(
                'Task id is not SPECIFIED. Please input task id first.')

        self.num_objs = num_objs
        self.num_constraints = num_constraints
        self.FAILED_PERF = [MAXINT] * num_objs
        super().__init__(objective_function,
                         config_space,
                         task_id=task_id,
                         output_dir=logging_dir,
                         random_state=random_state,
                         initial_runs=initial_runs,
                         max_runs=max_runs,
                         sample_strategy=sample_strategy,
                         time_limit_per_trial=time_limit_per_trial,
                         history_bo_data=history_bo_data)

        self.parallel_strategy = parallel_strategy
        self.batch_size = batch_size
        max_queue_len = max(100, 3 * batch_size)
        self.master_messager = MasterMessager(ip, port, authkey, max_queue_len,
                                              max_queue_len)

        advisor_kwargs = advisor_kwargs or {}
        if parallel_strategy == 'sync':
            self.config_advisor = SyncBatchAdvisor(
                config_space,
                num_objs=num_objs,
                num_constraints=num_constraints,
                batch_size=batch_size,
                batch_strategy=batch_strategy,
                initial_trials=initial_runs,
                initial_configurations=initial_configurations,
                init_strategy=init_strategy,
                history_bo_data=history_bo_data,
                optimization_strategy=sample_strategy,
                surrogate_type=surrogate_type,
                acq_type=acq_type,
                acq_optimizer_type=acq_optimizer_type,
                ref_point=ref_point,
                task_id=task_id,
                output_dir=logging_dir,
                random_state=random_state,
                **advisor_kwargs)
        elif parallel_strategy == 'async':
            self.config_advisor = AsyncBatchAdvisor(
                config_space,
                num_objs=num_objs,
                num_constraints=num_constraints,
                batch_size=batch_size,
                batch_strategy=batch_strategy,
                initial_trials=initial_runs,
                initial_configurations=initial_configurations,
                init_strategy=init_strategy,
                history_bo_data=history_bo_data,
                optimization_strategy=sample_strategy,
                surrogate_type=surrogate_type,
                acq_type=acq_type,
                acq_optimizer_type=acq_optimizer_type,
                ref_point=ref_point,
                task_id=task_id,
                output_dir=logging_dir,
                random_state=random_state,
                **advisor_kwargs)
        else:
            raise ValueError('Invalid parallel strategy - %s.' %
                             parallel_strategy)