From 1d03c03c71e980187963ce705ff8694cab9d696c Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:18:00 -0600 Subject: [PATCH 1/7] Make real time convergence stats optional If we try to display convergence stats when there is no terminal, the run will fail. --- radvel/cli.py | 3 +++ radvel/driver.py | 2 +- radvel/mcmc.py | 17 ++++++++++------- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/radvel/cli.py b/radvel/cli.py index 56343f74..e3c5071c 100644 --- a/radvel/cli.py +++ b/radvel/cli.py @@ -113,6 +113,9 @@ def main(): psr_mcmc.add_argument('--proceed', dest='proceed', action='store_true', help='If True, MCMC chains will resume from the previous run' ) + psr_mcmc.add_argument('--headless', dest='headless', action='store_true', default=False, + help='If True, convergence stats will not display in real time' + ) psr_mcmc.set_defaults(func=radvel.driver.mcmc) # Derive physical parameters diff --git a/radvel/driver.py b/radvel/driver.py index 9303dfd7..3ed2cb9a 100644 --- a/radvel/driver.py +++ b/radvel/driver.py @@ -195,7 +195,7 @@ def mcmc(args): minAfactor=args.minAfactor, maxArchange=args.maxArchange, burnAfactor=args.burnAfactor, burnGR=args.burnGR, maxGR=args.maxGR, minTz=args.minTz, minsteps=args.minsteps, minpercent=args.minpercent, thin=args.thin, serial=args.serial, save=args.save, - savename=backend_loc, proceed=args.proceed, proceedname=backend_loc) + savename=backend_loc, proceed=args.proceed, proceedname=backend_loc, headless=args.headless) mintz = statevars.mintz maxgr = statevars.maxgr diff --git a/radvel/mcmc.py b/radvel/mcmc.py index 65f884c9..8ed3aca6 100644 --- a/radvel/mcmc.py +++ b/radvel/mcmc.py @@ -101,7 +101,7 @@ def _status_message_CLI(statevars): statevars.screen.refresh() -def convergence_check(minAfactor, maxArchange, maxGR, minTz, minsteps, minpercent): +def convergence_check(minAfactor, maxArchange, maxGR, minTz, minsteps, minpercent, headless): """Check for convergence Check for convergence for a list of emcee samplers @@ -116,6 +116,7 @@ def convergence_check(minAfactor, maxArchange, maxGR, minTz, minsteps, minpercen will start after the minsteps threshold or the minpercent threshold has been hit. minpercent (float): Minimum percentage of total steps before convergence tests are performed. Convergence checks will start after the minsteps threshold or the minpercent threshold has been hit. + headless (bool): if set to true, the convergence statistics will not be displayed in real time. """ statevars.ar = 0 @@ -165,10 +166,11 @@ def convergence_check(minAfactor, maxArchange, maxGR, minTz, minsteps, minpercen else: statevars.mixcount = 0 - if isnotebook(): - _status_message_NB(statevars) - else: - _status_message_CLI(statevars) + if not headless: + if isnotebook(): + _status_message_NB(statevars) + else: + _status_message_CLI(statevars) def _domcmc(input_tuple): @@ -186,7 +188,7 @@ def _domcmc(input_tuple): def mcmc(post, nwalkers=50, nrun=10000, ensembles=8, checkinterval=50, minAfactor=40, maxArchange=.03, burnAfactor=25, burnGR=1.03, maxGR=1.01, minTz=1000, minsteps=1000, minpercent=5, thin=1, serial=False, save=False, - savename=None, proceed=False, proceedname=None): + savename=None, proceed=False, proceedname=None, headless=False): """Run MCMC Run MCMC chains using the emcee EnsambleSampler Args: @@ -215,6 +217,7 @@ def mcmc(post, nwalkers=50, nrun=10000, ensembles=8, checkinterval=50, minAfacto savename (string): location of h5py file where MCMC chains will be saved for future use proceed (bool): set to true to continue a previously saved run proceedname (string): location of h5py file with previously MCMC run chains + headless (bool): if set to true, the convergence statistics will not display in real time Returns: DataFrame: DataFrame containing the MCMC samples """ @@ -385,7 +388,7 @@ def mcmc(post, nwalkers=50, nrun=10000, ensembles=8, checkinterval=50, minAfacto statevars.interval = t2 - t1 convergence_check(minAfactor=minAfactor, maxArchange=maxArchange, maxGR=maxGR, minTz=minTz, - minsteps=minsteps, minpercent=minpercent) + minsteps=minsteps, minpercent=minpercent, headless=headless) if save: for i, sampler in enumerate(statevars.samplers): From 1a3a8ded74406fd464f24d594568bee55456c1fc Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:35:01 -0600 Subject: [PATCH 2/7] Testing --- radvel/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radvel/__init__.py b/radvel/__init__.py index 92a2156a..4c7b808d 100644 --- a/radvel/__init__.py +++ b/radvel/__init__.py @@ -29,7 +29,7 @@ def _custom_warningfmt(msg, *a, **b): __all__ = ['model', 'likelihood', 'posterior', 'mcmc', 'prior', 'utils', 'fitting', 'report', 'cli', 'driver', 'gp'] -__version__ = '1.4.0' +__version__ = '2.0.0' __spec__ = __name__ __package__ = __path__[0] From e68007ec20cdfccec82895e25b30c8564c609698 Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:37:46 -0600 Subject: [PATCH 3/7] Version Number --- radvel/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radvel/__init__.py b/radvel/__init__.py index 4c7b808d..92a2156a 100644 --- a/radvel/__init__.py +++ b/radvel/__init__.py @@ -29,7 +29,7 @@ def _custom_warningfmt(msg, *a, **b): __all__ = ['model', 'likelihood', 'posterior', 'mcmc', 'prior', 'utils', 'fitting', 'report', 'cli', 'driver', 'gp'] -__version__ = '2.0.0' +__version__ = '1.4.0' __spec__ = __name__ __package__ = __path__[0] From 7b7994d0abe5bdec1540afdcfe7bc829135733eb Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:48:20 -0600 Subject: [PATCH 4/7] Change to CLI --- radvel/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radvel/cli.py b/radvel/cli.py index e3c5071c..f6d31e55 100644 --- a/radvel/cli.py +++ b/radvel/cli.py @@ -113,7 +113,7 @@ def main(): psr_mcmc.add_argument('--proceed', dest='proceed', action='store_true', help='If True, MCMC chains will resume from the previous run' ) - psr_mcmc.add_argument('--headless', dest='headless', action='store_true', default=False, + psr_mcmc.add_argument('--headless', dest='headless', action='store_true', help='If True, convergence stats will not display in real time' ) psr_mcmc.set_defaults(func=radvel.driver.mcmc) From 9284348936d5a3aa7a5da69a2bec15c45c1ee0f5 Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:52:01 -0600 Subject: [PATCH 5/7] version loaded --- radvel/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radvel/__init__.py b/radvel/__init__.py index 92a2156a..0857d24e 100644 --- a/radvel/__init__.py +++ b/radvel/__init__.py @@ -29,7 +29,7 @@ def _custom_warningfmt(msg, *a, **b): __all__ = ['model', 'likelihood', 'posterior', 'mcmc', 'prior', 'utils', 'fitting', 'report', 'cli', 'driver', 'gp'] -__version__ = '1.4.0' +__version__ = '1.4.1' __spec__ = __name__ __package__ = __path__[0] From 9d00001651379ef7a1f73770476c887588f56b9b Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Mon, 1 Jun 2020 15:55:51 -0600 Subject: [PATCH 6/7] Fixing tests --- radvel/tests/test_api.py | 1 + 1 file changed, 1 insertion(+) diff --git a/radvel/tests/test_api.py b/radvel/tests/test_api.py index febc947f..67ae2fc3 100644 --- a/radvel/tests/test_api.py +++ b/radvel/tests/test_api.py @@ -36,6 +36,7 @@ class _args(types.SimpleNamespace): savename = 'rawchains.h5' proceed = False proceedname = None + headless=False def _standard_run(setupfn, arguments): From 78135a2e40f952d692fcdee301d3b5250cfdaa91 Mon Sep 17 00:00:00 2001 From: Spencer Hurt Date: Thu, 4 Jun 2020 10:40:32 -0600 Subject: [PATCH 7/7] Vary flexibility Allowing the vary attribute of parameters to be changed without setting up a new likelihood --- radvel/likelihood.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/radvel/likelihood.py b/radvel/likelihood.py index c133f559..dcf2add9 100644 --- a/radvel/likelihood.py +++ b/radvel/likelihood.py @@ -143,18 +143,15 @@ def set_vary_params(self, param_values_array): param_values_array = list(param_values_array) i = 0 try: - for index in self.vary_params: - self.vector.vector[index][0] = param_values_array[i] - i += 1 - assert i == len(param_values_array), \ - "Length of array must match number of varied parameters" + if len(self.vary_params) != len(param_values_array): + self.list_vary_params() except AttributeError: self.list_vary_params() - for index in self.vary_params: - self.vector.vector[index][0] = param_values_array[i] - i += 1 - assert i == len(param_values_array), \ - "Length of array must match number of varied parameters" + for index in self.vary_params: + self.vector.vector[index][0] = param_values_array[i] + i += 1 + assert i == len(param_values_array), \ + "Length of array must match number of varied parameters" def get_vary_params(self): try: