def __init__(self, sim_manager, plugin_config): if not sim_manager.work_manager.is_master: return self.sim_manager = sim_manager self.data_manager = sim_manager.data_manager self.system = sim_manager.system self.work_manager = sim_manager.work_manager self.do_reweight = check_bool( plugin_config.get('do_reweighting', False)) self.windowsize = 0.5 self.windowtype = 'fraction' windowsize = plugin_config.get('window_size') if windowsize is not None: if isinstance(windowsize, float): self.windowsize = windowsize self.windowtype = 'fraction' if self.windowsize <= 0 or self.windowsize > 1: raise ValueError( 'WESS parameter error -- fractional window size must be in (0,1]' ) elif isinstance(windowsize, int): self.windowsize = int(windowsize) self.windowtype = 'fixed' else: raise ValueError( 'WESS parameter error -- invalid window size {!r}'.format( windowsize)) log.info('using window size of {!r} ({})'.format( self.windowsize, self.windowtype)) self.max_windowsize = plugin_config.get('max_window_size') if self.max_windowsize is not None: log.info('Using max windowsize of {:d}'.format( self.max_windowsize)) self.reweight_period = plugin_config.get('reweight_period', 0) self.priority = plugin_config.get('priority', 0) self.rate_calc_queue_size = plugin_config.get('rate_calc_queue_size', 1) self.rate_calc_n_blocks = plugin_config.get('rate_calc_n_blocks', 1) bin_obj = plugin_config.get('bins', None) if isinstance(bin_obj, dict): bin_obj = bins_from_yaml_dict(bin_obj) self.bin_mapper = bin_obj if self.do_reweight: sim_manager.register_callback(sim_manager.prepare_new_iteration, self.prepare_new_iteration, self.priority) self.write_matrices = plugin_config.get('write_matrices', False)
def __init__(self, sim_manager, plugin_config): if not sim_manager.work_manager.is_master: return self.sim_manager = sim_manager self.data_manager = sim_manager.data_manager self.system = sim_manager.system # Parameters from config file # this enables the adaptive voronoi, allows turning adaptive scheme off self.doAdaptiveVoronoi = check_bool( plugin_config.get('av_enabled', False)) # sets maximim number of centers/voronoi bins self.max_centers = plugin_config.get('max_centers', 10) # sets number of walkers per bin/voronoi center self.walk_count = plugin_config.get('walk_count', 5) # center placement frequency in number of iterations self.center_freq = plugin_config.get('center_freq', 1) # priority of the plugin (allows for order of execution) self.priority = plugin_config.get('priority', 0) # pulls the distance function that will be used by the plugin self.dfunc = self.get_dfunc_method(plugin_config) # pulls a user defined function to build the next bin mapper self.mapper_func = self.get_mapper_func(plugin_config) # Get initial set of Voronoi centers self.centers = self.get_initial_centers() self.ncenters = len(self.centers) # Update the BinMapper self.update_bin_mapper() westpa.rc.pstatus('-adaptive voronoi mapping --------------\n') westpa.rc.pstatus('enabled: {}\n'.format(self.doAdaptiveVoronoi)) westpa.rc.pstatus('max centers: {}\n'.format(self.max_centers)) westpa.rc.pstatus('center adding freq: {}\n'.format(self.center_freq)) westpa.rc.pstatus('centers: {}\n'.format(self.centers)) westpa.rc.pstatus('----------------------------------------\n') westpa.rc.pflush() # Register callback if self.doAdaptiveVoronoi: sim_manager.register_callback(sim_manager.prepare_new_iteration, self.prepare_new_iteration, self.priority)
def __init__(self, rc=None): super().__init__(rc) # A mapping of environment variables to template strings which will be # added to the environment of all children launched. self.addtl_child_environ = dict() # A mapping of executable name ('propagator', 'pre_iteration', 'post_iteration') to # a dictionary of attributes like 'executable', 'stdout', 'stderr', 'environ', etc. self.exe_info = {} self.exe_info['propagator'] = {} self.exe_info['pre_iteration'] = {} self.exe_info['post_iteration'] = {} self.exe_info['get_pcoord'] = {} self.exe_info['gen_istate'] = {} # A mapping of data set name ('pcoord', 'coord', 'com', etc) to a dictionary of # attributes like 'loader', 'dtype', etc self.data_info = {} self.data_info['pcoord'] = {} # Validate configuration config = self.rc.config for key in [ ('west', 'executable', 'propagator', 'executable'), ('west', 'data', 'data_refs', 'segment'), ('west', 'data', 'data_refs', 'basis_state'), ('west', 'data', 'data_refs', 'initial_state'), ]: config.require(key) self.segment_ref_template = config['west', 'data', 'data_refs', 'segment'] self.basis_state_ref_template = config['west', 'data', 'data_refs', 'basis_state'] self.initial_state_ref_template = config['west', 'data', 'data_refs', 'initial_state'] # Load additional environment variables for all child processes self.addtl_child_environ.update({k: str(v) for k, v in (config['west', 'executable', 'environ'] or {}).items()}) # Load configuration items relating to child processes for child_type in ('propagator', 'pre_iteration', 'post_iteration', 'get_pcoord', 'gen_istate'): child_info = config.get(['west', 'executable', child_type]) if not child_info: continue info_prefix = ['west', 'executable', child_type] # require executable to be specified if anything is specified at all config.require(info_prefix + ['executable']) self.exe_info[child_type]['executable'] = child_info['executable'] self.exe_info[child_type]['stdin'] = child_info.get('stdin', os.devnull) self.exe_info[child_type]['stdout'] = child_info.get('stdout', None) self.exe_info[child_type]['stderr'] = child_info.get('stderr', None) self.exe_info[child_type]['cwd'] = child_info.get('cwd', None) if child_type not in ('propagator', 'get_pcoord', 'gen_istate'): self.exe_info[child_type]['enabled'] = child_info.get('enabled', True) else: # for consistency, propagator, get_pcoord, and gen_istate can never be disabled self.exe_info[child_type]['enabled'] = True # apply environment modifications specific to this executable self.exe_info[child_type]['environ'] = {k: str(v) for k, v in (child_info.get('environ') or {}).items()} log.debug('exe_info: {!r}'.format(self.exe_info)) # Load configuration items relating to dataset input self.data_info['pcoord'] = {'name': 'pcoord', 'loader': pcoord_loader, 'enabled': True, 'filename': None} dataset_configs = config.get(['west', 'executable', 'datasets']) or [] for dsinfo in dataset_configs: try: dsname = dsinfo['name'] except KeyError: raise ValueError('dataset specifications require a ``name`` field') if dsname != 'pcoord': check_bool(dsinfo.setdefault('enabled', True)) else: # can never disable pcoord collection dsinfo['enabled'] = True loader_directive = dsinfo.get('loader') if loader_directive: loader = get_object(loader_directive) elif dsname != 'pcoord': loader = aux_data_loader dsinfo['loader'] = loader self.data_info.setdefault(dsname, {}).update(dsinfo) log.debug('data_info: {!r}'.format(self.data_info))
def __init__(self, sim_manager, plugin_config): super().__init__() if not sim_manager.work_manager.is_master: return self.sim_manager = sim_manager self.data_manager = sim_manager.data_manager self.system = sim_manager.system # Parameters from config file self.windowsize = plugin_config.get('windowsize', 10) self.update_interval = plugin_config.get('update_interval', 10) self.initial_update = plugin_config.get('initial_update', 20) self.priority = plugin_config.get('priority', 0) self.write_avg_pos = check_bool(plugin_config.get( 'write_avgpos', True)) self.do_update = check_bool(plugin_config.get('do_update', True)) self.init_from_data = check_bool( plugin_config.get('init_from_data', True)) self.dfunc = self.get_dfunc_method(plugin_config) # Load method to calculate average position in a bin # If the method is defined in an external module, correctly bind it ap = self.get_avgpos_method(plugin_config) if hasattr(ap, 'im_class'): self.get_avgpos = ap else: self.get_avgpos = types.MethodType(ap, self) # Get initial set of string centers centers = self.get_initial_centers() try: sm_params = self.system.sm_params except AttributeError as e: log.error('String Driver Error: system does not define sm_params. \ This is required and should be added to the system definition; {}' .format(e)) raise # Initialize the string str_method = self.get_string_method(plugin_config) try: self.strings = str_method(centers, **sm_params) except (TypeError, AssertionError) as e: log.error( 'String Driver Error: Failed during initialization of string method: {}' .format(e)) raise # Update the BinMapper self.update_bin_mapper() # Register callback sim_manager.register_callback(sim_manager.prepare_new_iteration, self.prepare_new_iteration, self.priority) westpa.rc.pstatus('-westext.stringmethod -----------------\n') westpa.rc.pstatus('windowsize: {}\n'.format(self.windowsize)) westpa.rc.pstatus('update interval: {}\n'.format(self.update_interval)) westpa.rc.pstatus('initial update: {}\n'.format(self.initial_update)) westpa.rc.pstatus('priority: {}\n'.format(self.priority)) westpa.rc.pstatus('write average positions: {}\n'.format( self.write_avg_pos)) westpa.rc.pstatus('do update: {}\n'.format(self.do_update)) westpa.rc.pstatus('initialize from WE data: {}\n'.format( self.init_from_data)) westpa.rc.pstatus('----------------------------------------\n') westpa.rc.pflush()