Skip to main content
v2026.11,986 entries · CC-BY 4.0

dynesty: Dynamic Nested Sampling in Python (Install, Run, Read Results)

dynesty explained: install v3.2.0, run nested sampling on a worked example, read evidence and weighted samples, fix common errors.

Written and maintained by CASRAI Editorial Board

Published

On this page

dynesty is a free, MIT-licensed, pure-Python package for dynamic nested sampling. You give it a log-likelihood function and a prior transform, and it returns weighted posterior samples together with an estimate of the Bayesian evidence (the marginal likelihood) and its uncertainty. The current release listed on PyPI and in the project documentation is 3.2.0 (10 November 2026, checked 13 November 2026), and it needs Python 3.8 or later.

Ask CASRAI · free to tryQuestion about this guide? Ask CASRAI answers with linked sources. 2 free questions a day, no account.

Ask your first question freeSubscribe

What dynesty is used for in research

Most Bayesian workflows in Python rely on MCMC samplers that return a posterior but not the evidence. Nested sampling is built around the evidence: it works inward through nested shells of increasing likelihood and produces both the evidence and posterior samples from the same run. dynesty implements this with dynamic nested sampling, which can allocate more live points to the regions that matter most for the posterior or for the evidence. That makes it a fit for model comparison (comparing evidences, as covered in interpreting Bayes factors) as well as parameter estimation.

The documentation describes dynesty as general-purpose but advises caution above roughly 30 dimensions. It is a good match for problems with expensive likelihoods and tens of parameters, and a poor match for high-dimensional hierarchical models, where gradient-based samplers such as those described in the NumPyro guide are the usual choice. For the general idea of sampling a posterior, see Markov chain Monte Carlo and its diagnostics.

Two features of the design shape everything below. First, the prior is specified implicitly through a prior transform that maps the unit cube to parameter space, not through a density. Second, the size of the prior directly affects run time, because the sampler must integrate over the posterior starting from the whole prior volume (dynesty Getting Started, read 13 November 2026). An overly broad prior makes a run slower.

Install or access

The official route is PyPI: pip install dynesty. The documentation lists numpy, scipy and matplotlib as required, with tqdm and h5py optional. To install the development version, clone the repository and run pip install . from its root.

Release 3.2.0 fixes the evidence-uncertainty calculation and periodic-parameter sampling, and it removes the reflective boundary option. If you have older code that passes reflective, update it before upgrading. Record the version you used with your results; the evidence-uncertainty fix means that numbers from older versions may not be directly comparable.

Step-by-step: from prior and likelihood to a posterior

The sequence below follows the documentation’s own correlated-Gaussian example (a three-dimensional multivariate normal likelihood with a uniform prior on [-10, 10)). It is adapted from Getting Started.

  1. Define the log-likelihood. It takes a parameter vector and returns the log-likelihood as a float.
    import numpy as npndim = 3C = np.identity(ndim)C[C==0] = 0.95Cinv = np.linalg.inv(C)lnorm = -0.5 * (np.log(2 * np.pi) * ndim + np.log(np.linalg.det(C)))def loglike(x):    return -0.5 * np.dot(x, np.dot(Cinv, x)) + lnorm
  2. Define the prior transform. It receives a vector u drawn uniformly from the unit cube and returns the parameters. For a uniform prior from -10 to 10:
    def ptform(u):    return 20. * u - 10.

    For non-uniform priors, apply the inverse CDF (percent point function) of each parameter, for example scipy.stats.norm.ppf(u[0], loc=mu, scale=sigma). Conditional priors are built by working through the parameters in order, so a later parameter can depend on earlier ones.

  3. Create the sampler. Three arguments are required: the log-likelihood, the prior transform and the number of dimensions.
    from dynesty import NestedSamplersampler = NestedSampler(loglike, ptform, ndim, nlive=1000)

    For a dynamic run use dynesty.DynamicNestedSampler(loglike, ptform, ndim) instead; the two samplers share the same results interface.

  4. Run it.
    sampler.run_nested(dlogz=0.5)res = sampler.resultsres.summary()

    A second call such as sampler.run_nested(maxcall=10000) continues the run and adds samples.

  5. Cite what you used. print(sampler.citations) lists the papers that apply to the options you chose.

Output and how to read it

The results object holds the run in several arrays. The ones you will use most are summarised in the table below, taken from the Getting Started documentation.

Attribute What it contains
samples Samples in the native parameter space
samples_u The same samples in the unit cube
logwt Unnormalised log-weights of each sample
importance_weights() Normalised weights
logz Cumulative log-evidence; the final value is the estimate
logzerr Approximate standard deviation of logz
samples_equal() Equal-weight samples, produced by resampling with the weights

The samples are weighted, so a plain samples.mean(axis=0) is wrong. Either compute weighted statistics, for example with dynesty.utils.mean_and_cov(samples, weights), or call samples_equal() and treat the output like ordinary posterior draws. The last value of logz and the last value of logzerr are the evidence estimate and its uncertainty.

The dynesty.plotting module provides runplot, traceplot, cornerpoints, cornerplot, boundplot and cornerbound. Note that the default credible intervals in the plots are 95% (two-sigma), not 68%, so label figures accordingly. For choosing between interval types when you report, see summarizing a posterior distribution.

Dynamic sampling options

The dynamic sampler runs an initial baseline run and then adds live points in batches. Its default weighting puts 80% of the importance on the posterior and 20% on the evidence; pass wt_kwargs={'pfrac': 1.0} for posterior-only allocation or {'pfrac': 0.0} for evidence-only. The run_nested arguments dlogz_init (default 0.05), nlive_init (500) and nlive_batch (100) control the baseline and each batch. Stopping can be controlled with n_effective, maxiter, maxcall, maxiter_init, maxiter_batch, maxcall_batch and maxbatch. Source: dynesty dynamic nested sampling page, read 13 November 2026.

Choosing sampling and bounding options

The data table below (published with the page, with CSV and JSON downloads) consolidates the FAQ’s guidance on the sample method, the bound and the number of live points. In short: leave sample at its default 'auto' unless you have a reason, because it picks uniform sampling in low dimensions, rwalk for moderate dimensions and slice for high dimensions. For bound, 'multi' is the default and the most adaptive; 'single' suits a simple unimodal posterior; 'balls' and 'cubes' are for low dimensions; 'none' is a fallback.

For live points, the documentation gives rules of thumb: with ellipsoidal bounds the minimum is ndim + 1 and about 2 x ndim is safe; with uniform sampling and bootstrapped bounds expect roughly 50 x ndim per mode; with non-ellipsoid bounds roughly 10 x ndim per mode. The Getting Started page separately advises about 50 live points per possible mode to avoid mode die-off. If your posterior may have several separated modes, raise the live points or add a batch with add_batch(mode='full').

Troubleshooting

The bound shows 0 or sampling seems to freeze

This is normal. The sampler waits until the cumulative sampling efficiency reaches about 10% before it builds the first bound (the first_update behaviour), so early output can look stalled.

The run is slow

Turn on print_progress to see where time goes, raise update_interval, try bound='multi', and tighten overly broad priors, which the documentation names as a cause of long runs.

The run overshoots maxiter or maxcall

Not a bug. These limits are checked after an accepted point, so a run can finish slightly past them.

A parallel pool crashes

Check variable access, how pool.map is used and whether your functions can be pickled. Nested functions often need dill; set dynesty.utils.pickle_module = dill. The number of processes can go up to about the number of live points, and queue_size should equal the number of processes and be below nlive. For MPI, the FAQ points to schwimmbad’s MPIPool with the dynamic sampler. Checkpointing lets you restart a long run.

I need more samples after a finished run

Start a new run and combine it with merge_runs(), or for the dynamic sampler use add_batch or raise n_effective.

Free alternatives

The FAQ names nestle, MultiNest, UltraNest and PolyChord as related nested-sampling software, and notes that nestle underlies dynesty’s multi-ellipsoid approach, UltraNest uses agglomerative clustering and dynesty’s rslice follows PolyChord’s method. Only the two packages whose licence and install route were read in their own documentation are tabulated.

Package Licence Install route Notes from its documentation
dynesty MIT pip (PyPI) Pure Python; dynamic nested sampling; caution advised above about 30 dimensions
UltraNest GPLv3 pip and conda Aims at feature parity with MultiNest; aimed at slow likelihoods with 1 to hundreds of parameters

The licence difference matters if you plan to embed a sampler in distributed software; check your institution’s rules, and see sharing a reproducible conda environment for pinning whichever version you choose.

Citing dynesty

The documentation asks users to cite the code through its Zenodo DOI (10.5281/zenodo.3348367) together with Speagle (2020). sampler.citations prints the full list for your configuration; the error-analysis utilities additionally cite Chopin and Robert (2010), Higson et al. (2018) and Speagle (2020).

FAQ

What is dynesty used for?

Estimating Bayesian posteriors and evidences with dynamic nested sampling, in Python, for models with a log-likelihood function and a prior expressible as a transform of the unit cube.

How do I install dynesty?

Run pip install dynesty. It requires Python 3.8 or later plus numpy, scipy and matplotlib.

Is dynesty free?

Yes. It is distributed under the MIT licence.

What is a prior transform?

A function mapping a vector drawn uniformly from the unit cube to the parameter space, equivalent to the inverse CDF for independent parameters. dynesty uses it in place of a prior density.

How do I get the evidence from a run?

Read the last element of results.logz for the log-evidence and the last element of results.logzerr for its approximate standard deviation.

How many dimensions can dynesty handle?

The documentation advises caution above about 30 dimensions.

Sources

Data: dynesty sampling, bounding and live-point guidance from the project FAQ

Compilation of the dynesty documentation's guidance on the sample method, bound option and live-point counts, restructured into one lookup table from the FAQ page, read 13 November 2026.

Period covered: 2026.

dynesty sampling, bounding and live-point guidance from the project FAQ
OptionDocumented behaviour or rule of thumbTypical use
sample = 'auto' (default)Picks uniform sampling in low dimensions, rwalk in moderate, slice in highDefault choice
sample = 'rwalk'Random walks of about 25 steps for dModerate dimensions
sample = 'slice'Default slices = 3High dimensions
bound = 'multi' (default)Most adaptive bounding optionMulti-modal or unknown shape
bound = 'single'Simple single-ellipsoid boundSimple unimodal posterior
bound = 'balls' / 'cubes'Low-dimensional boundsLow dimensions
bound = 'none'Fallback when other bounds failFallback
Live points, ellipsoidal boundsMinimum ndim + 1; about 2 x ndim is safePer run
Live points, uniform sampling with bootstrapsAbout 50 x ndim per modePer mode
Live points, non-ellipsoid boundsAbout 10 x ndim per modePer mode

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · free to try

Ask about dynesty: Dynamic Nested Sampling in Python (Install, Run, Read Results)

2 free questions a day, no account.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →