From 0f14f829377e02a6f851ea25e834690f7ece95eb Mon Sep 17 00:00:00 2001 From: Bingjie Wang Date: Sat, 3 Jan 2026 10:21:50 -0500 Subject: [PATCH 1/2] add keywords for setting up dynesty and nautilus --- prospect/fitting/fitting.py | 29 ++++++++++++++++++++++++++++- prospect/fitting/nested.py | 37 +++++++++++++++++++++++++++++++++---- 2 files changed, 61 insertions(+), 5 deletions(-) diff --git a/prospect/fitting/fitting.py b/prospect/fitting/fitting.py index 2342afec..d79c9c9e 100755 --- a/prospect/fitting/fitting.py +++ b/prospect/fitting/fitting.py @@ -6,7 +6,7 @@ """ -import time +import time, sys from functools import partial as argfix import numpy as np @@ -431,6 +431,17 @@ def run_nested(observations, model, sps, nested_sampler="dynesty", nested_nlive=1000, nested_target_n_effective=1000, + nested_n_like_max=sys.maxsize, + nested_dlogz=0.01, + nested_nlive_batch=200, + nested_maxiter=sys.maxsize, + nested_maxcall=sys.maxsize, + nested_maxiter_init=sys.maxsize, + nested_maxcall_init=sys.maxsize, + nested_maxiter_batch=sys.maxsize, + nested_maxcall_batch=sys.maxsize, + nested_maxbatch=sys.maxsize, + nested_wt_kwargs={'pfrac': 1.0}, verbose=False, **kwargs): """Thin wrapper on :py:class:`prospect.fitting.nested.run_nested_sampler` @@ -461,6 +472,14 @@ def run_nested(observations, model, sps, Number of live points for the nested sampler. Meaning somewhat dependent on the chosen sampler + nested_n_like_max : int + Maximum number of likelihood evaluations for nautilus. + + nested_maxcall : int + Maximum number of likelihood evaluations for dynesty. + nested_maxiter : int + Maximum number of iterations for dynesty. + Returns -------- result: Dictionary @@ -481,6 +500,14 @@ def run_nested(observations, model, sps, verbose=verbose, nested_nlive=nested_nlive, nested_neff=nested_target_n_effective, + nested_n_like_max=nested_n_like_max, + nested_wt_kwargs=nested_wt_kwargs, + nested_dlogz=nested_dlogz, + nested_nlive_batch=nested_nlive_batch, + nested_maxiter=nested_maxiter, nested_maxcall=nested_maxcall, + nested_maxiter_init=nested_maxiter_init, nested_maxcall_init=nested_maxcall_init, + nested_maxiter_batch=nested_maxiter_batch, nested_maxcall_batch=nested_maxcall_batch, + nested_maxbatch=nested_maxbatch, **kwargs) info, result_obj = output diff --git a/prospect/fitting/nested.py b/prospect/fitting/nested.py index c8aaabc6..3218b4ab 100644 --- a/prospect/fitting/nested.py +++ b/prospect/fitting/nested.py @@ -1,6 +1,6 @@ import inspect import numpy as np -import time +import time, sys import warnings __all__ = ["run_nested_sampler"] @@ -11,6 +11,17 @@ def run_nested_sampler(model, nested_sampler="dynesty", nested_nlive=1000, nested_neff=1000, + nested_n_like_max=sys.maxsize, + nested_dlogz=0.01, + nested_nlive_batch=200, + nested_maxiter=sys.maxsize, + nested_maxcall=sys.maxsize, + nested_maxiter_init=sys.maxsize, + nested_maxcall_init=sys.maxsize, + nested_maxiter_batch=sys.maxsize, + nested_maxcall_batch=sys.maxsize, + nested_maxbatch=sys.maxsize, + nested_wt_kwargs={'pfrac': 1.0}, verbose=False, **kwargs): """We give a model -- parameter discription and prior transform -- and a @@ -26,6 +37,15 @@ def run_nested_sampler(model, Number of live points. nested_neff : float Minimum effective sample size. + + nested_n_like_max : int + Maximum number of likelihood evaluations for nautilus. + + nested_maxcall : int + Maximum number of likelihood evaluations for dynesty. + nested_maxiter : int + Maximum number of iterations for dynesty. + verbose : bool Whether to output sampler progress. @@ -59,7 +79,10 @@ def run_nested_sampler(model, from dynesty import DynamicNestedSampler sampler_init = DynamicNestedSampler init_args = (likelihood_function, model.prior_transform, model.ndim) - init_kwargs = dict(nlive=nested_nlive) + init_kwargs = dict(nlive=nested_nlive, + dlogz=nested_dlogz, + maxcall=nested_maxcall_init, + maxiter=nested_maxiter_init, ) elif nested_sampler == 'nestle': import nestle init_kwargs = dict() @@ -80,7 +103,7 @@ def run_nested_sampler(model, if nested_sampler == 'nautilus': sampler_run = sampler.run run_args = () - run_kwargs = dict(n_eff=nested_neff, verbose=verbose) + run_kwargs = dict(n_eff=nested_neff, n_like_max=nested_n_like_max, verbose=verbose) elif nested_sampler == 'ultranest': sampler_run = sampler.run run_args = () @@ -90,7 +113,13 @@ def run_nested_sampler(model, elif nested_sampler == 'dynesty': sampler_run = sampler.run_nested run_args = () - run_kwargs = dict(n_effective=nested_neff, print_progress=verbose) + run_kwargs = dict(n_effective=nested_neff, + wt_kwargs=nested_wt_kwargs, + nlive_batch=nested_nlive_batch, + maxiter=nested_maxiter, maxcall=nested_maxcall, + maxiter_batch=nested_maxiter_batch, + maxcall_batch=nested_maxcall_batch, maxbatch=nested_maxbatch, + print_progress=verbose) elif nested_sampler == 'nestle': sampler_run = nestle.sample run_args = (likelihood_function, model.prior_transform, model.ndim) From f7c9611ec27964e19dc070f6dc0543c6d459baa3 Mon Sep 17 00:00:00 2001 From: Bingjie Wang Date: Tue, 6 Jan 2026 12:31:38 -0500 Subject: [PATCH 2/2] add checkpointing option for nautilus --- prospect/fitting/fitting.py | 14 ++++++++++++++ prospect/fitting/nested.py | 15 +++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/prospect/fitting/fitting.py b/prospect/fitting/fitting.py index d79c9c9e..866397d5 100755 --- a/prospect/fitting/fitting.py +++ b/prospect/fitting/fitting.py @@ -442,6 +442,8 @@ def run_nested(observations, model, sps, nested_maxcall_batch=sys.maxsize, nested_maxbatch=sys.maxsize, nested_wt_kwargs={'pfrac': 1.0}, + nested_filepath=None, + nested_resume=True, verbose=False, **kwargs): """Thin wrapper on :py:class:`prospect.fitting.nested.run_nested_sampler` @@ -472,14 +474,24 @@ def run_nested(observations, model, sps, Number of live points for the nested sampler. Meaning somewhat dependent on the chosen sampler + nautilus-specific parameters + ---------------------------- nested_n_like_max : int Maximum number of likelihood evaluations for nautilus. + nested_filepath : str or None + Path to the checkpointing file. Must have a `.h5` or `.hdf5` extension. If None, no checkpointing are performed. Default is None. + nested_resume : bool + If True, resume from previous run if filepath exists. If False, start from scratch and overwrite any previous file. Default is True. + dynesty-specific parameters + ---------------------------- nested_maxcall : int Maximum number of likelihood evaluations for dynesty. nested_maxiter : int Maximum number of iterations for dynesty. + ---------------------------- + Returns -------- result: Dictionary @@ -508,6 +520,8 @@ def run_nested(observations, model, sps, nested_maxiter_init=nested_maxiter_init, nested_maxcall_init=nested_maxcall_init, nested_maxiter_batch=nested_maxiter_batch, nested_maxcall_batch=nested_maxcall_batch, nested_maxbatch=nested_maxbatch, + nested_filepath=nested_filepath, + nested_resume=nested_resume, **kwargs) info, result_obj = output diff --git a/prospect/fitting/nested.py b/prospect/fitting/nested.py index 3218b4ab..ca4f43e1 100644 --- a/prospect/fitting/nested.py +++ b/prospect/fitting/nested.py @@ -22,6 +22,8 @@ def run_nested_sampler(model, nested_maxcall_batch=sys.maxsize, nested_maxbatch=sys.maxsize, nested_wt_kwargs={'pfrac': 1.0}, + nested_filepath=None, + nested_resume=True, verbose=False, **kwargs): """We give a model -- parameter discription and prior transform -- and a @@ -38,14 +40,23 @@ def run_nested_sampler(model, nested_neff : float Minimum effective sample size. + nautilus-specific parameters + ---------------------------- nested_n_like_max : int Maximum number of likelihood evaluations for nautilus. + nested_filepath : str or None + Path to the file where results are saved. Must have a `.h5` or `.hdf5` extension. If None, no results are written. Default is None. + nested_resume : bool + If True, resume from previous run if filepath exists. If False, start from scratch and overwrite any previous file. Default is True. + dynesty-specific parameters + ---------------------------- nested_maxcall : int Maximum number of likelihood evaluations for dynesty. nested_maxiter : int Maximum number of iterations for dynesty. - + + ---------------------------- verbose : bool Whether to output sampler progress. @@ -68,7 +79,7 @@ def run_nested_sampler(model, sampler_init = Sampler init_args = (model.prior_transform, likelihood_function) init_kwargs = dict(pass_dict=False, n_live=nested_nlive, - n_dim=model.ndim) + n_dim=model.ndim, filepath=nested_filepath, resume=nested_resume) elif nested_sampler == 'ultranest': from ultranest import ReactiveNestedSampler sampler_init = ReactiveNestedSampler