autofit.DynestyStatic#
- class DynestyStatic[source]#
Bases:
AbstractDynestyA Dynesty NonLinearSearch using a static 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 (
Union[str,Path,None]) – 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 (
int) – Number of live points used for sampling.dlogz (
Optional[float]) – Stopping criterion: iteration stops when the estimated contribution of the remaining prior volume to the total evidence falls below this threshold.logl_max (
float) – Maximum log-likelihood value allowed.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.session (
Optional[Session]) – An SQLalchemy session instance so the results of the model-fit are written to an SQLite database.
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_poolchunk_is_finishedWhether a run_nested chunk stopped on dynesty's own termination criterion rather than on its budget, given the budget (iterations) and the total calls before and after the chunk.
chunk_kwargsExtra run_nested keyword arguments for a chunk, given the number of likelihood calls made before it.
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.
maxcall_fromThe maxcall handed to run_nested for a chunk of iterations likelihood calls, given that total_iterations calls have already been made.
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 static 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_fittotal_calls_fromThe total number of likelihood calls the sampler has made so far, or 0 for a sampler that has not run.
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.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.
- search_internal_from(model, fitness, checkpoint_exists, pool, queue_size)[source]#
Returns an instance of the Dynesty static 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#