autofit.Nautilus#

class autofit.Nautilus(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

A Nautilus non-linear search.

Nautilus 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 Nautilus checkout its Github and documentation webpages:

https://github.com/johannesulf/nautilus https://nautilus-sampler.readthedocs.io/en/stable/index.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

config_dict_with_test_mode_settings_from

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_mpi

Perform the non-linear search, using MPI to distribute the model-fit across multiple computing nodes.

fit_multiprocessing

Perform the non-linear search, using multiple CPU cores parallelized via Python's multiprocessing module.

fit_sequential

Fit multiple analyses contained within the analysis sequentially.

fit_x1_cpu

Perform the non-linear search, using one CPU core.

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_sampler_results

Output the sampler results to hard-disk in a generalized PyAutoFit 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.

remove_state_files

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

samples_via_csv_from

Returns a Samples object from the samples.csv and samples_info.json files.

samples_via_internal_from

Returns a Samples object from the ultranest internal results.

start_resume_fit

Start a non-linear search from scratch, or resumes one which was previously terminated mid-way through.

Attributes

checkpoint_file

The path to the file used for checkpointing.

config_dict

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_type

logger

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

name

paths

sampler_cls

samples_cls

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.

property checkpoint_file#

The path to the file used for checkpointing.

If autofit is not outputting results to hard-disk (e.g. paths is NullPaths), this function is bypassed.

fit_x1_cpu(fitness, model, analysis, checkpoint_exists: bool)[source]#

Perform the non-linear search, using one CPU core.

This is used if the likelihood function calls external libraries that cannot be parallelized or use threading in a way that conflicts with the parallelization of the non-linear search.

Parameters:
  • fitness – The function which takes a model instance and returns its log likelihood via the Analysis class

  • model – The model which maps parameters chosen via the non-linear search (e.g. via the priors or sampling) to instances of the model, which are passed to the fitness function.

  • analysis – Contains the data and the log likelihood function which fits an instance of the model to the data, returning the log likelihood the search maximizes.

  • checkpoint_exists – Does the checkpoint file corresponding do a previous run of this search exist?

fit_multiprocessing(fitness, model, analysis, checkpoint_exists: bool)[source]#

Perform the non-linear search, using multiple CPU cores parallelized via Python’s multiprocessing module.

This uses PyAutoFit’s sneaky pool class, which allows us to use the multiprocessing module in a way that plays nicely with the non-linear search (e.g. exception handling, keyboard interupts, etc.).

Multiprocessing parallelization can only parallelize across multiple cores on a single device, it cannot be distributed across multiple devices or computing nodes. For that, use the fit_mpi method.

Parameters:
  • fitness – The function which takes a model instance and returns its log likelihood via the Analysis class

  • model – The model which maps parameters chosen via the non-linear search (e.g. via the priors or sampling) to instances of the model, which are passed to the fitness function.

  • analysis – Contains the data and the log likelihood function which fits an instance of the model to the data, returning the log likelihood the search maximizes.

  • checkpoint_exists – Does the checkpoint file corresponding do a previous run of this search exist?

fit_mpi(fitness, model, analysis, checkpoint_exists: bool)[source]#

Perform the non-linear search, using MPI to distribute the model-fit across multiple computing nodes.

This uses PyAutoFit’s sneaky pool class, which allows us to use the multiprocessing module in a way that plays nicely with the non-linear search (e.g. exception handling, keyboard interupts, etc.).

MPI parallelization can be distributed across multiple devices or computing nodes.

Parameters:
  • fitness – The function which takes a model instance and returns its log likelihood via the Analysis class

  • model – The model which maps parameters chosen via the non-linear search (e.g. via the priors or sampling) to instances of the model, which are passed to the fitness function.

  • analysis – Contains the data and the log likelihood function which fits an instance of the model to the data, returning the log likelihood the search maximizes.

  • checkpoint_exists – Does the checkpoint file corresponding do a previous run of this search exist?

output_sampler_results(search_internal)[source]#

Output the sampler results to hard-disk in a generalized PyAutoFit format.

The results in this format are loaded by other functions in order to create a Samples object, perform updates which visualize the results and write the results to the hard-disk as an output of the model-fit.

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.