Skip to content

Commit

Permalink
Serialize PSP Attenuation test
Browse files Browse the repository at this point in the history
  • Loading branch information
blazma committed Nov 21, 2022
1 parent aed783f commit da7da26
Showing 1 changed file with 37 additions and 16 deletions.
53 changes: 37 additions & 16 deletions hippounit/tests/test_PSPAttenuationTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {},
Expand All @@ -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)

Expand Down Expand Up @@ -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."

Expand Down Expand Up @@ -480,7 +484,14 @@ def generate_prediction(self, model, verbose=False):
tau2 = self.config['tau_decay']
EPSC_amp = self.config['EPSC_amplitude']

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)

Expand All @@ -493,25 +504,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


Expand Down

0 comments on commit da7da26

Please sign in to comment.