From 64e62e1c4a78d653f71235b67f32aa8b9cfa2122 Mon Sep 17 00:00:00 2001 From: Anil Tuncel Date: Thu, 4 Apr 2024 18:36:34 +0200 Subject: [PATCH] attempt to feature extraction in parallel --- bluepyefe/cell.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/bluepyefe/cell.py b/bluepyefe/cell.py index cd60b48..b91b1a1 100644 --- a/bluepyefe/cell.py +++ b/bluepyefe/cell.py @@ -19,6 +19,7 @@ 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. """ import logging +from multiprocessing import Pool import numpy import matplotlib.pyplot as plt import pathlib @@ -172,6 +173,12 @@ def read_recordings( f"the available stimuli names" ) + def extract_efeatures_helper(self, recording_id, efeatures, efeature_names, efel_settings): + """Helper function to compute efeatures for a single recording.""" + self.recordings[recording_id].compute_efeatures( + efeatures, efeature_names, efel_settings) + return self.recordings[recording_id] + def extract_efeatures( self, protocol_name, @@ -192,10 +199,17 @@ def extract_efeatures( is to be extracted several time on different sections of the same recording. """ + recording_ids = self.get_recordings_id_by_protocol_name(protocol_name) + + # Run in parallel via multiprocessing + with Pool(maxtasksperchild=1) as pool: + tasks = [ + (rec_id, efeatures, efeature_names, efel_settings) + for rec_id in recording_ids + ] + results = pool.starmap(self.extract_efeatures_helper, tasks) - for i in self.get_recordings_id_by_protocol_name(protocol_name): - self.recordings[i].compute_efeatures( - efeatures, efeature_names, efel_settings) + self.recordings = results def compute_relative_amp(self): """Compute the relative current amplitude for all the recordings as a