From 95f57d81ad8650017358e08fbf25cce8b88e7752 Mon Sep 17 00:00:00 2001 From: Sylvia Biscoveanu <sylvia.biscoveanu@ligo.org> Date: Mon, 1 Oct 2018 23:39:02 -0500 Subject: [PATCH] =?UTF-8?q?Shortening=20the=20pymultinest=20output=20direc?= =?UTF-8?q?tory=20name=20and=20adding=20a=20warning=20if=20the=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 1 + test/sampler_test.py | 4 ++-- tupak/core/sampler/pymultinest.py | 19 +++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 28a02b7d..cdf3e209 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ re-instantiate the Prior in most cases - Users can now choose to overwrite existing result files, rather than creating a .old file. - Make likelihood values stored in the posterior correct for dynesty and nestle +- pymultinest output now stored in {outdir}/pm_{label}/ ### Removed - Removes the "--detectors" command line argument (not a general CLI requirement) diff --git a/test/sampler_test.py b/test/sampler_test.py index 53ec81b1..035d5324 100644 --- a/test/sampler_test.py +++ b/test/sampler_test.py @@ -360,7 +360,7 @@ class TestPymultinest(unittest.TestCase): def test_default_kwargs(self): expected = dict(importance_nested_sampling=False, resume=True, verbose=True, sampling_efficiency='parameter', - outputfiles_basename='outdir/pymultinest_label/', + outputfiles_basename='outdir/pm_label/', n_live_points=500, n_params=None, n_clustering_params=None, wrapped_params=None, multimodal=True, const_efficiency_mode=False, @@ -374,7 +374,7 @@ class TestPymultinest(unittest.TestCase): def test_translate_kwargs(self): expected = dict(importance_nested_sampling=False, resume=True, verbose=True, sampling_efficiency='parameter', - outputfiles_basename='outdir/pymultinest_label/', + outputfiles_basename='outdir/pm_label/', n_live_points=123, n_params=None, n_clustering_params=None, wrapped_params=None, multimodal=True, const_efficiency_mode=False, diff --git a/tupak/core/sampler/pymultinest.py b/tupak/core/sampler/pymultinest.py index 4ea5b0f2..02536831 100644 --- a/tupak/core/sampler/pymultinest.py +++ b/tupak/core/sampler/pymultinest.py @@ -2,6 +2,7 @@ from __future__ import absolute_import from ..utils import check_directory_exists_and_if_not_mkdir from .base_sampler import NestedSampler +from tupak.core.utils import logger class Pymultinest(NestedSampler): @@ -48,12 +49,26 @@ class Pymultinest(NestedSampler): kwargs['n_live_points'] = kwargs.pop(equiv) def _verify_kwargs_against_default_kwargs(self): + """ + Test the length of the directory where multinest will write the output. + + This is an issue with MultiNest that we can't solve here. + https://github.com/JohannesBuchner/PyMultiNest/issues/115 + """ if not self.kwargs['outputfiles_basename']: - self.kwargs['outputfiles_basename'] = self.outdir + '/pymultinest_{}/'.format(self.label) + self.kwargs['outputfiles_basename'] =\ + '{}/pm_{}/'.format(self.outdir, self.label) if self.kwargs['outputfiles_basename'].endswith('/') is False: self.kwargs['outputfiles_basename'] = '{}/'.format( self.kwargs['outputfiles_basename']) - check_directory_exists_and_if_not_mkdir(self.kwargs['outputfiles_basename']) + if len(self.kwargs['outputfiles_basename']) > (100 - 22): + logger.warning( + 'The length of {} exceeds 78 characters. ' + ' Post-processing will fail because the file names will be cut' + ' off. Please choose a shorter "outdir" or "label".' + .format(self.__kwargs['outputfiles_basename'])) + check_directory_exists_and_if_not_mkdir( + self.kwargs['outputfiles_basename']) NestedSampler._verify_kwargs_against_default_kwargs(self) def run_sampler(self): -- GitLab