From 1d403cff55a0c6d02c35db5bb7f294f2e1a552c5 Mon Sep 17 00:00:00 2001 From: Nick Reynolds Tran Date: Sun, 11 Dec 2022 14:41:21 -0600 Subject: [PATCH 1/3] Adding parallelization to fit_uv When calling gaussian_model, you can do ```py ... ncores = 10 # of processes to start, usually 2x the number of physical cores uv.fit_models(..., ncores=ncores) ``` This will greatly speed up the fit_models. For simple 1-2 gaussians it doesn't make too much difference but 4 gaussians, the fits were taking >10 hours This still isn't the most efficient as at the start of the cycle all the cores specified are used and then at end of every cycle you will have most of the cores waiting on just a couple to finish, but the bottleneck is now at dynesty implementation of MP. --- pdspy/interferometry/fit_model.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/pdspy/interferometry/fit_model.py b/pdspy/interferometry/fit_model.py index 8e6ac99..a6e62db 100644 --- a/pdspy/interferometry/fit_model.py +++ b/pdspy/interferometry/fit_model.py @@ -7,9 +7,9 @@ #import dynesty.plotting as dyplot from .model import model -def fit_model(data, funct='point', nsteps=1e3, niter=3, max_size=numpy.inf, \ - xmax=10., ymax=10., step_size=0.1, min_separation=1., \ - primary_beam=None, image_rms=None): +def fit_model(data, funct='point', max_size=numpy.inf, \ + xmax=10., ymax=10., min_separation=1., \ + primary_beam=None, image_rms=None, ncores=1): if type(funct) == str: funct = numpy.array([funct]) @@ -62,21 +62,25 @@ def fit_model(data, funct='point', nsteps=1e3, niter=3, max_size=numpy.inf, \ periodic.append(int(nparams.sum()-2)) ndim = int(nparams.sum()) - nlive = int(4*xmax*ymax / step_size**2) + nlive = 250 + nsteps = 1000 xlim = [[-xmax, xmax] for i in range(funct.size)] ylim = [[-ymax, ymax] for i in range(funct.size)] # Set up the dynesty sampler. - - sampler = dynesty.NestedSampler(lnlike, ptform, ndim=ndim, nlive=250, \ - bound='multi', logl_args=(x, y, z, zerr, funct, nparams,\ - primary_beam, data.freq.mean()), ptform_args=(funct, nparams, \ - xlim, ylim, max_size, min_separation, image_rms), periodic=periodic) - - # Run the nested sampling. - - sampler.run_nested(dlogz=0.05) + use_pool = {'prior_transform': True, 'propose_point': True, 'update_bound': True, 'loglikelihood': True} + with dynesty.pool.Pool(njobs=ncores, loglike=lnlike, prior_transform=ptform, + logl_args=(x, y, z, zerr, funct, nparams, + primary_beam, data.freq.mean()), + ptform_args=(funct, nparams,xlim, ylim, max_size, + min_separation, image_rms) + sampler = dynesty.NestedSampler(pool.loglike, pool.prior_transform, ndim=ndim, + nlive=nlive, bound='multi', walks=nsteps, + periodic=periodic, pool=pool) + + # Run the nested sampling. + sampler.run_nested(dlogz=0.05) # Get the samples. From a960d3c8d4b6fa0ea4ea27f394f78155507f5bb0 Mon Sep 17 00:00:00 2001 From: Nick Reynolds Tran Date: Sun, 5 Mar 2023 14:51:53 -0600 Subject: [PATCH 2/3] Update fit_model.py --- pdspy/interferometry/fit_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdspy/interferometry/fit_model.py b/pdspy/interferometry/fit_model.py index a6e62db..3b5aed5 100644 --- a/pdspy/interferometry/fit_model.py +++ b/pdspy/interferometry/fit_model.py @@ -74,7 +74,7 @@ def fit_model(data, funct='point', max_size=numpy.inf, \ logl_args=(x, y, z, zerr, funct, nparams, primary_beam, data.freq.mean()), ptform_args=(funct, nparams,xlim, ylim, max_size, - min_separation, image_rms) + min_separation, image_rms)): sampler = dynesty.NestedSampler(pool.loglike, pool.prior_transform, ndim=ndim, nlive=nlive, bound='multi', walks=nsteps, periodic=periodic, pool=pool) From 9cc912553dee5e8978b9969d9dd27227577e275b Mon Sep 17 00:00:00 2001 From: Nick Reynolds Tran Date: Sun, 5 Mar 2023 14:59:48 -0600 Subject: [PATCH 3/3] Update fit_model.py --- pdspy/interferometry/fit_model.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdspy/interferometry/fit_model.py b/pdspy/interferometry/fit_model.py index 3b5aed5..9c9a315 100644 --- a/pdspy/interferometry/fit_model.py +++ b/pdspy/interferometry/fit_model.py @@ -74,7 +74,7 @@ def fit_model(data, funct='point', max_size=numpy.inf, \ logl_args=(x, y, z, zerr, funct, nparams, primary_beam, data.freq.mean()), ptform_args=(funct, nparams,xlim, ylim, max_size, - min_separation, image_rms)): + min_separation, image_rms)) as pool: sampler = dynesty.NestedSampler(pool.loglike, pool.prior_transform, ndim=ndim, nlive=nlive, bound='multi', walks=nsteps, periodic=periodic, pool=pool)