def __init__(self, interface_wait=1, **kwargs): super(Interface, self).__init__() self.remaining_kwargs = mlu._config_logger(**kwargs) self.log = logging.getLogger(__name__) self.log.debug('Creating interface.') self.params_out_queue = mp.Queue() self.costs_in_queue = mp.Queue() self.end_event = mp.Event() self.interface_wait = float(interface_wait) if self.interface_wait <= 0: self.log.error('Interface wait time must be a positive number.') raise ValueError
def __init__(self, interface_wait = 1, **kwargs): super(Interface,self).__init__() self.remaining_kwargs = mlu._config_logger(**kwargs) self.log = logging.getLogger(__name__) self.log.debug('Creating interface.') self.params_out_queue = mp.Queue() self.costs_in_queue = mp.Queue() self.end_event = mp.Event() self.interface_wait = float(interface_wait) if self.interface_wait<=0: self.log.error('Interface wait time must be a positive number.') raise ValueError
def __init__(self, interface, max_num_runs = float('+inf'), target_cost = float('-inf'), max_num_runs_without_better_params = float('+inf'), controller_archive_filename=default_controller_archive_filename, controller_archive_file_type=default_controller_archive_file_type, archive_extra_dict = None, start_datetime = None, **kwargs): #Make logger self.remaining_kwargs = mlu._config_logger(**kwargs) self.log = logging.getLogger(__name__) #Variable that are included in archive self.num_in_costs = 0 self.num_out_params = 0 self.num_last_best_cost = 0 self.out_params = [] self.out_type = [] self.out_extras = [] self.in_costs = [] self.in_uncers = [] self.in_bads = [] self.in_extras = [] self.best_cost = float('inf') self.best_uncer = float('nan') self.best_index = float('nan') self.best_params = float('nan') #Variables that used internally self.last_out_params = None self.curr_params = None self.curr_cost = None self.curr_uncer = None self.curr_bad = None self.curr_extras = None #Constants self.controller_wait = float(1) #Learner related variables self.learner_params_queue = None self.learner_costs_queue = None self.end_learner = None self.learner = None #Variables set by user #save interface and extract important variables if isinstance(interface, mli.Interface): self.interface = interface else: self.log.error('interface is not a Interface as defined in the MLOOP package.') raise TypeError self.params_out_queue = interface.params_out_queue self.costs_in_queue = interface.costs_in_queue self.end_interface = interface.end_event #Other options if start_datetime is None: self.start_datetime = datetime.datetime.now() else: self.start_datetime = datetime.datetime(start_datetime) self.max_num_runs = float(max_num_runs) if self.max_num_runs<=0: self.log.error('Number of runs must be greater than zero. max_num_runs:'+repr(self.max_num_run)) raise ValueError self.target_cost = float(target_cost) self.max_num_runs_without_better_params = float(max_num_runs_without_better_params) if self.max_num_runs_without_better_params<=0: self.log.error('Max number of repeats must be greater than zero. max_num_runs:'+repr(max_num_runs_without_better_params)) raise ValueError if mlu.check_file_type_supported(controller_archive_file_type): self.controller_archive_file_type = controller_archive_file_type else: self.log.error('File in type is not supported:' + repr(controller_archive_file_type)) raise ValueError if controller_archive_filename is None: self.controller_archive_filename = None else: if not os.path.exists(mlu.archive_foldername): os.makedirs(mlu.archive_foldername) self.controller_archive_filename =str(controller_archive_filename) self.total_archive_filename = mlu.archive_foldername + self.controller_archive_filename + '_' + mlu.datetime_to_string(self.start_datetime) + '.' + self.controller_archive_file_type self.archive_dict = {'archive_type':'controller', 'num_out_params':self.num_out_params, 'out_params':self.out_params, 'out_type':self.out_type, 'out_extras':self.out_extras, 'in_costs':self.in_costs, 'in_uncers':self.in_uncers, 'in_bads':self.in_bads, 'in_extras':self.in_extras, 'max_num_runs':self.max_num_runs, 'start_datetime':mlu.datetime_to_string(self.start_datetime)} if archive_extra_dict is not None: self.archive_dict.update(archive_extra_dict) self.log.debug('Controller init completed.')
def __init__( self, interface, max_num_runs=float('+inf'), target_cost=float('-inf'), max_num_runs_without_better_params=float('+inf'), controller_archive_filename=default_controller_archive_filename, controller_archive_file_type=default_controller_archive_file_type, archive_extra_dict=None, start_datetime=None, **kwargs): #Make logger self.remaining_kwargs = mlu._config_logger(**kwargs) self.log = logging.getLogger(__name__) #Variable that are included in archive self.num_in_costs = 0 self.num_out_params = 0 self.num_last_best_cost = 0 self.out_params = [] self.out_type = [] self.out_extras = [] self.in_costs = [] self.in_uncers = [] self.in_bads = [] self.in_extras = [] self.best_cost = float('inf') self.best_uncer = float('nan') self.best_index = float('nan') self.best_params = float('nan') #Variables that used internally self.last_out_params = None self.curr_params = None self.curr_cost = None self.curr_uncer = None self.curr_bad = None self.curr_extras = None #Constants self.controller_wait = float(1) #Learner related variables self.learner_params_queue = None self.learner_costs_queue = None self.end_learner = None self.learner = None #Variables set by user #save interface and extract important variables if isinstance(interface, mli.Interface): self.interface = interface else: self.log.error( 'interface is not a Interface as defined in the M-LOOP package.' ) raise TypeError self.params_out_queue = interface.params_out_queue self.costs_in_queue = interface.costs_in_queue self.end_interface = interface.end_event #Other options if start_datetime is None: self.start_datetime = datetime.datetime.now() else: self.start_datetime = datetime.datetime(start_datetime) self.max_num_runs = float(max_num_runs) if self.max_num_runs <= 0: self.log.error( 'Number of runs must be greater than zero. max_num_runs:' + repr(self.max_num_run)) raise ValueError self.target_cost = float(target_cost) self.max_num_runs_without_better_params = float( max_num_runs_without_better_params) if self.max_num_runs_without_better_params <= 0: self.log.error( 'Max number of repeats must be greater than zero. max_num_runs:' + repr(max_num_runs_without_better_params)) raise ValueError if mlu.check_file_type_supported(controller_archive_file_type): self.controller_archive_file_type = controller_archive_file_type else: self.log.error('File in type is not supported:' + repr(controller_archive_file_type)) raise ValueError if controller_archive_filename is None: self.controller_archive_filename = None else: # Store self.controller_archive_filename without any path, but # include any path components in controller_archive_filename when # constructing the full path. controller_archive_filename = str(controller_archive_filename) self.controller_archive_filename = os.path.basename( controller_archive_filename) filename_suffix = mlu.generate_filename_suffix( self.controller_archive_file_type, file_datetime=self.start_datetime, ) filename = controller_archive_filename + filename_suffix self.total_archive_filename = os.path.join(mlu.archive_foldername, filename) # Include any path info from controller_archive_filename when # creating directory for archive files.] archive_dir = os.path.dirname(self.total_archive_filename) if not os.path.exists(archive_dir): os.makedirs(archive_dir) self.archive_dict = { 'mloop_version': __version__, 'archive_type': 'controller', 'num_out_params': self.num_out_params, 'out_params': self.out_params, 'out_type': self.out_type, 'out_extras': self.out_extras, 'in_costs': self.in_costs, 'in_uncers': self.in_uncers, 'in_bads': self.in_bads, 'in_extras': self.in_extras, 'max_num_runs': self.max_num_runs, 'start_datetime': mlu.datetime_to_string(self.start_datetime) } if archive_extra_dict is not None: self.archive_dict.update(archive_extra_dict) self.log.debug('Controller init completed.')