autofit.DynestyDynamic#

class DynestyDynamic[source]#

Bases: AbstractDynesty

A Dynesty non-linear search, using a dynamically changing number of live points.

For a full description of Dynesty, checkout its GitHub and readthedocs webpages:

https://github.com/joshspeagle/dynesty https://dynesty.readthedocs.io/en/latest/index.html

Parameters:
  • name (Optional[str]) – The name of the search, controlling the last folder results are output.

  • path_prefix (Optional[str]) – The path of folders prefixing the name folder where results are output.

  • unique_tag (Optional[str]) – The name of a unique tag for this model-fit, which will be given a unique entry in the sqlite database and also acts as the folder after the path prefix and before the search name.

  • nlive_init (int) – Number of live points used during the initial exploration phase.

  • dlogz_init (float) – Stopping criterion for the initial baseline run.

  • n_effective (Optional[int]) – The minimum effective posterior sample size (ESS) of the whole run. After the baseline run, dynesty keeps adding batches of live points until its default stopping function judges the estimated ESS to have reached this value (target_n_effective). If None (the default), the argument is not passed and dynesty’s own default applies, which in dynesty 2.x is max(10000, ndim ** 2). It has no effect if a custom stop_function is used. It is not an identifier field, so changing it alone does not give the search a new output folder.

  • iterations_per_full_update (int) – The number of iterations performed between update (e.g. output latest model to hard-disk, visualization).

  • number_of_cores (int) – The number of cores sampling is performed using a Python multiprocessing Pool instance.

Methods

apply_test_mode

Reduce the search's budget for test mode: the generic reduction sets each attribute of the declared test_mode_budget (apply_test_mode of this module).

check_model

check_pool

chunk_is_finished

The baseline-only first chunk of a chunked run is never finished: the batch phase (and so the n_effective stopping criterion) has not run yet.

chunk_kwargs

Extra run_nested keyword arguments for a chunk of the dynamic sampler.

copy_with_paths

exact_fit

execution_settings

How this search executes its objective on analysis, resolved once: batching, eager or jitted execution, gradient use and the resolved gradient mode, plus the Fitness keyword arguments the backend builds its Fitness with (autofit.non_linear.search.preflight.ExecutionSettings).

finalize_result

The one ending of a fit that ran (or was bypassed in test mode): build the Result, run the analysis' save_results hooks, unfreeze the model and complete the fit (archive, then .completed).

finalize_search_internal

Archive search_internal (output_search_internal) when the search retains its internal state, otherwise remove the search_internal folder.

fit

Fit a model, M with some function f that takes instances of the class represented by model M and gives a score for their fitness: the search produces instances of the model by picking points in its N dimensional space.

fitness_overrides

A JAX analysis is jitted lazily by the scalar objective __call__ dispatches to; the deprecated use_jax_jit=False keeps its old meaning (eager JAX) for one release.

info_from

The samples_info entries of a run(ctx) search's internal state, the info its raw_samples_from puts on the RawSamples (autofit.non_linear.samples.adapter).

iterations_from

Returns the next number of iterations that a dynesty call will use and the total number of iterations that have been performed so far.

live_points_init_from

By default, dynesty live points are generated via the sampler's in-built initialization.

load_search_internal

The archive (search_internal.dill, written when the fit completed) or, for a run that has not completed, the sampler restored from its resume state (savestate.save).

make_fitness

The Fitness this search evaluates its likelihood through, the one construction site every search shares.

maxcall_from

The maxcall for a chunk of the dynamic sampler.

optimise

Optimise one expectation-propagation factor with this search (autofit.graphical.expectation_propagation.SearchFactorOptimiser).

output_search_internal

Archive search_internal through the search's checkpointer and, once a fit has completed, discard its resume state (there is nothing left to resume).

perform_update

Perform an update of the non-linear search's model-fitting results.

perform_visualization

Perform visualization of the non-linear search's model-fitting results.

plot_latent_results

The search's plots of the model's latent parameters (the corner plot of a shear's magnitude and angle, say), by its posterior_kind; nothing for a search without one.

plot_results

The search's own plots of its samples, by its declared posterior_kind (autofit.non_linear.search.posterior_kind): the chain, weighted or point plotter.

plot_start_point

Visualize the starting point of the non-linear search, using an instance of the model at the starting point of the maximum likelihood estimator.

post_fit_output

Archives the output folder of a completed non-linear search into its .zip file (always), and then removes the folder so only the .zip is left (for supercomputers with a file-count limit) only when remove_files=True in the general.yaml output section; with remove_files=False both are kept.

pre_fit_output

Outputs attributes of fit before the non-linear search begins: the model composition (files/model.json), the search settings (files/search.json), the info dictionary (files/info.json), the analysis' save_attributes (e.g. files/data.json) and its visualize_before_fit / visualize_before_fit_combined visuals (quantities that do not change during the model-fit, e.g. the data).

progress

The run's progress for the status record (autofit.non_linear.status): the likelihood calls so far, the evidence and, when maxcall bounds the run, the share of it spent (fraction).

raw_samples_from

The dynesty run's samples, log likelihoods and nested-sampling weights (exp(logwt - logz[-1])) as raw samples.

read_uses_pool

If a Dynesty fit does not use a parallel pool, and is then resumed using one, this causes significant slow down.

result_via_completed_fit

Returns the result of the non-linear search of a completed model-fit.

run

Run dynesty (the run(ctx) hook; see docs/design/run_ctx.md) and return the sampler.

run_search_internal

Run the Dynesty sampler, which could be either the static of dynamic sampler.

samples_from

Loads the samples of a non-linear search from its output files.

samples_info_from

samples_via_internal_from

The samples of the search, converted from its internal state.

search_internal_from

Returns an instance of the Dynesty dynamic sampler set up using the input variables of this class.

start_points

The search's n initial points, drawn by its initializer, with the start-point plot made once, here, from the first of them.

start_resume_fit

total_calls_from

The dynamic sampler's own cumulative call counter, the quantity dynesty compares the cumulative maxcall with.

write_uses_pool

If a Dynesty fit does not use a parallel pool, and is then resumed using one, this causes significant slow down.

Attributes

batched

checkpoint_file

The path to the file used for checkpointing.

checkpointer

where the backend's final state is stored when a fit completes, for Result.search_internal and samples_via_internal_from.

chunked

Whether a run is split into run_nested chunks for on-the-fly output, i.e. whether iterations_per_full_update is finite rather than the inf-like default (1e99).

citation_keys

gradient

honours_gradient_mode

install_extra

invalid_value

jax_use

logger

Log 'msg % args' with severity 'DEBUG'.

name

number_live_points

objective_target

paths

posterior_kind

produces_evidence

quick_update_message

The one-line quick-update cadence logged at the start of every fit.

requires_fp64

resumable

resume_state

The file an interrupted run resumes from, for searches that genuinely resume (None otherwise).

retains_search_internal

always when the archive declares retain_after_completion (its results cannot be rebuilt without it), otherwise when the output.search_internal config is on.

run_kwargs

Run kwargs specific to each subclass, excluding maxcall.

search_internal

The sampler restored from the resume state (savestate.save) of a run that has not completed.

search_kwargs

Shared search kwargs passed to both Static and Dynamic Dynesty samplers.

should_plot_start_point

status

test_mode_budget

timer

The timer of the search (how long the search took, how much parallelization sped it up), or None when the paths keep no timer (has_timer: NullPaths, DatabasePaths).

upstream_url

warm_start

resume_state: Optional[Checkpointer] = NativeFileCheckpointer('savestate.save', retain_after_completion=False)#

The file an interrupted run resumes from, for searches that genuinely resume (None otherwise). Deleted when the fit completes unless it is the archive’s own file or declares retain_after_completion.

property run_kwargs: Dict#

Run kwargs specific to each subclass, excluding maxcall.

property chunked: bool#

Whether a run is split into run_nested chunks for on-the-fly output, i.e. whether iterations_per_full_update is finite rather than the inf-like default (1e99).

total_calls_from(search_internal)[source]#

The dynamic sampler’s own cumulative call counter, the quantity dynesty compares the cumulative maxcall with. results.ncall undercounts it (it omits each batch’s live-point initialisation), which would make a budget-limited batch chunk look converged. Falls back to the results count for objects without the counter.

maxcall_from(iterations, total_iterations)[source]#

The maxcall for a chunk of the dynamic sampler.

dynesty’s DynamicNestedSampler.run_nested compares maxcall with its cumulative call count (self.ncall, carried over from earlier calls), unlike the static sampler whose counter resets per call. The budget for a chunk is therefore the calls made so far plus the chunk size, capped at sys.maxsize (dynesty’s own “unbounded” value) so an inf-like value cannot overflow the C long dynesty subtracts from.

The first chunk of a chunked run is the exception: it is given the whole budget (maxcall if set, otherwise unbounded) because the baseline run must never be cut short, see chunk_kwargs.

chunk_kwargs(total_iterations)[source]#

Extra run_nested keyword arguments for a chunk of the dynamic sampler.

A dynamic run is a baseline nested sampling run followed by batches of live points. dynesty cannot continue a baseline run that maxcall cut short: the next run_nested call restarts it from scratch (sample_initial calls reset()), and resume=True refuses because the previous call ended in the RUN_DONE state. Batches, however, can be added across run_nested calls: once self.base is set the baseline is skipped and the batch loop continues from self.batch, evaluating the stopping criterion (including n_effective) first.

A chunked run therefore completes the baseline in its first chunk (maxbatch=0, no call budget) and chunks only the batch phase, by cumulative maxcall (maxcall_from). Intermediate output starts after the baseline run.

chunk_is_finished(iterations, total_iterations, iterations_after_run)[source]#

The baseline-only first chunk of a chunked run is never finished: the batch phase (and so the n_effective stopping criterion) has not run yet. If it turns out to be satisfied already, the next chunk adds no calls and run_search_internal’s no-new-calls criterion finishes the search.

A batch chunk stops sampling once its cumulative call count reaches the cumulative maxcall (it may land exactly on it), so it converged only if it stopped strictly inside that budget.

search_internal_from(model, fitness, checkpoint_exists, pool, queue_size)[source]#

Returns an instance of the Dynesty dynamic sampler set up using the input variables of this class.

If no existing dynesty sampler exist on hard-disk (located via a checkpoint_file) a new instance is created with which sampler is performed. If one does exist, the dynesty restore() function is used to create the instance of the sampler.

Dynesty samplers with a multiprocessing pool may be created by inputting a dynesty Pool object, however non pooled instances can also be created by passing pool=None and queue_size=None.

Parameters:
  • model (AbstractPriorModel) – The model which generates instances for different points in parameter space.

  • fitness – An instance of the fitness class used to evaluate the likelihood of each model.

  • pool (Optional) – A dynesty Pool object which performs likelihood evaluations over multiple CPUs.

  • queue_size (Optional[int]) – The number of CPU’s over which multiprocessing is performed, determining how many samples are stored in the dynesty queue for samples.

property number_live_points#