autofit.DynestyDynamic#
- class DynestyDynamic[source]#
Bases:
AbstractDynestyA 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_modeReduce the search's budget for test mode: the generic reduction sets each attribute of the declared
test_mode_budget(apply_test_modeof this module).check_modelcheck_poolThe 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.
Extra run_nested keyword arguments for a chunk of the dynamic sampler.
copy_with_pathsexact_fitexecution_settingsHow this search executes its objective on
analysis, resolved once: batching, eager or jitted execution, gradient use and the resolved gradient mode, plus theFitnesskeyword arguments the backend builds itsFitnesswith (autofit.non_linear.search.preflight.ExecutionSettings).finalize_resultThe one ending of a fit that ran (or was bypassed in test mode): build the
Result, run the analysis'save_resultshooks, unfreeze the model and complete the fit (archive, then.completed).finalize_search_internalArchive
search_internal(output_search_internal) when the search retains its internal state, otherwise remove thesearch_internalfolder.fitFit 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_overridesA 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_fromThe
samples_infoentries of arun(ctx)search's internal state, theinfoitsraw_samples_fromputs on theRawSamples(autofit.non_linear.samples.adapter).iterations_fromReturns 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_fromBy default, dynesty live points are generated via the sampler's in-built initialization.
load_search_internalThe 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_fitnessThe Fitness this search evaluates its likelihood through, the one construction site every search shares.
The maxcall for a chunk of the dynamic sampler.
optimiseOptimise one expectation-propagation factor with this search (
autofit.graphical.expectation_propagation.SearchFactorOptimiser).output_search_internalArchive
search_internalthrough the search'scheckpointerand, once a fit has completed, discard its resume state (there is nothing left to resume).perform_updatePerform an update of the non-linear search's model-fitting results.
perform_visualizationPerform visualization of the non-linear search's model-fitting results.
plot_latent_resultsThe 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_resultsThe 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_pointVisualize 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_outputArchives 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_outputOutputs 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).
progressThe run's progress for the status record (
autofit.non_linear.status): the likelihood calls so far, the evidence and, whenmaxcallbounds the run, the share of it spent (fraction).raw_samples_fromThe dynesty run's samples, log likelihoods and nested-sampling weights (
exp(logwt - logz[-1])) as raw samples.read_uses_poolIf a Dynesty fit does not use a parallel pool, and is then resumed using one, this causes significant slow down.
result_via_completed_fitReturns the result of the non-linear search of a completed model-fit.
runRun dynesty (the
run(ctx)hook; seedocs/design/run_ctx.md) and return the sampler.run_search_internalRun the Dynesty sampler, which could be either the static of dynamic sampler.
samples_fromLoads the samples of a non-linear search from its output files.
samples_info_fromsamples_via_internal_fromThe samples of the search, converted from its internal state.
Returns an instance of the Dynesty dynamic sampler set up using the input variables of this class.
start_pointsThe search's
ninitial points, drawn by its initializer, with the start-point plot made once, here, from the first of them.start_resume_fitThe dynamic sampler's own cumulative call counter, the quantity dynesty compares the cumulative maxcall with.
write_uses_poolIf a Dynesty fit does not use a parallel pool, and is then resumed using one, this causes significant slow down.
Attributes
batchedcheckpoint_fileThe path to the file used for checkpointing.
checkpointerwhere the backend's final state is stored when a fit completes, for
Result.search_internalandsamples_via_internal_from.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_keysgradienthonours_gradient_modeinstall_extrainvalid_valuejax_useloggerLog 'msg % args' with severity 'DEBUG'.
nameobjective_targetpathsposterior_kindproduces_evidencequick_update_messageThe one-line quick-update cadence logged at the start of every fit.
requires_fp64resumableThe file an interrupted run resumes from, for searches that genuinely resume (
Noneotherwise).retains_search_internalalways when the archive declares
retain_after_completion(its results cannot be rebuilt without it), otherwise when theoutput.search_internalconfig is on.Run kwargs specific to each subclass, excluding maxcall.
search_internalThe sampler restored from the resume state (
savestate.save) of a run that has not completed.search_kwargsShared search kwargs passed to both Static and Dynamic Dynesty samplers.
should_plot_start_pointstatustest_mode_budgettimerThe timer of the search (how long the search took, how much parallelization sped it up), or
Nonewhen the paths keep no timer (has_timer:NullPaths,DatabasePaths).upstream_urlwarm_start- resume_state: Optional[Checkpointer] = NativeFileCheckpointer('savestate.save', retain_after_completion=False)#
The file an interrupted run resumes from, for searches that genuinely resume (
Noneotherwise). Deleted when the fit completes unless it is the archive’s own file or declaresretain_after_completion.
- 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#