From b003a3c03b851de5060cc0d73cd2528dfc184880 Mon Sep 17 00:00:00 2001 From: blazma Date: Thu, 1 Sep 2022 16:19:01 +0200 Subject: [PATCH 1/7] Neuroptimus integration --- hippounit/tests/test_SomaticFeaturesTest.py | 55 ++++++++++++--------- hippounit/utils.py | 29 +++++++++++ 2 files changed, 62 insertions(+), 22 deletions(-) diff --git a/hippounit/tests/test_SomaticFeaturesTest.py b/hippounit/tests/test_SomaticFeaturesTest.py index 33f6b14..647abe1 100755 --- a/hippounit/tests/test_SomaticFeaturesTest.py +++ b/hippounit/tests/test_SomaticFeaturesTest.py @@ -98,6 +98,8 @@ class SomaticFeaturesTest(Test): If False, only the JSON files containing the absolute feature values, the feature error scores and the final scores, and a log file are saved, but the figures and pickle files are not. specify_data_set : str When set to a string, output will be saved into subdirectory (within the model_name subderotory) named like this. This makes it possible to run the validation on a specific model, against different data sets, and save the results separately. + serialized : boolean + if True, simulation and feature analysis are not parallelized """ def __init__(self, @@ -108,7 +110,8 @@ def __init__(self, base_directory=None, show_plot=True, save_all = True, - specify_data_set = ''): + specify_data_set = '', + serialized=False): Test.__init__(self,observation,name) @@ -130,7 +133,8 @@ def __init__(self, self.logFile = None self.test_log_filename = 'test_log.txt' self.specify_data_set = specify_data_set #this is added to the name of the directory (somaticfeat), so tests runs using different data sets can be saved into different directories - + self.serialized = serialized + self.SomaFeaturesDict = {} plt.close('all') #needed to avoid overlapping of saved images when the test is run on multiple models in a for loop #with open('./stimfeat/PC_newfeat_No14112401_15012303-m990803_stimfeat.json') as f: @@ -391,30 +395,35 @@ def generate_prediction(self, model, verbose=False): global model_name_soma model_name_soma = model.name - pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) - stimuli_list=self.create_stimuli_list() - - run_stim_ = functools.partial(self.run_stim, model) - traces_results = pool.map(run_stim_, stimuli_list, chunksize=1) - #traces_results = traces_result.get() - - - pool.terminate() - pool.join() - del pool - - pool2 = multiprocessing.Pool(self.npool, maxtasksperchild=1) - features_names, features_list = self.create_features_list(self.observation) - analyse_traces_ = functools.partial(self.analyse_traces, stimuli_list, traces_results) - feature_results = pool2.map(analyse_traces_, features_list, chunksize=1) - #feature_results = feature_result.get() + if self.serialized: + traces_results = [] + for stimuli in stimuli_list: + traces_result = self.run_stim(model, stimuli) + traces_results.append(traces_result) - pool2.terminate() - pool2.join() - del pool2 + feature_results = [] + for features in features_list: + feature_result = self.analyse_traces(stimuli_list, traces_results, features) + feature_results.append(feature_result) + else: + pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) + run_stim_ = functools.partial(self.run_stim, model) + traces_results = pool.map(run_stim_, stimuli_list, chunksize=1) + # traces_results = traces_result.get() + pool.terminate() + pool.join() + del pool + + pool2 = multiprocessing.Pool(self.npool, maxtasksperchild=1) + analyse_traces_ = functools.partial(self.analyse_traces, stimuli_list, traces_results) + feature_results = pool2.map(analyse_traces_, features_list, chunksize=1) + # feature_results = feature_result.get() + pool2.terminate() + pool2.join() + del pool2 feature_results_dict={} for i in range (0,len(feature_results)): @@ -467,6 +476,8 @@ def generate_prediction(self, model, verbose=False): efel.reset() + self.SomaFeaturesDict = SomaFeaturesDict + return prediction def compute_score(self, observation, prediction, verbose=False): diff --git a/hippounit/utils.py b/hippounit/utils.py index e2bed06..3e3dcdc 100644 --- a/hippounit/utils.py +++ b/hippounit/utils.py @@ -19,6 +19,7 @@ import pkg_resources import sys +import re @@ -1381,3 +1382,31 @@ def setup_values(self): else: self.celsius = celsius self.trunk_origin = [0.5] + + +class ModelLoaderNeuroptimus(ModelLoader): + def __init__(self, name="model", mod_files_path=None, user_function_string=""): + super(ModelLoaderNeuroptimus, self).__init__(name=name, mod_files_path=mod_files_path) + self.candidate = None + self.user_function = None + self.set_user_function(user_function_string) + + def set_user_function(self, user_function_string): + global user_function_name + exec(user_function_string) + match_obj = re.search(r"(?<=def).*?(?=\()", user_function_string) + user_function_name = match_obj.group(0).strip() + setattr(self.__class__, user_function_name, locals()[user_function_name]) + self.user_function = user_function_name + + def set_candidate(self, candidate): + self.candidate = candidate + + def set_parameters(self): + v = self.candidate + exec("self.{user_function}(v)".format(user_function=self.user_function)) + + def initialise(self): + super(ModelLoaderNeuroptimus, self).initialise() + if self.candidate is not None: + self.set_parameters() From fefa366dfc7aa697bbc100a304fc9af817a15fe8 Mon Sep 17 00:00:00 2001 From: blazma Date: Thu, 6 Oct 2022 15:56:04 +0200 Subject: [PATCH 2/7] Load mod files only once --- hippounit/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/hippounit/utils.py b/hippounit/utils.py index 3e3dcdc..c14d836 100644 --- a/hippounit/utils.py +++ b/hippounit/utils.py @@ -108,6 +108,7 @@ def __init__(self, name="model", mod_files_path=None): self.base_directory = './validation_results/' # inside current directory self.find_section_lists = False + self.mod_files_loaded = False self.compile_mod_files() self.compile_default_NMDA() @@ -142,7 +143,9 @@ def initialise(self): # sys.stdout=open("trash","w") #sys.stdout=open('/dev/stdout', 'w') #rather print it to the console - this does not work above python 3.5 sys.stdout=open('/dev/null', 'a') #not showing it - self.load_mod_files() + if not self.mod_files_loaded: + self.load_mod_files() + self.mod_files_loaded = True if self.hocpath is None: raise Exception("Please give the path to the hoc file (eg. model.modelpath = \"/home/models/CA1_pyr/CA1_pyr_model.hoc\")") From 545ca928e593353a31cf225e3d7007fedcb6121f Mon Sep 17 00:00:00 2001 From: blazma Date: Fri, 7 Oct 2022 19:36:30 +0200 Subject: [PATCH 3/7] Load mod files in ModelLoader --- hippounit/utils.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/hippounit/utils.py b/hippounit/utils.py index c14d836..478b3ff 100644 --- a/hippounit/utils.py +++ b/hippounit/utils.py @@ -108,10 +108,10 @@ def __init__(self, name="model", mod_files_path=None): self.base_directory = './validation_results/' # inside current directory self.find_section_lists = False - self.mod_files_loaded = False self.compile_mod_files() self.compile_default_NMDA() + self.load_mod_files() def translate(self, sectiontype, distance=0): @@ -143,9 +143,6 @@ def initialise(self): # sys.stdout=open("trash","w") #sys.stdout=open('/dev/stdout', 'w') #rather print it to the console - this does not work above python 3.5 sys.stdout=open('/dev/null', 'a') #not showing it - if not self.mod_files_loaded: - self.load_mod_files() - self.mod_files_loaded = True if self.hocpath is None: raise Exception("Please give the path to the hoc file (eg. model.modelpath = \"/home/models/CA1_pyr/CA1_pyr_model.hoc\")") From 4a4d559c4bd5f39997a3b5abc235524c20f2c79e Mon Sep 17 00:00:00 2001 From: blazma Date: Mon, 17 Oct 2022 16:30:32 +0200 Subject: [PATCH 4/7] Serialize DepolarizationBlockTest --- .../tests/test_DepolarizationBlockTest.py | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/hippounit/tests/test_DepolarizationBlockTest.py b/hippounit/tests/test_DepolarizationBlockTest.py index daec5cc..2cb955c 100644 --- a/hippounit/tests/test_DepolarizationBlockTest.py +++ b/hippounit/tests/test_DepolarizationBlockTest.py @@ -93,6 +93,8 @@ class DepolarizationBlockTest(Test): If False, plots are not displayed but still saved save_all : boolean If False, only the JSON files containing the absolute feature values, the feature error scores and the final scores, and a log file are saved, but the figures and pickle files are not. + serialized : boolean + if True, simulation and feature analysis are not parallelized """ def __init__(self, @@ -100,8 +102,9 @@ def __init__(self, name="Depolarization block test" , force_run=False, base_directory= None, - show_plot=True, - save_all=True): + show_plot=True, + save_all=True, + serialized=False): observation = self.format_data(observation) @@ -125,6 +128,7 @@ def __init__(self, self.logFile = None self.test_log_filename = 'test_log.txt' + self.serialized = serialized description = "Tests if the model enters depolarization block under current injection of increasing amplitudes." @@ -567,17 +571,19 @@ def generate_prediction(self, model, verbose=False): efel.reset() - pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) - #amps = numpy.arange(0,3.55,0.05) - amps = numpy.arange(0,1.65,0.05) - - cclamp_ = functools.partial(self.cclamp, model, delay = 500, dur = 1000) - results = pool.map(cclamp_, amps, chunksize=1) - #results = result.get() - - pool.terminate() - pool.join() - del pool + amps = numpy.arange(0, 1.65, 0.05) + if self.serialized: + results = [] + for amp in amps: + cclamp = self.cclamp(model, amp, delay=500, dur=1000) + results.append(cclamp) + else: + pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) + cclamp_ = functools.partial(self.cclamp, model, delay = 500, dur = 1000) + results = pool.map(cclamp_, amps, chunksize=1) + pool.terminate() + pool.join() + del pool plt.close('all') #needed to avoid overlapping of saved images when the test is run on multiple models in a for loop From df10bd1be16b2ddcc8c20dafdfb36247a5366b62 Mon Sep 17 00:00:00 2001 From: blazma Date: Tue, 15 Nov 2022 18:30:09 +0100 Subject: [PATCH 5/7] Serialize DepolBlockTest and bAPTest, add penalty to bAPTest if neuron never fires --- .../scores/score_ZScore_backpropagatingAP.py | 3 + hippounit/tests/test_BackpropagatingAPTest.py | 64 +++++++++++++------ .../tests/test_DepolarizationBlockTest.py | 2 +- 3 files changed, 48 insertions(+), 21 deletions(-) diff --git a/hippounit/scores/score_ZScore_backpropagatingAP.py b/hippounit/scores/score_ZScore_backpropagatingAP.py index 1ad5572..4b94f31 100644 --- a/hippounit/scores/score_ZScore_backpropagatingAP.py +++ b/hippounit/scores/score_ZScore_backpropagatingAP.py @@ -25,6 +25,9 @@ def compute(cls, observation, prediction, distances): """Computes average of z-scores from observation and prediction for back-propagating AP amplitudes""" errors = collections.OrderedDict() + if not prediction: + never_fired_penalty = 250 + return [never_fired_penalty, never_fired_penalty], errors for i in range (0, len(distances)): if 'mean_AP1_amp_strong_propagating_at_'+str(distances[i])+'um' in list(observation.keys()) or 'mean_AP1_amp_weak_propagating_at_'+str(distances[i])+'um' in list(observation.keys()): diff --git a/hippounit/tests/test_BackpropagatingAPTest.py b/hippounit/tests/test_BackpropagatingAPTest.py index 896eab9..cbe97ff 100644 --- a/hippounit/tests/test_BackpropagatingAPTest.py +++ b/hippounit/tests/test_BackpropagatingAPTest.py @@ -102,6 +102,8 @@ class BackpropagatingAPTest(Test): If False, only the JSON files containing the absolute feature values, the feature error scores and the final scores, and a log file are saved, but the figures and pickle files are not. trunk_origin : list first element : name of the section from which the trunk originates, second element : position on section (E.g. ['soma[5]', 1]). If not set by the user, the end of the default soma section is used. + serialized : boolean + if True, the simulation is not parallelized """ def __init__(self, config = {}, @@ -131,7 +133,8 @@ def __init__(self, config = {}, base_directory= None, show_plot=True, save_all = True, - trunk_origin = None): + trunk_origin = None, + serialized = False): observation = self.format_data(observation) @@ -158,6 +161,7 @@ def __init__(self, config = {}, self.npool = multiprocessing.cpu_count() - 1 self.config = config + self.serialized = serialized description = "Tests the mode and efficacy of back-propagating action potentials on the apical trunk." @@ -213,12 +217,14 @@ def binsearch(self, model, stim_range, delay, dur, section_stim, loc_stim, secti result=[] - pool = multiprocessing.Pool(1, maxtasksperchild = 1) # I use multiprocessing to keep every NEURON related task in independent processes - - traces= pool.apply(self.run_cclamp_on_soma, args = (model, amplitude, delay, dur, section_stim, loc_stim, section_rec, loc_rec)) - pool.terminate() - pool.join() - del pool + if self.serialized: + traces = self.run_cclamp_on_soma(model, amplitude, delay, dur, section_stim, loc_stim, section_rec, loc_rec) + else: + pool = multiprocessing.Pool(1, maxtasksperchild = 1) # I use multiprocessing to keep every NEURON related task in independent processes + traces = pool.apply(self.run_cclamp_on_soma, args = (model, amplitude, delay, dur, section_stim, loc_stim, section_rec, loc_rec)) + pool.terminate() + pool.join() + del pool spikecount = self.spikecount(delay, dur, traces) @@ -290,15 +296,17 @@ def find_current_amp(self, model, delay, dur, section_stim, loc_stim, section_re #amps=[0.0,0.3,0.8] #amps=[0.0,0.2, 0.9] - pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) - - - run_cclamp_on_soma_ = functools.partial(self.run_cclamp_on_soma, model, delay=delay, dur=dur, section_stim=section_stim, loc_stim=loc_stim, section_rec=section_rec, loc_rec=loc_rec) - traces = pool.map(run_cclamp_on_soma_, amps, chunksize=1) - - pool.terminate() - pool.join() - del pool + if self.serialized: + traces = [] + for amp in amps: + traces.append(self.run_cclamp_on_soma(model, amp, delay=delay, dur=dur, section_stim=section_stim, loc_stim=loc_stim, section_rec=section_rec, loc_rec=loc_rec)) + else: + pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) + run_cclamp_on_soma_ = functools.partial(self.run_cclamp_on_soma, model, delay=delay, dur=dur, section_stim=section_stim, loc_stim=loc_stim, section_rec=section_rec, loc_rec=loc_rec) + traces = pool.map(run_cclamp_on_soma_, amps, chunksize=1) + pool.terminate() + pool.join() + del pool spikecounts = [] _spikecounts = [] @@ -311,6 +319,13 @@ def find_current_amp(self, model, delay, dur, section_stim, loc_stim, section_re for i in range(len(traces)): spikecounts.append(self.spikecount(delay, dur, traces[i])) + if not spikecounts: + message_to_logFile += 'The model did not fire at all for any current injection amplitude.\n' + message_to_logFile += "---------------------------------------------------------------------------------------------------\n" + + print('The model did not fire at all for any current injection amplitude') + amplitude = None + return amplitude, message_to_logFile if amps[0] == 0.0 and spikecounts[0] > 0: @@ -319,7 +334,7 @@ def find_current_amp(self, model, delay, dur, section_stim, loc_stim, section_re print('Spontaneous firing') amplitude = None - """TODO: stop the whole thing""" + return amplitude, message_to_logFile elif max(spikecounts) < 10: @@ -328,6 +343,7 @@ def find_current_amp(self, model, delay, dur, section_stim, loc_stim, section_re print('The model fired at ' + str(max(spikecounts)[0]) + ' Hz to ' + str(amps[-1]) + ' nA current step, and did not reach 10 Hz firing rate as supposed (according to Bianchi et al 2012 Fig. 1 B eg.)') amplitude = None + return amplitude, message_to_logFile else: for i in range(len(spikecounts)): @@ -750,7 +766,10 @@ def generate_prediction(self, model, verbose=False): distances = self.config['recording']['distances'] tolerance = self.config['recording']['tolerance'] - dend_locations, actual_distances = model.find_trunk_locations_multiproc(distances, tolerance, self.trunk_origin) + if self.serialized: + dend_locations, actual_distances = model.find_trunk_locations(distances, tolerance, self.trunk_origin) + else: + dend_locations, actual_distances = model.find_trunk_locations_multiproc(distances, tolerance, self.trunk_origin) #print dend_locations, actual_distances print('Dendritic locations to be tested (with their actual distances):', actual_distances) @@ -766,9 +785,14 @@ def generate_prediction(self, model, verbose=False): plt.close('all') #needed to avoid overlapping of saved images when the test is run on multiple models amplitude, message_to_logFile = self.find_current_amp(model, delay, duration, "soma", 0.5, "soma", 0.5) + if amplitude is None: + return prediction - pool = multiprocessing.Pool(1, maxtasksperchild = 1) - traces = pool.apply(self.cclamp, args = (model, amplitude, delay, duration, "soma", 0.5, dend_locations)) + if self.serialized: + traces = self.cclamp(model, amplitude, delay, duration, "soma", 0.5, dend_locations) + else: + pool = multiprocessing.Pool(1, maxtasksperchild = 1) + traces = pool.apply(self.cclamp, args = (model, amplitude, delay, duration, "soma", 0.5, dend_locations)) filepath = self.path_results + self.test_log_filename self.logFile = open(filepath, 'w') # if it is opened before multiprocessing, the multiporeccing won't work under python3 diff --git a/hippounit/tests/test_DepolarizationBlockTest.py b/hippounit/tests/test_DepolarizationBlockTest.py index 2cb955c..480592e 100644 --- a/hippounit/tests/test_DepolarizationBlockTest.py +++ b/hippounit/tests/test_DepolarizationBlockTest.py @@ -94,7 +94,7 @@ class DepolarizationBlockTest(Test): save_all : boolean If False, only the JSON files containing the absolute feature values, the feature error scores and the final scores, and a log file are saved, but the figures and pickle files are not. serialized : boolean - if True, simulation and feature analysis are not parallelized + if True, the simulation is not parallelized """ def __init__(self, From 44ea44d33793d919cc285d65a956f93e36e9471d Mon Sep 17 00:00:00 2001 From: blazma Date: Mon, 21 Nov 2022 18:01:57 +0100 Subject: [PATCH 6/7] Serialize PSP Attenuation test --- hippounit/tests/test_PSPAttenuationTest.py | 54 +++++++++++++++------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/hippounit/tests/test_PSPAttenuationTest.py b/hippounit/tests/test_PSPAttenuationTest.py index 7fdd4c6..0bb8b33 100644 --- a/hippounit/tests/test_PSPAttenuationTest.py +++ b/hippounit/tests/test_PSPAttenuationTest.py @@ -104,6 +104,8 @@ class PSPAttenuationTest(Test): random seed for random dendritic location selection trunk_origin : list first element : name of the section from which the trunk originates, second element : position on section (E.g. ['soma[5]', 1]). If not set by the user, the end of the default soma section is used. + serialized : boolean + if True, the simulation is not parallelized """ def __init__(self, config = {}, @@ -116,7 +118,8 @@ def __init__(self, config = {}, num_of_dend_locations = 15, random_seed = 1, save_all = True, - trunk_origin = None): + trunk_origin = None, + serialized=False): observation = self.format_data(observation) @@ -144,6 +147,7 @@ def __init__(self, config = {}, self.num_of_dend_locations = num_of_dend_locations self.random_seed = random_seed + self.serialized = serialized description = "Tests how much synaptic potential attenuates from the dendrite (different distances) to the soma." @@ -481,7 +485,15 @@ def generate_prediction(self, model, verbose=False): EPSC_amp = self.config['EPSC_amplitude'] model.SecList_name = model.TrunkSecList_name - locations, locations_distances = model.get_random_locations_multiproc(self.num_of_dend_locations, self.random_seed, dist_range, self.trunk_origin) # number of random locations , seed + if self.serialized: + locations, locations_distances = model.get_random_locations(self.num_of_dend_locations, + self.random_seed, dist_range, + self.trunk_origin) + else: + locations, locations_distances = model.get_random_locations_multiproc(self.num_of_dend_locations, + self.random_seed, dist_range, + self.trunk_origin) # number of random locations , seed + #print dend_locations, actual_distances print('Dendritic locations to be tested (with their actual distances):', locations_distances) @@ -494,25 +506,35 @@ def generate_prediction(self, model, verbose=False): #print locations_weights """ run model without an input""" - pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) - run_stimulus_ = functools.partial(self.run_stimulus, model, tau1 = tau1, tau2 = tau2) - traces_no_input = pool.map(run_stimulus_, locations_weights, chunksize=1) - - pool.terminate() - pool.join() - del pool + if self.serialized: + traces_no_input = [] + for locations_weight in locations_weights: + trace = self.run_stimulus(model, locations_weight, tau1=tau1, tau2=tau2) + traces_no_input.append(trace) + else: + pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) + run_stimulus_ = functools.partial(self.run_stimulus, model, tau1 = tau1, tau2 = tau2) + traces_no_input = pool.map(run_stimulus_, locations_weights, chunksize=1) + pool.terminate() + pool.join() + del pool traces_dict_no_input = dict(list(i.items())[0] for i in traces_no_input) # merge list of dicts into single dict locations_weights = self.calculate_weights(traces_dict_no_input, EPSC_amp) """run model with inputs""" - pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) - run_stimulus_ = functools.partial(self.run_stimulus, model, tau1 = tau1, tau2 = tau2) - traces = pool.map(run_stimulus_, locations_weights, chunksize=1) - - pool.terminate() - pool.join() - del pool + if self.serialized: + traces = [] + for locations_weight in locations_weights: + trace = self.run_stimulus(model, locations_weight, tau1=tau1, tau2=tau2) + traces.append(trace) + else: + pool = multiprocessing.Pool(self.npool, maxtasksperchild=1) + run_stimulus_ = functools.partial(self.run_stimulus, model, tau1 = tau1, tau2 = tau2) + traces = pool.map(run_stimulus_, locations_weights, chunksize=1) + pool.terminate() + pool.join() + del pool traces_dict = dict(list(i.items())[0] for i in traces) # merge list of dicts into single dict From 9c3dfa7b3b47887b95fbff135cb14ec79d78763b Mon Sep 17 00:00:00 2001 From: blazma Date: Tue, 20 Dec 2022 17:18:18 +0100 Subject: [PATCH 7/7] [wip] Serialize ObliqueIntegrationTest --- .../tests/test_ObliqueIntegrationTest.py | 52 +++++++++++-------- hippounit/utils.py | 3 +- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/hippounit/tests/test_ObliqueIntegrationTest.py b/hippounit/tests/test_ObliqueIntegrationTest.py index 2beddfa..f5d2b18 100644 --- a/hippounit/tests/test_ObliqueIntegrationTest.py +++ b/hippounit/tests/test_ObliqueIntegrationTest.py @@ -119,6 +119,8 @@ class ObliqueIntegrationTest(Test): If False, only the JSON files containing the absolute feature values, the feature error scores and the final scores, and a log file are saved, but the figures and pickle files are not. trunk_origin : list first element : name of the section from which the trunk originates, second element : position on section (E.g. ['soma[5]', 1]). If not set by the user, the end of the default soma section is used. + serialized : boolean + if True, the simulation is not parallelized """ def __init__(self, @@ -137,7 +139,8 @@ def __init__(self, base_directory= None, show_plot=True, save_all = True, - trunk_origin = None): + trunk_origin = None, + serialized=False): observation = self.format_data(observation) observation = self.add_std_to_observation(observation) @@ -165,6 +168,7 @@ def __init__(self, self.max_num_syn = 10 self.threshold_index = 5 #threshold input number for dendritic spike generation - index 0 is 0 input + self.serialized = serialized description = "Tests the signal integration in oblique dendrites for increasing number of synchronous and asynchronous inputs" @@ -323,13 +327,14 @@ def binsearch(self, model, dend_loc0): for n in num: - - pool_syn = multiprocessing.Pool(1, maxtasksperchild = 1) # I use multiprocessing to keep every NEURON related task in independent processes - - t, v, v_dend = pool_syn.apply(self.syn_binsearch, args = (model, dend_loc0, interval, n, c_stim[midpoint])) - pool_syn.terminate() - pool_syn.join() - del pool_syn + if self.serialized: + t, v, v_dend = self.syn_binsearch(model, dend_loc0, interval, n, c_stim[midpoint]) + else: + pool_syn = multiprocessing.Pool(1, maxtasksperchild = 1) # I use multiprocessing to keep every NEURON related task in independent processes + t, v, v_dend = pool_syn.apply(self.syn_binsearch, args = (model, dend_loc0, interval, n, c_stim[midpoint])) + pool_syn.terminate() + pool_syn.join() + del pool_syn result.append(self.analyse_syn_traces(model, t, v, v_dend, model.threshold)) #print result @@ -1687,8 +1692,10 @@ def generate_prediction(self, model, verbose=False): raise pass - - model.find_obliques_multiproc(self.trunk_origin) + if self.serialized: + model.dend_loc = model.find_good_obliques(self.trunk_origin) + else: + model.find_obliques_multiproc(self.trunk_origin) print('Dendrites and locations to be tested: ', model.dend_loc) @@ -1706,18 +1713,19 @@ def generate_prediction(self, model, verbose=False): print('The default NMDA model of HippoUnit is used with Jahr, Stevens voltage dependence.') print('') - #pool0 = multiprocessing.pool.ThreadPool(self.npool) # multiprocessing.pool.ThreadPool is used because a nested multiprocessing is used in the function called here (to keep every NEURON related task in independent processes) - pool0 = NonDaemonPool(self.npool, maxtasksperchild = 1) - - print("Adjusting synaptic weights on all the locations ...") - - binsearch_ = functools.partial(self.binsearch, model) - results0 = pool0.map(binsearch_, model.dend_loc, chunksize=1) #model.dend_loc[0:2] - no need for info if it is distal or proximal - #results0 = result0.get() - - pool0.terminate() - pool0.join() - del pool0 + ##pool0 = multiprocessing.pool.ThreadPool(self.npool) # multiprocessing.pool.ThreadPool is used because a nested multiprocessing is used in the function called here (to keep every NEURON related task in independent processes) + #pool0 = NonDaemonPool(self.npool, maxtasksperchild = 1) + #print("Adjusting synaptic weights on all the locations ...") + #binsearch_ = functools.partial(self.binsearch, model) + #results0 = pool0.map(binsearch_, model.dend_loc, chunksize=1) #model.dend_loc[0:2] - no need for info if it is distal or proximal + results0 = [] + for dend_loc in model.dend_loc: + result0 = self.binsearch(model, dend_loc) + results0.append(result0) + ##results0 = result0.get() + #pool0.terminate() + #pool0.join() + #del pool0 num = numpy.arange(0,self.max_num_syn+1) diff --git a/hippounit/utils.py b/hippounit/utils.py index 478b3ff..55a03b4 100644 --- a/hippounit/utils.py +++ b/hippounit/utils.py @@ -111,7 +111,7 @@ def __init__(self, name="model", mod_files_path=None): self.compile_mod_files() self.compile_default_NMDA() - self.load_mod_files() + self.load_mod_files() # if this is here Oblique does NOT work but everything else does def translate(self, sectiontype, distance=0): @@ -143,6 +143,7 @@ def initialise(self): # sys.stdout=open("trash","w") #sys.stdout=open('/dev/stdout', 'w') #rather print it to the console - this does not work above python 3.5 sys.stdout=open('/dev/null', 'a') #not showing it + #self.load_mod_files() # if this is here then Oblique works, if it is not here everything else works if self.hocpath is None: raise Exception("Please give the path to the hoc file (eg. model.modelpath = \"/home/models/CA1_pyr/CA1_pyr_model.hoc\")")