nessai.flowsampler
==================

.. py:module:: nessai.flowsampler

.. autoapi-nested-parse::

   Main code that handles running and checkpoiting the sampler.

   ..
       !! processed by numpydoc !!


Classes
-------

.. autoapisummary::

   nessai.flowsampler.FlowSampler


Module Contents
---------------

.. py:class:: FlowSampler(model, output=None, importance_nested_sampler=False, resume=True, resume_file='nested_sampler_resume.pkl', resume_data=None, weights_file=None, weights_path=None, signal_handling=True, exit_code=130, pytorch_threads=1, close_pool=True, eps=None, torch_dtype=None, disable_vectorisation=False, likelihood_chunksize=None, allow_multi_valued_likelihood=None, parallelise_prior=None, result_extension='hdf5', **kwargs)

   
   Main class to handle running the nested sampler.


   :Parameters:

       **model** : :obj:`nessai.model.Model`
           User-defined model.

       **output** : str, optional
           Output directory

       **resume** : bool, optional
           If True try to resume the sampler is the resume file exists.

       **resume_file** : str, optional
           File to resume sampler from.

       **resume_data: Any, optional**
           Data to resume the sampler from instead of a resume file. The data will
           be passed to the :code:`resume_from_pickled_sampler` of the relevant
           class.

       **weights_path** : str, optional
           Path to either the weights file or directory containing subdirectories
           with weight files.

       **weights_file** : str, optional
           Weights file to use, same as :code:`weights_path` and included for
           backwards_compatibility. Will be ignored is :code:`weights_paths` has
           also been specified.

       **pytorch_threads** : int
           Maximum number of threads to use for torch. If ``None`` torch uses all
           available threads.

       **signal_handling** : bool
           Enable or disable signal handling.

       **exit_code** : int, optional
           Exit code to use when forcibly exiting the sampler.

       **close_pool** : bool
           If True, the multiprocessing pool will be closed once the run method
           has been called. Disables the option in :code:`NestedSampler` if
           enabled.

       **disable_vectorisation** : bool
           Disable likelihood vectorisation. Overrides the value of
           :py:attr:`nessai.model.Model.allow_vectorised`.

       **likelihood_chunksize** : Optional[int]
           Chunksize used when evaluating a vectorised likelihood. Overrides the
           of :py:attr:`nessai.model.Model.likelihood_chunksize`. Set to None to
           evaluate the likelihood with all available points.

       **allow_multi_valued_likelihood** : Optional[bool]
           Allow for a multi-valued likelihood function that will return different
           likelihood values for the same point in parameter space. See
           :py:attr:`nessai.model.Model.allow_multi_valued_likelihood` for more
           details.

       **parallelise_prior** : Optional[bool]
           If true, and a multiprocessing pool has been specified, then the
           log-prior calculation will be parallelised using multiprocessing.
           If false, then the pool with not be used. Overrides the value of the
           `parallelise_prior` attribute in the model class, which is false by
           default.

       **result_extension** : str
           Extension used when saving the result format. Defaults to HDF5, but
           also supports JSON.

       **kwargs**
           Keyword arguments passed to
           :obj:`~nessai.samplers.nestedsampler.NestedSampler`.














   ..
       !! processed by numpydoc !!

   .. py:method:: check_resume(resume_file, resume_data)

      
      Check if it is possible to resume the sampler
















      ..
          !! processed by numpydoc !!


   .. py:property:: log_evidence

      
      Return the most recent log evidence
















      ..
          !! processed by numpydoc !!


   .. py:property:: log_evidence_error

      
      Return the most recent log evidence error
















      ..
          !! processed by numpydoc !!


   .. py:property:: nested_samples

      
      Return the nested samples
















      ..
          !! processed by numpydoc !!


   .. py:property:: rng

      
      Return the random number generator
















      ..
          !! processed by numpydoc !!


   .. py:method:: run(plot=True, save=True, posterior_sampling_method=None, close_pool=None, **kwargs)

      
      Run the nested sampler.

      Will pick the correct run method given the configuration used.

      :Parameters:

          **plot** : bool
              Toggle all plots produced once the sampler has converged.

          **save** : bool, optional
              Toggle automatic saving of results

          **posterior_sampling_method** : str, optional
              Method used for drawing posterior samples. Defaults to rejection
              sampling.

          **close_pool** : bool, optional
              Boolean to indicated if the pool should be closed at the end of the
              run function. If False, the user must manually close the pool. If
              specified, this value overrides the value passed when initialising
              the FlowSampler class.














      ..
          !! processed by numpydoc !!


   .. py:method:: run_standard_sampler(plot=True, plot_indices=True, plot_posterior=True, plot_logXlogL=True, save=True, posterior_sampling_method=None, close_pool=None)

      
      Run the standard nested sampler.


      :Parameters:

          **plot** : bool
              Toggle all plots produced once the sampler has converged.

          **plot_indices** : bool
              Toggle the insertion indices plot.

          **plot_posterior** : bool
              Toggle the posterior distribution plot.

          **plot_logXlogL** : bool
              Toggle the log-prior volume vs log-likelihood plot.

          **save**
              Enable or disable saving of a results file.

          **posterior_sampling_method**
              Method used for drawing posterior samples. Defaults to rejection
              sampling.

          **close_pool** : bool
              Boolean to indicated if the pool should be closed at the end of the
              run function. If False, the user must manually close the pool. If
              specified, this value overrides the value passed when initialising
              the class.














      ..
          !! processed by numpydoc !!


   .. py:method:: run_importance_nested_sampler(plot=True, plot_posterior=True, save=True, posterior_sampling_method=None, redraw_samples=False, n_posterior_samples=None, compute_initial_posterior=False, close_pool=None, **kwargs)

      
      Run the importance nested sampler.


      :Parameters:

          **plot**
              Enable or disable plotting. Independent of the value passed
              to the :code:`NestedSampler` object.

          **save**
              Enable or disable saving of a results file.

          **posterior_sampling_method**
              Method used for drawing posterior samples. Defaults to importance
              sampling.

          **redraw_samples**
              If True after the sampling is finished, samples are redrawn from
              the meta proposal and used to compute an updated evidence estimate
              and posterior. This can reduce biases in the results.

          **n_posterior_samples**
              Number of posterior samples to draw when when redrawing samples.

          **compute_initial_posterior**
              Enables or disables computing the posterior before redrawing
              samples. If :code:`redraw_samples` is False, then this flag is
              ignored.

          **close_pool** : bool
              Boolean to indicated if the pool should be closed at the end of the
              run function. If False, the user must manually close the pool. If
              specified, this value overrides the value passed when initialising
              the class.

          **kwargs**
              Keyword arguments passed to                 :py:meth:`~nessai.importancesampler.ImportanceNestedSampler.draw_final_samples`














      ..
          !! processed by numpydoc !!


   .. py:method:: save_kwargs(kwargs: dict) -> None

      
      Save the dictionary of keyword arguments used.

      Uses an encoder class to handle numpy arrays.

      :Parameters:

          **kwargs** : dict
              Dictionary of kwargs to save.














      ..
          !! processed by numpydoc !!


   .. py:method:: save_results(filename: str, extension: Optional[str] = None) -> None

      
      Save the results from sampling to a specific results file.


      :Parameters:

          **filename** : str
              Name of file to save results to.

          **extension** : Optional[str]
              File extension to used. If not specified, it will be inferred from
              the filename.














      ..
          !! processed by numpydoc !!


   .. py:method:: terminate_run(code=None)

      
      Terminate a sampling run.


      :Parameters:

          **code** : int, optional
              Code passed to :code:`close_pool`














      ..
          !! processed by numpydoc !!


   .. py:method:: safe_exit(signum=None, frame=None)

      
      Safely exit. This includes closing the multiprocessing pool.
















      ..
          !! processed by numpydoc !!


