def update_run_params(env, param_tuples): for population in env.biophys_cells: synapse_config = env.celltypes[population].get('synapses', {}) weights_dict = synapse_config.get('weights', {}) for param_tuple, param_value in param_tuples: if param_tuple.population != population: continue source = param_tuple.source sec_type = param_tuple.sec_type syn_name = param_tuple.syn_name param_path = param_tuple.param_path if isinstance(param_path, list) or isinstance(param_path, tuple): p, s = param_path else: p, s = param_path, None sources = None if isinstance(source, list) or isinstance(source, tuple): sources = source else: if source is not None: sources = [source] if isinstance(sec_type, list) or isinstance(sec_type, tuple): sec_types = sec_type else: sec_types = [sec_type] biophys_cell_dict = env.biophys_cells[population] for gid in biophys_cell_dict: biophys_cell = biophys_cell_dict[gid] is_reduced = False if hasattr(biophys_cell, 'is_reduced'): is_reduced = biophys_cell.is_reduced for this_sec_type in sec_types: synapses.modify_syn_param( biophys_cell, env, this_sec_type, syn_name, param_name=p, value={s: param_value} if (s is not None) else param_value, filters={'sources': sources} if sources is not None else None, origin=None if is_reduced else 'soma', update_targets=True)
def update_network_params(env, param_tuple_values): if context is None: raise RuntimeError('update_network: missing required Context object') for param_tuple, param_value in param_tuple_values: pop_name = param_tuple.population biophys_cell_dict = env.biophys_cells[pop_name] synapse_config = env.celltypes[pop_name]['synapses'] weights_dict = synapse_config.get('weights', {}) for gid in biophys_cell_dict: biophys_cell = biophys_cell_dict[gid] is_reduced = False if hasattr(biophys_cell, 'is_reduced'): is_reduced = biophys_cell.is_reduced source = param_tuple.source sec_type = param_tuple.sec_type syn_name = param_tuple.syn_name param_path = param_tuple.param_path if isinstance(param_path, list) or isinstance(param_path, tuple): p, s = param_path else: p, s = param_path, None sources = None if isinstance(source, list) or isinstance(source, tuple): sources = source else: if source is not None: sources = [source] if isinstance(sec_type, list) or isinstance(sec_type, tuple): sec_types = sec_type else: sec_types = [sec_type] for this_sec_type in sec_types: synapses.modify_syn_param( biophys_cell, env, this_sec_type, syn_name, param_name=p, value={s: param_value} if (s is not None) else param_value, filters={'sources': sources} if sources is not None else None, origin=None if is_reduced else 'soma', update_targets=True)
def update_network(x, context=None): """ :param x: array :param context: :class:'Context' """ if context is None: raise RuntimeError('update_network: missing required Context object') for pop_name in context.target_populations: param_values = context.from_param_vector(x) for destination, source, sec_type, syn_name, param_path, param_value in param_values: if pop_name != destination: continue conn_params = context.env.connection_config[pop_name][source].mechanisms sec_type_index = context.env.SWC_Types[sec_type] if 'default' in conn_params: mech_params = conn_params['default'][syn_name] else: mech_params = conn_params[sec_type_index][syn_name] if isinstance(param_path, tuple): p, s = param_path mech_param = mech_params[p] try: mech_param[s] = param_value except Exception as err: context.logger.exception('source: %s sec type: %s syn name: %s param path: %s mech params: %s' % (str(source), str(sec_type), str(syn_name), str(param_path), str(mech_params))) context.logger.exception(err) raise err biophys_cell_dict = context.env.biophys_cells[pop_name] for gid, biophys_cell in viewitems(biophys_cell_dict): for destination, source, sec_type, syn_name, param_path, param_value in param_values: if pop_name != destination: continue if isinstance(param_path, tuple): p, s = param_path else: p = param_path synapses.modify_syn_param(biophys_cell, context.env, sec_type, syn_name, param_name=p, value=param_value, filters={'sources': [source]}, origin='soma', update_targets=True)
def update_network_clamp(x, context=None): """ :param x: array :param context: :class:'Context' """ if context is None: raise RuntimeError('update_network: missing required Context object') param_values = context.from_param_vector(x) context.logger.info("parameter values: %s" % str(param_values)) biophys_cell_dict = context.env.biophys_cells[context.population] for gid, biophys_cell in viewitems(biophys_cell_dict): for destination, source, sec_type, syn_name, param_path, param_value in param_values: if context.population != destination: continue if isinstance(param_path, tuple): p, s = param_path else: p, s = param_path, None sources = None if isinstance(source, tuple): sources = list(source) else: if source is not None: sources = [source] context.logger.info("gid %d: updating parameter %s with value %s" % (gid, str(p), str(param_value))) synapses.modify_syn_param( biophys_cell, context.env, sec_type, syn_name, param_name=p, value={s: param_value} if (s is not None) else param_value, filters={'sources': sources} if sources is not None else None, origin='soma', update_targets=True) context.pop_spike_dict = network_clamp.run(context.env, pc_runworker=False)
def update_network(x, context=None): """ :param x: array :param context: :class:'Context' """ if context is None: raise RuntimeError('update_network: missing required Context object') x_dict = param_array_to_dict(x, context.param_names) for postsyn_name in ['GC']: first_gid = True for gid in context.env.biophys_cells[postsyn_name]: if context.comm.rank == 0 and first_gid and context.verbose: verbose = True first_gid = False else: verbose = False cell = context.env.biophys_cells[postsyn_name][gid] for presyn_name, param_name, syn_name, syn_param_name in \ zip(['BC'], ['BC_GC.GABA_A.g_unit'], ['GABA_A'], ['g_unit']): sec_types = \ context.env.model_config['Connection Generator']['Synapses'][postsyn_name][presyn_name]['sections'] layers = \ context.env.model_config['Connection Generator']['Synapses'][postsyn_name][presyn_name]['layers'] syn_types = \ [context.env.model_config['Connection Generator']['Synapses'][postsyn_name][presyn_name]['type']] for sec_type in sec_types: synapses.modify_syn_param(cell, context.env, sec_type, syn_name=syn_name, param_name=syn_param_name, filters={ 'syn_types': syn_types, 'sources': [presyn_name], 'layers': layers }, value=x_dict[param_name], update_targets=True, verbose=True)
def standard_modify_syn_param_tests(cell, env, syn_name='AMPA', param_name='g_unit', show=False): """ :param cell: :class:'BiophysCell' :param env: :class:'Env' :param syn_name: str :param_name: str """ start_time = time.time() gid = cell.gid pop_name = cell.pop_name init_syn_mech_attrs(cell, env) syn_attrs = env.synapse_attributes sec_type = 'apical' syn_mech_name = syn_attrs.syn_mech_names[syn_name] param_label = '%s; %s; %s' % (syn_name, syn_mech_name, 'weight') plot_synaptic_attribute_distribution(cell, env, syn_name, 'weight', filters=None, from_mech_attrs=True, from_target_attrs=False, param_label=param_label, export='syn_weights.hdf5', description='stage0', show=show, overwrite=True, output_dir=context.output_dir) config_biophys_cell_syns(env, gid, pop_name, insert=True, insert_netcons=True, insert_vecstims=True, verbose=context.verbose) plot_synaptic_attribute_distribution(cell, env, syn_name, 'weight', filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_weights.hdf5', description='stage1', show=show, output_dir=context.output_dir) if param_name in syn_attrs.syn_param_rules[syn_mech_name]['netcon_params']: param_label = '%s; %s; %s' % (syn_name, syn_mech_name, param_name) plot_synaptic_attribute_distribution(cell, env, syn_name, param_name, filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_attrs.hdf5', description='stage0', show=show, overwrite=True, output_dir=context.output_dir) modify_syn_param(cell, env, sec_type, syn_name, param_name=param_name, value=0.0005, filters={'syn_types': ['excitatory']}, origin='soma', slope=0.0001, tau=50., xhalf=200., update_targets=True, verbose=context.verbose) plot_synaptic_attribute_distribution(cell, env, syn_name, param_name, filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_attrs.hdf5', description='stage1', show=show, output_dir=context.output_dir) modify_syn_param(cell, env, sec_type, syn_name, param_name=param_name, filters={'syn_types': ['excitatory'], 'layers': ['OML']}, origin='apical', origin_filters={'syn_types': ['excitatory'], 'layers': ['MML']}, update_targets=True, append=True, verbose=context.verbose) plot_synaptic_attribute_distribution(cell, env, syn_name, param_name, filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_attrs.hdf5', description='stage2', show=show, output_dir=context.output_dir) if context.verbose: print('standard_modify_syn_param tests with cache_queries: %s took %.2f s' % \ (str(env.cache_queries), time.time() - start_time)) plot_syn_attr_from_file(syn_name, param_name, 'syn_attrs.hdf5', param_label=param_label) else: param_name = 'weight' param_label = '%s; %s; %s' % (syn_name, syn_mech_name, param_name) modify_syn_param(cell, env, sec_type, syn_name, param_name=param_name, value=0.0005, filters={'syn_types': ['excitatory']}, origin='soma', slope=0.0001, tau=50., xhalf=200., update_targets=True, verbose=context.verbose) plot_synaptic_attribute_distribution(cell, env, syn_name, param_name, filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_weights.hdf5', description='stage2', show=show, output_dir=context.output_dir) modify_syn_param(cell, env, sec_type, syn_name, param_name=param_name, filters={'syn_types': ['excitatory'], 'layers': ['OML']}, origin='apical', origin_filters={'syn_types': ['excitatory'], 'layers': ['MML']}, update_targets=True, append=True, verbose=context.verbose) plot_synaptic_attribute_distribution(cell, env, syn_name, param_name, filters=None, from_mech_attrs=True, from_target_attrs=True, param_label=param_label, export='syn_weights.hdf5', description='stage3', show=show, output_dir=context.output_dir) if context.verbose: print('standard_modify_syn_param tests with cache_queries: %s took %.2f s' % \ (str(env.cache_queries), time.time() - start_time)) param_name = 'weight' param_label = '%s; %s; %s' % (syn_name, syn_mech_name, param_name) plot_syn_attr_from_file(syn_name, param_name, 'syn_weights.hdf5', param_label=param_label)