From 0e093e56c6ff5a9d068e6925f594b6e2607e2770 Mon Sep 17 00:00:00 2001 From: blazma Date: Tue, 20 Dec 2022 17:18:18 +0100 Subject: [PATCH] [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 6734e4a..06c2148 100644 --- a/hippounit/utils.py +++ b/hippounit/utils.py @@ -110,7 +110,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): @@ -142,6 +142,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\")")