aspire_bilby.plugin
===================

.. py:module:: aspire_bilby.plugin

.. autoapi-nested-parse::

   Plugin for the aspire sampler in bilby.



Classes
-------

.. autoapisummary::

   aspire_bilby.plugin.Aspire


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

.. py:class:: Aspire(likelihood, priors, outdir='outdir', label='label', use_ratio=False, plot=False, skip_import_verification=False, injection_parameters=None, meta_data=None, result_class=None, likelihood_benchmark=False, soft_init=False, exit_code=130, npool=1, **kwargs)

   Bases: :py:obj:`bilby.core.sampler.base_sampler.Sampler`


   Bilby wrapper for aspire.

   Aspire: https://github.com/mj-will/bayesian-aspire

   Since aspire is designed to be called in multiple steps, specific keyword
   arguments are used for each step:
   - `fit_kwargs` for the fit step
   - `sample_kwargs` for the sampling step
   In addition, there are custom arguments for handling e.g. logging:
   - `aspire_log_level` for the logging level of aspire
   - `initial_conversion_function` for a function to convert the initial
   samples.
   - `sample_from_prior` to specify parameters that should be sampled from the
   prior regardless of whether they are in the initial result file.


   It also includes a method to read initial samples from a bilby result.

   Aspire also supports checkpointing and resuming via the built-in
   checkpointing functionality. If :code:`enable_checkpointing` is set to
   :code:`True` (default), a checkpoint file will be created in the output
   directory with the name :code:`{label}_aspire_checkpoint.h5`. If you
   provide a custom checkpoint file via the :code:`checkpoint_file` keyword
   argument in :code:`sample_kwargs`, that file will be used instead. The
   checkpoint file is updated every :code:`checkpoint_every` iterations
   (default 1). If the checkpoint file already exists, Aspire will resume
   from the last checkpoint. If `resume` is set to `False`, the checkpoint file
   then any existing checkpoint file will be ignored and overwritten, and the
   sampler will start from scratch.


   .. py:attribute:: sampler_name
      :value: 'aspire'


      Name of the sampler.


   .. py:property:: external_sampler_name
      :type: str


      The name of package that provides the sampler.


   .. py:property:: default_kwargs
      :type: dict


      Dictionary of default keyword arguments.


   .. py:method:: get_conversion_function(conversion_function = None)

      Get the conversion function from a string or return None.



   .. py:method:: read_initial_samples(initial_result_file, sample_from_prior = None, conversion_function = None)

      Read the initial samples from a bilby result file.

      If parameters are missing, they will be drawn from the prior.

      :param initial_result_file: The path to the initial result file.
      :type initial_result_file: :py:class:`str`
      :param parameters_to_sample: List of parameters to sample from the prior regardless of whether
                                   they are in the initial result file.
      :type parameters_to_sample: :py:class:`list`
      :param sample_from_prior: List of parameters to sample from the prior regardless of whether
                                they are in the initial result file. If None, all parameters will
                                be sampled from the initial result file.
      :type sample_from_prior: :py:class:`list[str]`, *optional*
      :param conversion_function: A function to convert the initial samples.
      :type conversion_function: :py:class:`Callable`



   .. py:method:: run_sampler()

      Run the sampler.



   .. py:method:: add_samples_to_result(samples)

      Add samples to the result object.

      Handles different types of samples objects and adds the appropriate attributes to the result.



   .. py:method:: get_expected_outputs(outdir=None, label=None)
      :classmethod:


      Get lists of the expected outputs directories and files.

      These are used by :code:`bilby_pipe` when transferring files via
      HTCondor. Both can be empty.

      :param outdir: The output directory.
      :type outdir: :py:class:`str`
      :param label: The label for the run.
      :type label: :py:class:`str`

      :returns: * :py:class:`list` -- List of file names.
                * :py:class:`list` -- List of directory names.



