From 26d07c8eae44d0a6919fd775728cdb1bb2808298 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 19 Aug 2021 09:50:40 +0200 Subject: ParallelParamFit -> ParamFit, optionally without parallelism --- lib/paramfit.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib/paramfit.py') diff --git a/lib/paramfit.py b/lib/paramfit.py index 8bc7505..5fdaf7a 100644 --- a/lib/paramfit.py +++ b/lib/paramfit.py @@ -17,7 +17,7 @@ from .utils import ( logger = logging.getLogger(__name__) -class ParallelParamFit: +class ParamFit: """ Fit a set of functions on parameterized measurements. @@ -25,9 +25,10 @@ class ParallelParamFit: function type for each parameter. """ - def __init__(self): - """Create a new ParallelParamFit object.""" + def __init__(self, parallel=True): + """Create a new ParamFit object.""" self.fit_queue = list() + self.parallel = parallel def enqueue(self, key, param, args, kwargs=dict()): """ @@ -49,10 +50,13 @@ class ParallelParamFit: Fitting is one in parallel with one process per core. - Results can be accessed using the public ParallelParamFit.results object. + Results can be accessed using the public ParamFit.results object. """ - with Pool() as pool: - self.results = pool.map(_try_fits_parallel, self.fit_queue) + if self.parallel: + with Pool() as pool: + self.results = pool.map(_try_fits_parallel, self.fit_queue) + else: + self.results = list(map(_try_fits_parallel, self.fit_queue)) def get_result(self, key): """ -- cgit v1.2.3