autofit.UltraNest#
- class autofit.UltraNest(name: Optional[str] = None, path_prefix: Optional[str] = None, unique_tag: Optional[str] = None, iterations_per_update: Optional[int] = None, number_of_cores: Optional[int] = None, session: Optional[Session] = None, **kwargs)[source]#
Bases:
AbstractNest
An UltraNest non-linear search.
UltraNest is an optional requirement and must be installed manually via the command pip install ultranest. It is optional as it has certain dependencies which are generally straight forward to install (e.g. Cython).
For a full description of UltraNest and its Python wrapper PyUltraNest, checkout its Github and documentation webpages:
https://github.com/JohannesBuchner/UltraNest https://johannesbuchner.github.io/UltraNest/readme.html
- Parameters:
name – The name of the search, controlling the last folder results are output.
path_prefix – The path of folders prefixing the name folder where results are output.
unique_tag – 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.
iterations_per_update – The number of iterations performed between update (e.g. output latest model to hard-disk, visualization).
number_of_cores – The number of cores sampling is performed using a Python multiprocessing Pool instance.
session – An SQLalchemy session instance so the results of the model-fit are written to an SQLite database.
Methods
check_model
Returns a configuration dictionary for test mode meaning that the sampler terminates as quickly as possible.
copy_with_paths
exact_fit
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.
fit_sequential
Fit multiple analyses contained within the analysis sequentially.
make_pool
Make the pool instance used to parallelize a NonLinearSearch alongside a set of unique ids for every process in the pool.
make_sneakier_pool
make_sneaky_pool
Create a pool for multiprocessing that uses slight-of-hand to avoid copying the fitness function between processes multiple times.
optimise
Perform optimisation for expectation propagation.
Output the sampler results to hard-disk in their internal format.
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_results
post_fit_output
Cleans up the output folderds after a completed non-linear search.
pre_fit_output
Outputs attributes of fit before the non-linear search begins.
result_via_completed_fit
Returns the result of the non-linear search of a completed model-fit.
samples_from
Loads the samples of a non-linear search from its output files.
samples_info_from
Returns a Samples object from the ultranest internal results.
start_resume_fit
Attributes
config_dict_run
A property that is only computed once per instance and then replaces itself with an ordinary attribute.
config_dict_search
A property that is only computed once per instance and then replaces itself with an ordinary attribute.
config_dict_settings
config_dict_stepsampler
config_type
logger
Log 'msg % args' with severity 'DEBUG'.
name
paths
plotter_cls
samples_cls
stepsampler
timer
Returns the timer of the search, which is used to output informaiton such as how long the search took and how much parallelization sped up the search time.
using_mpi
Whether the search is being performing using MPI for parallelisation or not.
- output_search_internal(search_internal)[source]#
Output the sampler results to hard-disk in their internal format.
UltraNest uses a backend to store and load results, therefore the outputting of the search internal to a dill file is disabled.
However, a dictionary of the search results is output to dill above.
- Parameters:
sampler – The nautilus sampler object containing the results of the model-fit.
- samples_via_internal_from(model: AbstractPriorModel, search_internal=None)[source]#
Returns a Samples object from the ultranest internal results.
The samples contain all information on the parameter space sampling (e.g. the parameters, log likelihoods, etc.).
The internal search results are converted from the native format used by the search to lists of values (e.g. parameter_lists, log_likelihood_list).
- Parameters:
model – Maps input vectors of unit parameter values to physical values and model instances via priors.
- config_dict_test_mode_from(config_dict: Dict) Dict [source]#
Returns a configuration dictionary for test mode meaning that the sampler terminates as quickly as possible.
Entries which set the total number of samples of the sampler (e.g. maximum calls, maximum likelihood evaluations) are reduced to low values meaning it terminates nearly immediately.
- Parameters:
config_dict – The original configuration dictionary for this sampler which includes entries controlling how fast the sampler terminates.
- Returns:
A configuration dictionary where settings which control the sampler’s number of samples are reduced so it
terminates as quickly as possible.